int bytesRead;
Packet packetToSend;
try {
while ((bytesRead = outputPipedInput.read(buffer)) != -1) {
// Create the packet.
packetToSend = new DataPacket(buffer, 0, bytesRead);
/*
* This synchronization is to make sure we are not adding
* new packet to the buffer and the queue, while we are
* adding the packets that hasn't be send to the queue.