public static int unshuffle ( ByteBuffer shuffled , BitShuffleType type , ByteBuffer output ) throws IOException { if ( ! shuffled . isDirect ( ) ) { throw new SnappyError ( SnappyErrorCode . NOT_A_DIRECT_BUFFER , "input is not a direct buffer" ) ; } if ( ! output . isDirect ( ) ) { throw new SnappyError ( SnappyErrorCode . NOT_A_DIRECT_BUFFER , "destination is not a direct buffer" ) ; } // input: input[pos(), limit()) // output: shuffled int uPos = shuffled . position ( ) ; int uLen = shuffled . remaining ( ) ; int typeSize = type . getTypeSize ( ) ; if ( uLen % typeSize != 0 ) { throw new IllegalArgumentException ( "length of input shuffled data must be a multiple of the given type size: " + typeSize ) ; } if ( output . remaining ( ) < uLen ) { throw new IllegalArgumentException ( "not enough space for output" ) ; } int numProcessed = impl . unshuffleDirectBuffer ( shuffled , uPos , typeSize , uLen , output , shuffled . position ( ) ) ; assert ( numProcessed == uLen ) ; // pos limit // [ ......BBBBBBB.........] shuffled . limit ( shuffled . position ( ) + numProcessed ) ; return numProcessed ; }
Convert the input bit - shuffled byte array into an original array . The result is dumped to the specified output buffer .