public static void copyBuffer ( WsByteBuffer src , WsByteBuffer dst , int length ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "copyBuffer: length=" + length + "\r\n\tsrc: " + getBufferTraceInfo ( src ) + "\r\n\tdst: " + getBufferTraceInfo ( dst ) ) ; } // Double check that there is enough space in the dst buffer. if ( ( dst . remaining ( ) < length ) || ( src . remaining ( ) < length ) ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "copyBuffer: Not enough space" ) ; } RuntimeException e = new RuntimeException ( "Attempt to copy source buffer to inadequate destination buffer" ) ; FFDCFilter . processException ( e , CLASS_NAME , "762" , src ) ; throw e ; } // If the input buffer has a backing array, a copy will be more efficient. if ( src . hasArray ( ) ) { int newSrcPosition = src . position ( ) + length ; // This buffer has a backing array. Copy the byte array in bulk. dst . put ( src . array ( ) , src . arrayOffset ( ) + src . position ( ) , length ) ; // Advance position of src to show data has been read. src . position ( newSrcPosition ) ; } else { // No backing array. Pull the data into a byte array. byte srcByteArray [ ] = new byte [ length ] ; src . get ( srcByteArray , 0 , length ) ; // Copy the data into the dst buffer with a single put. dst . put ( srcByteArray ) ; } }
Copy all the contents of the source buffer into the destination buffer . The contents copied from the source buffer will be from its position . The data will be copied into the destination buffer starting at its current position .