public static byte [ ] longToUID ( final long uid , final short width ) { // Verify that we're going to drop bytes that are 0. final byte [ ] padded = Bytes . fromLong ( uid ) ; for ( int i = 0 ; i < padded . length - width ; i ++ ) { if ( padded [ i ] != 0 ) { final String message = "UID " + Long . toString ( uid ) + " was too large for " + width + " bytes" ; LOG . error ( "OMG " + message ) ; throw new IllegalStateException ( message ) ; } } // Shrink the ID on the requested number of bytes. return Arrays . copyOfRange ( padded , padded . length - width , padded . length ) ; }
Converts a Long to a byte array with the proper UID width