Code example for ByteBuffer

Methods: get, hasArray, hasRemaining, isDirect, position

0
        // source buffer must be not null 
        checkNotNull(source);
        // status must be open and connected 
        checkOpenConnected(); 
        // return immediately if source is full 
        if (!source.hasRemaining()) {
            return 0; 
        } 
 
        ByteBuffer writeBuffer = null;
        byte[] writeArray = null;
        int oldposition = source.position();
        int result;
        if (source.isDirect() || source.hasArray()) {
            writeBuffer = source;
        } else { 
            writeArray = new byte[source.remaining()];
            source.get(writeArray);
            writeBuffer = ByteBuffer.wrap(writeArray);
        } 
        result = writeImpl(writeBuffer);
        if (result > 0) {
            source.position(oldposition + result);
        } 
        return result;
    } 
 
    /**