Package java.nio

Examples of java.nio.ByteBuffer.flip()


        SocketChannel channel = header.getChannel();

        try
        {
            nonBlockingRead( channel, headerBuf );
            headerBuf.flip();
            read = headerBuf.getInt();
            IOUtil.setReceiveBufferSize( channel.socket(), read );
        }
        catch ( IncompleteIOException ioe )
        {
View Full Code Here


        ByteBuffer headerBuf = ByteBufferAllocator.allocate( EJConstants.NIO_HEADER_SIZE, false );
        SocketChannel channel = header.getChannel();

        int length = buffer != null ? buffer.remaining() : 0;
        headerBuf.putInt( length );
        headerBuf.flip();
        try
        {
            nonBlockingWrite( channel, headerBuf );
            IOUtil.setSendBufferSize( channel.socket(), length );
        }
View Full Code Here

            magicBuf = ByteBufferAllocator.allocate( 4, false );
            semiBlockingRead( channel, magicBuf, timeout );
            // at least the handshake must be read in one operation
            // if not prevent us from dealing with bad networks or crappy clients
            if ( magicBuf.hasRemaining() ) return null;
            magicBuf.flip();
            // copy the read four byte into a buffer - we will need them again maybe
            preReadData = new byte[4];
            magicBuf.get( preReadData );
            magicBuf.rewind();
            // read the first four bytes as int
View Full Code Here

        {
            logger.log( Level.FINEST, "HTTP Header read: complete=" + HttpHeaderParser.isComplete( headerBuf )
                    + ", readControl=" + readControl + ", bytes read: " + headerBuf.position() );
        }

        headerBuf.flip();

        if ( logger.isLoggable( Level.FINE ) )
        {
            logger.log( Level.FINE, IOUtil.decodeToString( headerBuf ) );
            headerBuf.position( 0 );
View Full Code Here

                out.write( buffer, 0, read );
                count += read;
            }

            result = out.getBackingBuffer();
            result.flip();
        }
        finally
        {
            IOUtil.closeQuiet( bIn );
            IOUtil.closeQuiet( out );
View Full Code Here

    public static String decodeToString( ByteBuffer dataBuf )
    {
        ByteBuffer tmpBuf = dataBuf.duplicate();
        if ( tmpBuf.position() > 0 )
        {
            tmpBuf.flip();
        }
        return csDefault.decode( tmpBuf ).toString();
    }

    /**
 
View Full Code Here

    public static String decodeToString( ByteBuffer dataBuf, String charset )
    {
        ByteBuffer tmpBuf = dataBuf.duplicate();
        if ( tmpBuf.position() > 0 )
        {
            tmpBuf.flip();
        }
        return Charset.forName( charset ).decode( tmpBuf ).toString();
    }

    /**
 
View Full Code Here

    private String execute() throws IOException
    {
        byte[] tmp = IOUtil.encodeToBytes( "test" );
        ByteBuffer input = ByteBufferAllocator.allocate( tmp.length );
        input.put( tmp );
        input.flip();
        input = (ByteBuffer) client.execute( input );
        input.get( tmp );
        return new String( tmp, "UTF8" );
    }
}
View Full Code Here

    public Object handle( Object obj ) throws Exception
    {
        ByteBuffer input = (ByteBuffer) obj;
        ByteBuffer output = ByteBufferAllocator.allocate( input.remaining() );
        output.put( input );
        output.flip();
        return output;
    }
}
View Full Code Here

  public static long copy(ReadableByteChannel from,
      WritableByteChannel to) throws IOException {
    ByteBuffer buf = ByteBuffer.allocate(BUF_SIZE);
    long total = 0;
    while (from.read(buf) != -1) {
      buf.flip();
      while (buf.hasRemaining()) {
        total += to.write(buf);
      }
      buf.clear();
    }
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.