private static EventEnvelope extractEnvelope ( Socket socket ) throws IOException { // To-Do: Read the ZeroMQ socket via a NIO wrapper to support large data: // indeed the arrays has a maximal size bounded by a native int value, and // the real data could be larger than this limit. byte [ ] data = socket . recv ( ZMQ . DONTWAIT ) ; byte [ ] cdata ; int oldSize = 0 ; while ( socket . hasReceiveMore ( ) ) { cdata = socket . recv ( ZMQ . DONTWAIT ) ; oldSize = data . length ; data = Arrays . copyOf ( data , data . length + cdata . length ) ; System . arraycopy ( cdata , 0 , data , oldSize , cdata . length ) ; } final ByteBuffer buffer = ByteBuffer . wrap ( data ) ; final byte [ ] contextId = readBlock ( buffer ) ; assert contextId != null && contextId . length > 0 ; final byte [ ] spaceId = readBlock ( buffer ) ; assert spaceId != null && spaceId . length > 0 ; final byte [ ] scope = readBlock ( buffer ) ; assert scope != null && scope . length > 0 ; final byte [ ] headers = readBlock ( buffer ) ; assert headers != null && headers . length > 0 ; final byte [ ] body = readBlock ( buffer ) ; assert body != null && body . length > 0 ; return new EventEnvelope ( contextId , spaceId , scope , headers , body ) ; }
Receive data from the network .