use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.
the class DNSRecordCommands method importRecord.
/*
* Imports a specific DNS record type from a file.
*/
private void importRecord(String path, int type) {
DnsRecord dnsRecord = loadAndVerifyDnsRecordFromBin(path);
if (dnsRecord.getType() != type) {
throw new IllegalArgumentException("File " + path + " does not contain the requested record type");
}
addDNS(dnsRecord);
}
use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.
the class DNSRecordCommands method loadAndVerifyDnsRecordFromBin.
/*
* Loads a record from a file. Records are stored in raw wire format.
*/
private DnsRecord loadAndVerifyDnsRecordFromBin(String path) {
File recFile = new File(path);
if (!recFile.exists())
throw new IllegalArgumentException("Record file " + recFile.getAbsolutePath() + " not found");
Record rec = null;
try {
byte[] wire = FileUtils.readFileToByteArray(recFile);
rec = Record.fromWire(wire, Section.ANSWER);
} catch (Exception e) {
throw new RuntimeException("Error reading file " + recFile.getAbsolutePath() + " : " + e.getMessage(), e);
}
return (rec != null) ? fromRecord(rec) : null;
}
Aggregations