@Override public void close() throws IOException { wrapped.write(CharsetUtil.getUtf8Bytes(stringBuilder.toString())); wrapped.close(); }
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); }
/** * @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; }
/** * @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; }
/** * @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; }
protected BlobCrypter getBlobCrypter(String fileName) { BasicBlobCrypter c = new BasicBlobCrypter(CharsetUtil.getUtf8Bytes(fileName)); c.timeSource = timeSource; return c; }
/** * Validate a xml string against a supplied schema. * * @param xml * the xml presented as a string * @param schema * an input stream containing the xsd * @return a list of errors or a 0 lenght string if none. */ public static String validate(String xml, InputStream schema) { return validate(new ByteArrayInputStream(CharsetUtil.getUtf8Bytes(xml)), schema); }
private void testStringOfLength(int len) { StringBuilder sb = new StringBuilder(); for (int i=0; i < len; ++i) { sb.append('a'); } byte[] out = CharsetUtil.getUtf8Bytes(sb.toString()); assertEquals(len, out.length); for (int i=0; i < len; ++i) { assertEquals('a', out[i]); } }
private void testStringOfLength(int len) { StringBuilder sb = new StringBuilder(); for (int i=0; i < len; ++i) { sb.append('a'); } byte[] out = CharsetUtil.getUtf8Bytes(sb.toString()); assertEquals(len, out.length); for (int i=0; i < len; ++i) { assertEquals('a', out[i]); } }
private void testStringOfLength(int len) { StringBuilder sb = new StringBuilder(); for (int i=0; i < len; ++i) { sb.append('a'); } byte[] out = CharsetUtil.getUtf8Bytes(sb.toString()); assertEquals(len, out.length); for (int i=0; i < len; ++i) { assertEquals('a', out[i]); } }
@Test public void testLatin1() { ArrayAssert.assertEquals(LATIN1_UTF8_DATA, CharsetUtil.getUtf8Bytes(LATIN1_STRING)); } }
@Test public void testLatin1() { ArrayAssert.assertEquals(LATIN1_UTF8_DATA, CharsetUtil.getUtf8Bytes(LATIN1_STRING)); } }
@Test public void testBodyHashNoContentType() throws Exception { FakeHttpServletRequest req = new FakeHttpServletRequest(); req.setPostData(CharsetUtil.getUtf8Bytes("")); String hash = new String(Base64.encodeBase64(DigestUtils.sha(CharsetUtil .getUtf8Bytes(""))), "UTF-8"); OAuthAuthenticationHandler.verifyBodyHash(req, hash); } }
@Test public void testBodyHashNoContentType() throws Exception { FakeHttpServletRequest req = new FakeHttpServletRequest(); req.setPostData(CharsetUtil.getUtf8Bytes("")); String hash = new String(Base64.encodeBase64(DigestUtils.sha(CharsetUtil .getUtf8Bytes(""))), "UTF-8"); OAuthAuthenticationHandler.verifyBodyHash(req, hash); } }
@Test public void testBodyHashNoContentType() throws Exception { FakeHttpServletRequest req = new FakeHttpServletRequest(); req.setPostData(CharsetUtil.getUtf8Bytes("")); String hash = new String(Base64.encodeBase64(DigestUtils.sha(CharsetUtil.getUtf8Bytes(""))), "UTF-8"); OAuthAuthenticationHandler.verifyBodyHash(req, hash); } }
@Test public void testBodySigning() throws Exception { FakeHttpServletRequest req = new FakeHttpServletRequest(); req.setContentType("text/plain"); String body = "BODY"; req.setPostData(CharsetUtil.getUtf8Bytes(body)); String hash = new String(Base64.encodeBase64(GenericDigestUtils.digest(CharsetUtil .getUtf8Bytes(body))), "UTF-8"); req.setParameter(OAuthConstants.OAUTH_BODY_HASH, hash); OAuthAuthenticationHandler.verifyBodyHash(req, hash); }
@Test public void testStashBody() throws Exception { FakeHttpServletRequest req = new FakeHttpServletRequest(); String body = "BODY"; req.setPostData(CharsetUtil.getUtf8Bytes(body)); byte[] bytes = OAuthAuthenticationHandler.readBody(req); assertTrue(Arrays.equals(bytes, CharsetUtil.getUtf8Bytes(body))); assertEquals(req.getAttribute(AuthenticationHandler.STASHED_BODY), bytes); }
@Test public void testStashBody() throws Exception { FakeHttpServletRequest req = new FakeHttpServletRequest(); String body = "BODY"; req.setPostData(CharsetUtil.getUtf8Bytes(body)); byte[] bytes = OAuthAuthenticationHandler.readBody(req); assertTrue(Arrays.equals(bytes, CharsetUtil.getUtf8Bytes(body))); assertEquals(req.getAttribute(AuthenticationHandler.STASHED_BODY), bytes); }
@Test public void testGetUtf8String() { ArrayAssert.assertEquals(new byte[] { 0x69, 0x6e }, CharsetUtil.getUtf8Bytes("in")); ArrayAssert.assertEquals(new byte[] {}, CharsetUtil.getUtf8Bytes(null)); testStringOfLength(0); testStringOfLength(10); testStringOfLength(100); testStringOfLength(1000); }
@Test public void testGetUtf8String() { ArrayAssert.assertEquals(new byte[] { 0x69, 0x6e }, CharsetUtil.getUtf8Bytes("in")); ArrayAssert.assertEquals(new byte[] {}, CharsetUtil.getUtf8Bytes(null)); testStringOfLength(0); testStringOfLength(10); testStringOfLength(100); testStringOfLength(1000); }