Code example for ByteBuffer

Methods: array, hasArray, limit, position

0
    //------------------------------------------ 
    private final int getArray(ByteBuffer out) {
        if(out.hasArray()){
            // BEGIN android-changed: take arrayOffset into account 
            output = out.array();
            outEnd = out.arrayOffset() + out.limit();
            return out.arrayOffset() + out.position();
            // END android-changed 
        }else{ 
            outEnd = out.remaining();
            // BEGIN android-added 
            if (allocatedOutput == null || (outEnd > allocatedOutput.length)) {
                allocatedOutput = new byte[outEnd];
            } 
            output = allocatedOutput;
            // END android-added 
            //since the new 
            // buffer start position 
            // is 0 
            return 0; 
        }