@Override public BaseEncoding upperCase() { return delegate.upperCase().withSeparator(separator, afterEveryChars); }
@Override public BaseEncoding upperCase() { return delegate.upperCase().withSeparator(separator, afterEveryChars); }
@Override public BaseEncoding upperCase() { return delegate.upperCase().withSeparator(separator, afterEveryChars); }
/** * Calculates the hashcode for the serializable object based on its content. * @param object serializable object. * @return the hashcode for serializable object. */ private static String getHashCodeBasedOnObjectContent(Serializable object) { try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // in-memory serialization of Configuration serialize(object, outputStream); // Instead of hexEncoding outputStream.toByteArray() directly we // use a message digest here to keep the length of the // hashcode reasonable final MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(outputStream.toByteArray()); return BaseEncoding.base16().upperCase().encode(digest.digest()); } catch (final IOException | NoSuchAlgorithmException ex) { // rethrow as unchecked exception throw new IllegalStateException("Unable to calculate hashcode.", ex); } }
public void testBase64CannotUpperCase() { try { base64().upperCase(); fail(); } catch (IllegalStateException expected) { // success } }
public void testBase16UpperCaseIsNoOp() { assertSame(base16(), base16().upperCase()); }
public void testBase32HexUpperCaseIsNoOp() { assertSame(base32Hex(), base32Hex().upperCase()); }
public void testBase32UpperCaseIsNoOp() { assertSame(base32(), base32().upperCase()); }
@Test public void testExternalResourceIsSavedInCache() throws Exception { final Configuration config = new DefaultConfiguration("myName"); final String filePath = temporaryFolder.newFile().getPath(); final PropertyCacheFile cache = new PropertyCacheFile(config, filePath); cache.load(); final Set<String> resources = new HashSet<>(); final String pathToResource = getPath("InputPropertyCacheFileExternal.properties"); resources.add(pathToResource); cache.putExternalResources(resources); final MessageDigest digest = MessageDigest.getInstance("SHA-1"); final URI uri = CommonUtil.getUriByFilename(pathToResource); final byte[] input = ByteStreams.toByteArray(new BufferedInputStream(uri.toURL().openStream())); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(out)) { oos.writeObject(input); } digest.update(out.toByteArray()); final String expected = BaseEncoding.base16().upperCase().encode(digest.digest()); assertEquals("Hashes are not equal", expected, cache.get("module-resource*?:" + pathToResource)); }
private static void testEncodingWithCasing( BaseEncoding encoding, String decoded, String encoded) { testEncodingWithSeparators(encoding, decoded, encoded); testEncodingWithSeparators(encoding.upperCase(), decoded, Ascii.toUpperCase(encoded)); testEncodingWithSeparators(encoding.lowerCase(), decoded, Ascii.toLowerCase(encoded)); }
@GwtIncompatible // Reader/Writer private static void testStreamingEncodingWithCasing( BaseEncoding encoding, String decoded, String encoded) throws IOException { testStreamingEncodingWithSeparators(encoding, decoded, encoded); testStreamingEncodingWithSeparators(encoding.upperCase(), decoded, Ascii.toUpperCase(encoded)); testStreamingEncodingWithSeparators(encoding.lowerCase(), decoded, Ascii.toLowerCase(encoded)); }
private static String encodeCassandraHexString(byte[] data) { return CASSANDRA_PREFIX + BaseEncoding.base16().upperCase().encode(data); } }
private static String encodeCassandraHexBytes(byte[] bytes) { return "0x" + BaseEncoding.base16().upperCase().encode(bytes); }
@Override public BaseEncoding upperCase() { return delegate.upperCase().withSeparator(separator, afterEveryChars); }
@Override public BaseEncoding upperCase() { return delegate.upperCase().withSeparator(separator, afterEveryChars); }
@Override public BaseEncoding upperCase() { return delegate.upperCase().withSeparator(separator, afterEveryChars); }
@Override public BaseEncoding upperCase() { return delegate.upperCase().withSeparator(separator, afterEveryChars); }
public void testBase64CannotUpperCase() { try { base64().upperCase(); fail(); } catch (IllegalStateException expected) { // success } }
private static void testEncodingWithCasing( BaseEncoding encoding, String decoded, String encoded) { testEncodingWithSeparators(encoding, decoded, encoded); testEncodingWithSeparators(encoding.upperCase(), decoded, Ascii.toUpperCase(encoded)); testEncodingWithSeparators(encoding.lowerCase(), decoded, Ascii.toLowerCase(encoded)); }
@GwtIncompatible // Reader/Writer private static void testStreamingEncodingWithCasing( BaseEncoding encoding, String decoded, String encoded) throws IOException { testStreamingEncodingWithSeparators(encoding, decoded, encoded); testStreamingEncodingWithSeparators(encoding.upperCase(), decoded, Ascii.toUpperCase(encoded)); testStreamingEncodingWithSeparators(encoding.lowerCase(), decoded, Ascii.toLowerCase(encoded)); }