Package java.nio

Examples of java.nio.ByteBuffer.remaining()


        // Write until there's not more data ...
        while (!queue.isEmpty()) {
          ByteBuffer buf = queue.get(0);
          socketChannel.write(buf);

          if (buf.remaining() > 0) {
            // ... or the socket's buffer fills up
            break;
          }
          queue.remove(0);
        }
View Full Code Here


            dataBuf.flip();

            if ( log.isLoggable( Level.FINE ) )
            {
                byte[] tmp = new byte[dataBuf.remaining()];
                dataBuf.get( tmp );
                dataBuf.position( 0 );
                log.log( Level.FINE, "Client request read:\n" + new String( tmp, EJConstants.EJOE_DEFAULT_CHARSET ) );
            }
View Full Code Here

                    dataBuf.flip();
                }

                if ( log.isLoggable( Level.FINE ) )
                {
                    byte[] tmp = new byte[dataBuf.remaining()];
                    dataBuf.get( tmp );
                    dataBuf.position( 0 );
                    log.log( Level.FINE, "Going to send request..."
                            + new String( tmp, EJConstants.EJOE_DEFAULT_CHARSET ) );
                }
View Full Code Here

            if ( header.isClient() )
            {
                // ok, get the control bits as well as the adapter name in a
                // ByteChannel
                ByteBuffer tmpBuf = header.toByteBuffer();
                magicBuf = ByteBufferAllocator.allocate( tmpBuf.remaining() + 4, false );
                magicBuf.putInt( EJConstants.EJOE_MAGIC_NUMBER );
                magicBuf.put( tmpBuf );
                magicBuf.flip();
                logger.log( Level.FINEST, "Sending Clientheader: " + header );
                semiBlockingWrite( channel, magicBuf, timeout );
View Full Code Here

        long timePeriod = -1;
        do
        {
            limit = headerBuf.limit();
            // increase the byte buffer if it's free memory falls below 20 percent
            if ( headerBuf.remaining() <= (limit / 5) )
            {
                logger.log( Level.FINEST, "Allocating additional " + (limit / 2) + "b for buffer with " + limit + "b" );
                headerBuf = ByteBufferAllocator.reAllocate( headerBuf, limit + (limit / 2) );
            }
View Full Code Here

            return 0;
        }
        int olen = len;
        while(true) {
            ByteBuffer bb = link.peekFirst();
            if(len < bb.remaining()) {
                bb.get(b, off, len);
                return olen;
            }
            int rem = bb.remaining();
            bb.get(b, off, rem);
View Full Code Here

            ByteBuffer bb = link.peekFirst();
            if(len < bb.remaining()) {
                bb.get(b, off, len);
                return olen;
            }
            int rem = bb.remaining();
            bb.get(b, off, rem);
            len -= rem;
            off += rem;
            if(!removeFirstLink(bb)) {
                break;
View Full Code Here

    public boolean tryRefer(BufferReferer ref, int len) throws IOException {
        ByteBuffer bb = link.peekFirst();
        if(bb == null) {
            throw new EndOfBufferException();
        } else if(bb.remaining() < len) {
            return false;
        }
        boolean success = false;
        int pos = bb.position();
        int lim = bb.limit();
View Full Code Here

            if(success) {
                bb.position(pos+len);
            } else {
                bb.position(pos);
            }
            if(bb.remaining() == 0) {
                removeFirstLink(bb);
            }
        }
        return true;
    }
View Full Code Here

        return true;
    }

    public byte readByte() throws EOFException {
        ByteBuffer bb = link.peekFirst();
        if(bb == null || bb.remaining() == 0) {
            throw new EndOfBufferException();
        }
        byte result = bb.get();
        if(bb.remaining() == 0) {
            removeFirstLink(bb);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.