/** * Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. * The returned array will be double the length of the passed array, as it takes two characters to represent any * given byte. * * @param data * a byte[] to convert to Hex characters * @return A char[] containing lower-case hexadecimal characters */ public static char[] encodeHex(final byte[] data) { return encodeHex(data, true); }
/** * Converts a byte buffer into an array of characters representing the hexadecimal values of each byte in order. * The returned array will be double the length of the passed array, as it takes two characters to represent any * given byte. * * @param data * a byte buffer to convert to Hex characters * @return A char[] containing lower-case hexadecimal characters * @since 1.11 */ public static char[] encodeHex(final ByteBuffer data) { return encodeHex(data, true); }
/** * Converts a byte buffer into an array of characters representing the hexadecimal values of each byte in order. * The returned array will be double the length of the passed array, as it takes two characters to represent any * given byte. * * @param data * a byte buffer to convert to Hex characters * @param toLowerCase * <code>true</code> converts to lowercase, <code>false</code> to uppercase * @return A char[] containing hexadecimal characters in the selected case * @since 1.11 */ public static char[] encodeHex(final ByteBuffer data, final boolean toLowerCase) { return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); }
/** * Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order. * The returned array will be double the length of the passed array, as it takes two characters to represent any * given byte. * * @param data * a byte[] to convert to Hex characters * @param toLowerCase * <code>true</code> converts to lowercase, <code>false</code> to uppercase * @return A char[] containing hexadecimal characters in the selected case * @since 1.4 */ public static char[] encodeHex(final byte[] data, final boolean toLowerCase) { return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); }
/** * Converts a byte buffer into a String representing the hexadecimal values of each byte in order. The returned * String will be double the length of the passed array, as it takes two characters to represent any given byte. * * @param data * a byte buffer to convert to Hex characters * @return A String containing lower-case hexadecimal characters * @since 1.11 */ public static String encodeHexString(final ByteBuffer data) { return new String(encodeHex(data)); }
/** * Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned * String will be double the length of the passed array, as it takes two characters to represent any given byte. * * @param data * a byte[] to convert to Hex characters * @return A String containing lower-case hexadecimal characters * @since 1.4 */ public static String encodeHexString(final byte[] data) { return new String(encodeHex(data)); }
private void renewSeedInternal() { String currentSeed = this.seed; String newSeed = currentSeed; byte[] bytes = new byte[SEED_NUM_BYTES]; while (Objects.equals(newSeed, currentSeed)) { RANDOM.nextBytes(bytes); newSeed = new String(Hex.encodeHex(bytes)); } this.seed = newSeed; }
/** * Converts an array of bytes into a String representing the hexadecimal values of each byte in order. The returned * String will be double the length of the passed array, as it takes two characters to represent any given byte. * * @param data * a byte[] to convert to Hex characters * @param toLowerCase * <code>true</code> converts to lowercase, <code>false</code> to uppercase * @return A String containing lower-case hexadecimal characters * @since 1.11 */ public static String encodeHexString(final byte[] data, final boolean toLowerCase) { return new String(encodeHex(data, toLowerCase)); }
/** * Converts a byte buffer into a String representing the hexadecimal values of each byte in order. The returned * String will be double the length of the passed array, as it takes two characters to represent any given byte. * * @param data * a byte buffer to convert to Hex characters * @param toLowerCase * <code>true</code> converts to lowercase, <code>false</code> to uppercase * @return A String containing lower-case hexadecimal characters * @since 1.11 */ public static String encodeHexString(final ByteBuffer data, final boolean toLowerCase) { return new String(encodeHex(data, toLowerCase)); }
/** * Converts a byte buffer into an array of characters representing the hexadecimal values of each byte in order. * The returned array will be double the length of the passed array, as it takes two characters to represent any * given byte. * * @param data * a byte buffer to convert to Hex characters * @param toDigits * the output alphabet (must be at least 16 characters) * @return A char[] containing the appropriate characters from the alphabet * For best results, this should be either upper- or lower-case hex. * @since 1.11 */ protected static char[] encodeHex(final ByteBuffer data, final char[] toDigits) { return encodeHex(data.array(), toDigits); }
private Path createTargetPath(final StorageMetadata metadata, final Path projectsPath) { return new Path(projectsPath, String.format("%s-%s.zip", String.valueOf(metadata.getProjectId()), new String(Hex.encodeHex(metadata.getHash())) )); }
private String buildFingerprint(List<Stream> streams) { final MessageDigest sha1Digest = DigestUtils.getSha1Digest(); final StringBuilder sb = new StringBuilder(); for (Stream stream : Ordering.from(getStreamComparator()).sortedCopy(streams)) { sb.append(stream.hashCode()); for (StreamRule rule : Ordering.from(getStreamRuleComparator()).sortedCopy(stream.getStreamRules())) { sb.append(rule.hashCode()); } for (Output output : Ordering.from(getOutputComparator()).sortedCopy(stream.getOutputs())) { sb.append(output.hashCode()); } } return String.valueOf(Hex.encodeHex(sha1Digest.digest(sb.toString().getBytes(StandardCharsets.US_ASCII)))); }
@Test public void testEncodeHexByteBufferHelloWorldUpperCaseHex() { final ByteBuffer b = StringUtils.getByteBufferUtf8("Hello World"); final String expected = "48656C6C6F20576F726C64"; char[] actual; actual = Hex.encodeHex(b); assertFalse(expected.equals(new String(actual))); actual = Hex.encodeHex(b, true); assertFalse(expected.equals(new String(actual))); actual = Hex.encodeHex(b, false); assertTrue(expected.equals(new String(actual))); }
@Test public void testEncodeHexByteArrayHelloWorldUpperCaseHex() { final byte[] b = StringUtils.getBytesUtf8("Hello World"); final String expected = "48656C6C6F20576F726C64"; char[] actual; actual = Hex.encodeHex(b); assertFalse(expected.equals(new String(actual))); actual = Hex.encodeHex(b, true); assertFalse(expected.equals(new String(actual))); actual = Hex.encodeHex(b, false); assertTrue(expected.equals(new String(actual))); }
@Test public void testEncodeHexByteArrayHelloWorldLowerCaseHex() { final byte[] b = StringUtils.getBytesUtf8("Hello World"); final String expected = "48656c6c6f20576f726c64"; char[] actual; actual = Hex.encodeHex(b); assertEquals(expected, new String(actual)); actual = Hex.encodeHex(b, true); assertEquals(expected, new String(actual)); actual = Hex.encodeHex(b, false); assertFalse(expected.equals(new String(actual))); }
@Test public void testEncodeHexByteBufferHelloWorldLowerCaseHex() { final ByteBuffer b = StringUtils.getByteBufferUtf8("Hello World"); final String expected = "48656c6c6f20576f726c64"; char[] actual; actual = Hex.encodeHex(b); assertEquals(expected, new String(actual)); actual = Hex.encodeHex(b, true); assertEquals(expected, new String(actual)); actual = Hex.encodeHex(b, false); assertFalse(expected.equals(new String(actual))); }
@Test public void testEncodeHex_ByteBufferOfZeroes() { final char[] c = Hex.encodeHex(ByteBuffer.allocate(36)); assertEquals("000000000000000000000000000000000000000000000000000000000000000000000000", new String(c)); }
@Test public void testEncodeHexByteArrayZeroes() { final char[] c = Hex.encodeHex(new byte[36]); assertEquals("000000000000000000000000000000000000000000000000000000000000000000000000", new String(c)); }
@Test public void testEncodeHexByteBufferEmpty() { assertTrue(Arrays.equals(new char[0], Hex.encodeHex(ByteBuffer.allocate(0)))); assertTrue(Arrays.equals(new byte[0], new Hex().encode(ByteBuffer.allocate(0)))); }
@Test public void testEncodeHexByteArrayEmpty() { assertTrue(Arrays.equals(new char[0], Hex.encodeHex(new byte[0]))); assertTrue(Arrays.equals(new byte[0], new Hex().encode(new byte[0]))); }