Code example for ByteBuffer

Methods: hasRemainingget

0
    public ByteBufferInputStream(final ByteBuffer byteBuffer) {
        this.byteBuffer = byteBuffer;
    } 
 
    public int read() throws IOException { 
        if (!byteBuffer.hasRemaining()) {
            return -1; 
        } 
        return byteBuffer.get();
    } 
 
    public static Message buildMessage(Message prototype, ByteBuffer byteBuffer) {
        try { 
            return prototype.toBuilder().mergeFrom(new ByteBufferInputStream(byteBuffer)).build();
        } catch (InvalidProtocolBufferException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            //Never happen 
            throw new RuntimeException(e);
        } 
Stop searching for code, let great code find you!  Add Codota to your java IDE