DataUtils { public final static byte [] unsignedLongToByteArray(final long value) { if( 0 == value ) return _byte0; if( 0 <= value && value <= 0x00FF ) { byte [] bb = new byte[1]; bb[0] = (byte) (value & 0x00FF); return bb; } byte [] out = null; int offset = -1; for(int i = 7; i >=0; --i) { byte b = (byte) ((value >> (i * 8)) & 0xFF); if( out == null && b != 0 ) { out = new byte[i+1]; offset = i; } if( out != null ) out[ offset - i ] = b; } return out; }  static int compare(T left, T right); static int compare(byte [] left, byte [] right); static int compare(ArrayList<byte []> left, ArrayList<byte []> right); static String printBytes(byte [] bytes); static String printHexBytes(byte [] bytes); static byte [] base64Decode(byte [] input); static byte [] base64Encode(byte [] input); static String base64Encode(byte [] input, Integer lineLength); @Deprecated static byte [] lineWrapBase64(byte [] input, int lineLength); static String lineWrap(String inputString, int lineLength); static boolean arrayEquals(byte[] left, byte[] right); static boolean arrayEquals(byte[] left, byte[] right, int length); static boolean isBinaryPrefix(byte [] prefix, byte [] data); static void deleteDirectory(File directory); static byte[] getBytesFromFile(File file); static byte [] getBytesFromStream(InputStream input); static String getUTF8StringFromBytes(byte [] stringBytes); static byte [] getBytesFromUTF8String(String stringData); static int bytencmp(byte[] arr1, int offset1, byte[] arr2, int offset2, int count); static int bytencmp(byte [] arr1, byte [] arr2, int count); static int byteindex(byte [] array, int startingOffset, byte byteToFind); static int byteindex(byte [] array, byte byteToFind); static int byterindex(byte [] array, int startingOffset, byte byteToFind); static int byterindex(byte [] array, byte byteToFind); static int occurcount(byte [] array, int startingOffset, int length, byte byteToFind); static int occurcount(byte [] array, int length, byte byteToFind); static int occurcount(byte [] array, byte byteToFind); static byte [][] binarySplit(byte [] array, int startingOffset, byte splitValue); static byte [][] binarySplit(byte [] array, byte splitValue); static byte [] subarray(byte [] array, int offset, int len); final static long byteArrayToUnsignedLong(final byte [] src); final static long byteArrayToUnsignedLong(final byte [] src, int start); final static byte [] unsignedLongToByteArray(final long value); final static byte [] unsignedLongToByteArray(final long value, final byte firstByte); static final int BITS_PER_BYTE; static final String EMPTY; static final String LINE_SEPARATOR; static Charset UTF8_CHARSET; static final int LINELEN; }
@Test public void testUnsignedLongToByteArray() throws Exception { for(long v : testset) { byte [] truth = longToByteArray(v); byte [] test = DataUtils.unsignedLongToByteArray(v); Assert.assertArrayEquals(truth, test); } }
@Test public void testSegmentationProfile() throws Exception { long v; for(v = 0; v < 4096; v++) { byte [] truth = segmentToByteArray(v); byte [] test = DataUtils.unsignedLongToByteArray(v, SegmentationProfile.SEGMENT_MARKER); Assert.assertArrayEquals(String.format("Mismatch value %d", v), truth, test); } }