@Override public void close() throws IOException { wrapped.write(CharsetUtil.getUtf8Bytes(stringBuilder.toString())); wrapped.close(); }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } // TODO: allow a charset to be passed in? return CharsetUtil.newUtf8String(Base64.decodeBase64(CharsetUtil.getUtf8Bytes(text))); }
/** * @return The post body as a string, assuming UTF-8 encoding. * TODO: We should probably tolerate other encodings, based on the * Content-Type header. */ public String getPostBodyAsString() { return CharsetUtil.newUtf8String(postBody); }
/** * Calculate hash value for response and update metadata value (DATA_HASH) * @return hash value */ public String getHash(HttpResponse response) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(response.getResponseAsBytes()); byte[] md5val = md5.digest(); return CharsetUtil.newUtf8String(Base32.encodeBase32(md5val)); } catch (NoSuchAlgorithmException e) { // Should not happen if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "getHash", MessageKeys.ERROR_GETTING_MD5); } } return null; }
private void init(String masterKey) { if (masterKey == null) { throw new IllegalArgumentException("Unexpectedly empty masterKey:" + masterKey); } masterKey = masterKey.trim(); byte[] keyBytes = CharsetUtil.getUtf8Bytes(masterKey); init(keyBytes); }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } // TODO: allow a charset to be passed in? return CharsetUtil.newUtf8String(Base64.decodeBase64(CharsetUtil.getUtf8Bytes(text))); }
private Map<String, String> deserialize(byte[] plain) { String base = CharsetUtil.newUtf8String(plain); // replaces [&=] regex String[] items = StringUtils.splitPreserveAllTokens(base, "&="); Map<String, String> map = Maps.newHashMapWithExpectedSize(items.length); for (int i=0; i < items.length; ) { String key = Utf8UrlCoder.decode(items[i++]); String val = Utf8UrlCoder.decode(items[i++]); map.put(key, val); } return map; } }
/** * @param body The response string. Converted to UTF-8 bytes and copied when set. */ public HttpResponseBuilder setResponseString(String body) { setContentBytes(CharsetUtil.getUtf8Bytes(body), Charsets.UTF_8); return this; }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } // TODO: allow a charset to be passed in? return CharsetUtil.newUtf8String(Base64.decodeBase64(CharsetUtil.getUtf8Bytes(text))); }
private Map<String, String> deserialize(byte[] plain) { String base = CharsetUtil.newUtf8String(plain); // replaces [&=] regex String[] items = StringUtils.splitPreserveAllTokens(base, "&="); Map<String, String> map = Maps.newHashMapWithExpectedSize(items.length); for (int i=0; i < items.length; ) { String key = Utf8UrlCoder.decode(items[i++]); String val = Utf8UrlCoder.decode(items[i++]); map.put(key, val); } return map; } }
/** * @param body The response string. Converted to UTF-8 bytes and copied when set. */ public HttpResponseBuilder setResponseString(String body) { setContentBytes(CharsetUtil.getUtf8Bytes(body), Charsets.UTF_8); return this; }
private Map<String, String> deserialize(byte[] plain) { String base = CharsetUtil.newUtf8String(plain); // replaces [&=] regex String[] items = StringUtils.splitPreserveAllTokens(base, "&="); Map<String, String> map = Maps.newHashMapWithExpectedSize(items.length); for (int i=0; i < items.length; ) { String key = Utf8UrlCoder.decode(items[i++]); String val = Utf8UrlCoder.decode(items[i++]); map.put(key, val); } return map; } }
/** * @param body The response string. Converted to UTF-8 bytes and copied when set. */ public HttpResponseBuilder setResponseString(String body) { setContentBytes(CharsetUtil.getUtf8Bytes(body), Charsets.UTF_8); return this; }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
private void init(String masterKey) { if (masterKey == null) { throw new IllegalArgumentException("Unexpectedly empty masterKey:" + masterKey); } masterKey = masterKey.trim(); byte[] keyBytes = CharsetUtil.getUtf8Bytes(masterKey); init(keyBytes); }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
private void init(String masterKey) { if (masterKey == null) { throw new IllegalArgumentException("Unexpectedly empty masterKey:" + masterKey); } masterKey = masterKey.trim(); byte[] keyBytes = CharsetUtil.getUtf8Bytes(masterKey); init(keyBytes); }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
/** * Encode the input for transfer. We use something a lot like HTML form * encodings. * @param in map of parameters to encode */ private byte[] serialize(Map<String, String> in) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> val : in.entrySet()) { sb.append(Utf8UrlCoder.encode(val.getKey())); sb.append('='); sb.append(Utf8UrlCoder.encode(val.getValue())); sb.append('&'); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); // Remove the last & } return CharsetUtil.getUtf8Bytes(sb.toString()); }
/** * Encode the input for transfer. We use something a lot like HTML form * encodings. * @param in map of parameters to encode */ private byte[] serialize(Map<String, String> in) { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> val : in.entrySet()) { sb.append(Utf8UrlCoder.encode(val.getKey())); sb.append('='); sb.append(Utf8UrlCoder.encode(val.getValue())); sb.append('&'); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); // Remove the last & } return CharsetUtil.getUtf8Bytes(sb.toString()); }