Skip to content
Prev Previous commit
Next Next commit
resolve format complaints in mDNS-modified code
resolve maven com.coveo:format plugin's complaints
  • Loading branch information
ka2ddo authored Jan 7, 2021
commit cc916e5a6872ace64216fcf793542169a16e2e24
34 changes: 13 additions & 21 deletions src/main/java/org/xbill/DNS/NioUdpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ private static class Transaction implements KeyProcessor {

void send() throws IOException {
ByteBuffer buffer = ByteBuffer.wrap(data);
verboseLog(
"UDP write",
channel.socket().getLocalSocketAddress(),
remoteSocketAddress,
data);
verboseLog("UDP write", channel.socket().getLocalSocketAddress(), remoteSocketAddress, data);
int n = channel.send(buffer, remoteSocketAddress);
if (n <= 0) {
throw new EOFException();
Expand Down Expand Up @@ -131,11 +127,7 @@ public void processReadyKey(SelectionKey key) {
buffer.flip();
byte[] data = new byte[read];
System.arraycopy(buffer.array(), 0, data, 0, read);
verboseLog(
"UDP read",
channel.socket().getLocalSocketAddress(),
source,
data);
verboseLog("UDP read", channel.socket().getLocalSocketAddress(), source, data);
silentCloseChannel();
f.complete(Collections.singletonList(data));
pendingTransactions.remove(this);
Expand All @@ -157,13 +149,17 @@ void closeTransaction() {
}

private static class MultiAnswerTransaction extends Transaction {
MultiAnswerTransaction(byte[] query, int max, long endTime, DatagramChannel channel,
SocketAddress remoteSocketAddress,
CompletableFuture<List<byte[]>> f) {
super(query, max, endTime, channel, remoteSocketAddress, f);
}
MultiAnswerTransaction(
byte[] query,
int max,
long endTime,
DatagramChannel channel,
SocketAddress remoteSocketAddress,
CompletableFuture<List<byte[]>> f) {
super(query, max, endTime, channel, remoteSocketAddress, f);
}

public void processReadyKey(SelectionKey key) {
public void processReadyKey(SelectionKey key) {
if (!key.isReadable()) {
silentCloseChannel();
f.completeExceptionally(new EOFException("channel not readable"));
Expand Down Expand Up @@ -191,11 +187,7 @@ public void processReadyKey(SelectionKey key) {
buffer.flip();
byte[] data = new byte[read];
System.arraycopy(buffer.array(), 0, data, 0, read);
verboseLog(
"UDP read",
channel.socket().getLocalSocketAddress(),
source,
data);
verboseLog("UDP read", channel.socket().getLocalSocketAddress(), source, data);
answers.add(data);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only other line in this method that differs for mDNS. Instead of duplicating everything, move the processing of the data byte-array into a separate method, e.g.

// in Transaction:
...
  System.arraycopy(buffer.array(), 0, data, 0, read);
  verboseLog("UDP read", channel.socket().getLocalSocketAddress(), source, data);
  processAnswer(data);
}

processAnswer(byte[] data) {
  silentCloseChannel();
  f.complete(Collections.singletonList(data));
  pendingTransactions.remove(this);
}

// in MultiAnswerTransaction:
processAnswer(byte[] data) {
  answers.add(data);
}

}

Expand Down