throw new LocalCancellationException();
if (inputStream == null)
throw new IOException("Socket already disposed");
BinaryPacket packet = BinaryPacket
.parseDelimitedFrom(inputStream);
if (packet == null) {
if (progress.isCanceled())
throw new LocalCancellationException();
throw new EOFException("No more packets");
}
final int objectid = packet.getObjectid();
switch (packet.getType()) {
case TRANSFERDESCRIPTION:
incomingDescriptionPackets.get(objectid).add(packet);
if (packet.getRemaining() == 0) {
List<BinaryPacket> list = incomingDescriptionPackets
.remove(objectid);
byte[] data = getData(list);
final TransferDescription transferDescription = buildTransferDescription(
objectid, data, progress);
// Side-effect! Create a new BlockingQueue in the
// incomingPackets AutoHashMap!
BlockingQueue<BinaryPacket> queue = incomingPackets
.get(objectid);
if (queue.size() > 0) {
log.warn("New incoming transfer, but already"
+ " packets exist with the given ID!"
+ " Discarding - " + transferDescription);
queue.clear();
}
return new BinaryChannelTransferObject(this,
transferDescription, objectid);
}
break;
case DATA:
// Only keep packets for DATA we are expecting!
if (incomingPackets.containsKey(objectid))
incomingPackets.get(objectid).add(packet);
else {
if (log.isDebugEnabled())
log.warn("Discarding Packet: " + packet);
}
break;
case CANCEL:
incomingDescriptionPackets.remove(objectid);
if (incomingPackets.containsKey(objectid)) {
// Pass the cancelation to the
// BinaryChanelTransferObject
// if no incomingPackets is found the transfer has
// already been finished
incomingPackets.get(objectid).add(packet);
}
break;
case FINISHED: // fall through
case REJECT:
remoteTransfers.get(objectid).add(packet);
break;
case SHUTDOWN:
// TODO Terminate BinaryChannel
break;
default:
log.error("Unknown BinaryHeaderType: " + packet.getType());
}
}
} finally {
progress.done();