private boolean verify ( ByteBuffer content ) { ByteBuffer bb = ByteBuffer . allocate ( l2i ( getContentSize ( ) + ( deadBytes != null ? deadBytes . limit ( ) : 0 ) ) ) ; getContent ( bb ) ; if ( deadBytes != null ) { deadBytes . rewind ( ) ; while ( deadBytes . remaining ( ) > 0 ) { bb . put ( deadBytes ) ; } } content . rewind ( ) ; bb . rewind ( ) ; if ( content . remaining ( ) != bb . remaining ( ) ) { LOG . error ( "{}: remaining differs {} vs. {}" , this . getType ( ) , content . remaining ( ) , bb . remaining ( ) ) ; return false ; } int p = content . position ( ) ; for ( int i = content . limit ( ) - 1 , j = bb . limit ( ) - 1 ; i >= p ; i -- , j -- ) { byte v1 = content . get ( i ) ; byte v2 = bb . get ( j ) ; if ( v1 != v2 ) { LOG . error ( "{}: buffers differ at {}: {}/{}" , this . getType ( ) , i , v1 , v2 ) ; byte [ ] b1 = new byte [ content . remaining ( ) ] ; byte [ ] b2 = new byte [ bb . remaining ( ) ] ; content . get ( b1 ) ; bb . get ( b2 ) ; LOG . error ( "original : {}" , Hex . encodeHex ( b1 , 4 ) ) ; LOG . error ( "reconstructed : {}" , Hex . encodeHex ( b2 , 4 ) ) ; return false ; } } return true ; }
Verifies that a box can be reconstructed byte - exact after parsing .