Buffer hasRemaining - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Buffer hasRemaining method.

This code example shows how to use the following methods:hasRemaining, remaining, get
        return buffer.get();
    } 
 
    @Override 
    public int read(byte[] b, int off, int len) throws IOException {
        if (!buffer.hasRemaining()) {
            return -1; 
        } 
 
        len = Math.min(len, buffer.remaining());
        buffer.get(b, off, len);
        return len;
    } 
 
    @Override 
    public long skip(long n) throws IOException {
        if (n > buffer.remaining()) {
            int ret = buffer.position();
            buffer.position(buffer.limit());
            return ret;
9
CodeRank
This code example shows how to use the following methods:hasRemaining, rewind
    return numInserted;
  } 
 
  public void add(long value) throws IOException
  { 
    if (! endBuffer.hasRemaining()) {
      endBuffer.rewind();
      flattener.write(StupidResourceHolder.create(endBuffer));
      endBuffer = LongBuffer.allocate(sizePer);
      endBuffer.mark();
    } 
 
    endBuffer.put(value);
    ++numInserted;
  } 
 
  public void closeAndConsolidate(OutputSupplier<? extends OutputStream> consolidatedOut) throws IOException
  { 
    endBuffer.limit(endBuffer.position());
    endBuffer.rewind();
8
CodeRank
This code example shows how to use the following methods:hasRemaining, rewind
    return numInserted;
  } 
 
  public void add(float value) throws IOException
  { 
    if (! endBuffer.hasRemaining()) {
      endBuffer.rewind();
      flattener.write(StupidResourceHolder.create(endBuffer));
      endBuffer = FloatBuffer.allocate(sizePer);
      endBuffer.mark();
    } 
 
    endBuffer.put(value);
    ++numInserted;
  } 
 
  public void closeAndConsolidate(OutputSupplier<? extends OutputStream> consolidatedOut) throws IOException
  { 
    endBuffer.limit(endBuffer.position());
    endBuffer.rewind();
8
CodeRank
This code example shows how to use the following methods:capacity, flip, hasRemaining, position, duplicate
7
CodeRank
This code example shows how to use the following methods:hasRemaining
    } 
 
    private boolean readAcknowledgement() { 
        int read;
        try { 
            read = handler.getChannel().read(ackBuffer);
            if (read < 0) {
                if (log.isInfoEnabled()) { 
                    log.info("closing channel"); 
                } 
                inError = true;
                return false; 
            } else if (ackBuffer.hasRemaining()) {
                // extra read attempt 
                int plusRead = handler.getChannel().read(ackBuffer);
                if (plusRead < 0) {
                    if (log.isInfoEnabled()) { 
                        log.info("closing channel"); 
                    } 
                    inError = true;
7
CodeRank
This code example shows how to use the following methods:flip, hasRemaining, compact
    public void produceContent( 
            final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
        if (this.channel == null) {
            this.channel = Channels.newChannel(this.entity.getContent());
        } 
        final int i = this.channel.read(this.buffer);
        this.buffer.flip();
        encoder.write(this.buffer);
        final boolean buffering = this.buffer.hasRemaining();
        this.buffer.compact();
        if (i == -1 && !buffering) {
            encoder.complete();
            close(); 
        } 
    } 
 
    public boolean isRepeatable() { 
        return this.entity.isRepeatable();
    } 
 
7
CodeRank
This code example shows how to use the following methods:hasRemaining
    } 
 
    /* ------------------------------------------------------------------------------- */ 
     public synchronized void write(ByteBuffer buffer)
     { 
         if (buffer.hasRemaining())
         { 
             _buffers=LazyList.add(_buffers,buffer); 
            this.notify();
         } 
         else 
             recycle(buffer);
     } 
 
    /* ------------------------------------------------------------------------------- */ 
    private synchronized boolean waitForContent() 
        throws InterruptedIOException 
    { 
        if (_buffer!=null)
        { 

6
CodeRank
This code example shows how to use the following methods:capacity, hasRemaining, isReadOnly, limit, position
    @Test 
    public void testGetByteBuffer() { 
        ByteBuffer result = fixture.getByteBuffer();
 
        assertNotNull(result);
        assertEquals("java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]", result.toString());
        assertEquals(false, result.isDirect());
        assertEquals(true, result.hasArray());
        assertEquals(0, result.arrayOffset());
        assertEquals(0, result.limit());
        assertEquals(0, result.remaining());
        assertEquals(0, result.position());
        assertEquals(0, result.capacity());
        assertEquals(false, result.hasRemaining());
        assertEquals(false, result.isReadOnly());
    } 
 
    /** 
     * Run the ByteOrder getByteOrder() method test. 
     */ 
6
CodeRank
This code example shows how to use the following methods:hasRemaining, limit, position, array, arrayOffset
	} 
 
	@Override 
	protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer source) throws Exception {
		ByteBuffer buffer = source.toByteBuffer();
		if(!buffer.hasRemaining())
			return null; 
 
		byte[] bytes = buffer.array();
		int offset = buffer.arrayOffset() + buffer.position();
		int length = buffer.arrayOffset() + buffer.limit();
 
		int noffset = pac.execute(bytes, offset, length);
		if(noffset > offset)
			source.skipBytes(noffset - offset);
 
		if(pac.isFinished()) {
			MessagePackObject msg = pac.getData();
			pac.reset();
			return msg;
6
CodeRank
This code example shows how to use the following methods:flip, hasRemaining, compact
    } 
 
    public void produceContent( 
            final ContentEncoder encoder,
            final IOControl ioctrl) throws IOException {
        int i = this.channel.read(this.buffer);
        this.buffer.flip();
        encoder.write(this.buffer);
        boolean buffering = this.buffer.hasRemaining();
        this.buffer.compact();
        if (i == -1 && !buffering) {
            encoder.complete();
            this.channel.close();
        } 
    } 
 
    public void finish() { 
        try { 
            this.channel.close();
        } catch (IOException ignore) {
7
CodeRank

Related Buffer hasRemaining Questions & Answers:

hasRemaining Method Overview
Tells whether there are any elements between the current position and the limit.
See Code Examples for other Java 8 Buffer Methods: