Permalink
Browse files

Allow DnsMessage.writeTo() to skip the length information

  • Loading branch information...
Flowdalic committed Jul 24, 2018
1 parent fa110c6 commit 923d595b490438d0e9532ea68f275716a71766d3
@@ -475,9 +475,15 @@ public DatagramPacket asDatagram(InetAddress address, int port) {
}

public void writeTo(OutputStream outputStream) throws IOException {
writeTo(outputStream, true);
}

public void writeTo(OutputStream outputStream, boolean writeLength) throws IOException {
byte[] bytes = serialize();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeShort(bytes.length);
if (writeLength) {
dataOutputStream.writeShort(bytes.length);
}
dataOutputStream.write(bytes);
}

@@ -80,7 +80,7 @@ public static void main(String[] args) throws IOException, SecurityException, Il

public static void writeToFile(DnsMessage dnsMessage, String path) throws IOException {
try (FileOutputStream fos = new FileOutputStream(path)) {
dnsMessage.writeTo(fos);
dnsMessage.writeTo(fos, true);
}
}
}

0 comments on commit 923d595

Please sign in to comment.