public Buffer readRawBytes()

in activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java [359:392]


    public Buffer readRawBytes(int size) throws IOException {
        if( size == 0) {
            return new Buffer(new byte[]{});
        }
        if( this.pos+size > limit ) {
            throw new EOFException();
        }
        
        // If the underlying stream is a ByteArrayInputStream
        // then we can avoid an array copy.
        if( bis!=null ) {
            Buffer rc = bis.readBuffer(size);
            if( rc==null || rc.getLength() < size ) {
                throw new EOFException();
            }
            this.pos += rc.getLength();
            return rc;
        }

        // Otherwise we, have to do it the old fasioned way
        byte[] rc = new byte[size];
        int c;
        int pos=0;
        while( pos < size ) {
            c = in.read(rc, pos, size-pos);
            if( c < 0 ) {
                throw new EOFException();
            }
            this.pos += c;
            pos += c;
        }
        
        return new Buffer(rc);
    }