} else if ("IdentifierCollision".equals(messageName)) {
fireReceivedIdentifierCollision(new IdentifierCollision(fcpMessage));
} else if ("AllData".equals(messageName)) {
- long dataLength;
- try {
- dataLength = Long.valueOf(fcpMessage.getField("DataLength"));
- } catch (NumberFormatException nfe1) {
- dataLength = -1;
- }
- LimitedInputStream payloadInputStream = new LimitedInputStream(remoteInputStream, dataLength);
+ LimitedInputStream payloadInputStream = getInputStream(FcpUtils.safeParseLong(fcpMessage.getField("DataLength")));
fireReceivedAllData(new AllData(fcpMessage, payloadInputStream));
try {
payloadInputStream.consume();
} catch (IOException ioe1) {
- /* FIXME - what now? */
/* well, ignore. when the connection handler fails, all fails. */
}
} else if ("EndListPeerNotes".equals(messageName)) {
incomingMessageStatistics.put(name, oldValue + 1);
}
+ /**
+ * Returns a limited input stream from the node’s input stream.
+ *
+ * @param dataLength
+ * The length of the stream
+ * @return The limited input stream
+ */
+ private LimitedInputStream getInputStream(long dataLength) {
+ if (dataLength <= 0) {
+ return new LimitedInputStream(null, 0);
+ }
+ return new LimitedInputStream(remoteInputStream, dataLength);
+ }
+
}