List of usage examples for org.apache.commons.codec.binary StringUtils getBytesUtf8
public static byte[] getBytesUtf8(final String string)
From source file:de.alpharogroup.crypto.aes.HexDumpTest.java
/** * Test method for {@link de.alpharogroup.crypto.aes.HexDump#decodeHexToString(char[])} * * @throws DecoderException// ww w .j a v a 2 s. c o m * the decoder exception */ @Test public void testDecodeHexToString() throws DecoderException { final String expected = "Secret message"; final char[] actualCharArray = HexDump.encodeHex(StringUtils.getBytesUtf8(expected)); final String actual = HexDump.decodeHexToString(actualCharArray); assertEquals(expected, actual); }
From source file:de.alpharogroup.crypto.hex.HexExtensionsTest.java
/** * Test method for {@link HexExtensions#decodeHex(byte[])} * * @throws DecoderException/*from w w w . j a v a 2 s. c o m*/ * is thrown if an odd number or illegal of characters is supplied */ @Test public void testDecodeHexCharacterArray() throws DecoderException { final String expected = "Secret message"; final char[] actualCharArray = HexExtensions.encodeHex(StringUtils.getBytesUtf8(expected)); final byte[] decoded = HexExtensions.decodeHex(actualCharArray); final String actual = HexExtensions.decodeHex(decoded); assertEquals(expected, actual); }
From source file:com.squarespace.gibson.GibsonUtils.java
private static void append(MessageDigest md, String value) { append(md, StringUtils.getBytesUtf8(value)); }
From source file:com.smartitengineering.cms.spi.impl.workspace.search.SequenceHelper.java
@Override protected Sequence convertFromT2F(MultivalueMap<String, Object> toBean) { try {/*w w w . j av a2 s . c o m*/ byte[] contentId = StringUtils.getBytesUtf8(toBean.getFirst(SolrFieldNames.ID).toString()); SequenceId id = contentTypeLoader.getFromByteArray(contentId); return id.getSequence(); } catch (Exception ex) { logger.error("Error converting to content type, returning null!", ex); } return null; }
From source file:com.smartitengineering.cms.spi.impl.AbstractVariationProvider.java
protected MutableVariation getVariation(Content content, Field field, String variationName) { if (logger.isDebugEnabled()) { logger.debug("Parameters: " + content + " " + field + " " + variationName); }//from w ww. ja va 2 s . c o m if (field == null) { return null; } final FieldDef fieldDef = field.getFieldDef(); if (fieldDef == null) { return null; } final VariationDef varDef = fieldDef.getVariations().get(variationName); if (varDef == null) { return null; } VariationGenerator generator; generator = SmartContentAPI.getInstance().getWorkspaceApi() .getVariationGenerator(content.getContentId().getWorkspaceId(), varDef.getResourceUri().getValue()); if (generator == null) { if (logger.isInfoEnabled()) { logger.info("Generator not available!"); } return null; } final Object variationForField = generator.getVariationForField(field, varDef.getParameters()); final byte[] bytes; if (variationForField instanceof String) { bytes = StringUtils.getBytesUtf8((String) variationForField); } else if (variationForField instanceof byte[]) { bytes = (byte[]) variationForField; } else if (variationForField instanceof InputStream) { try { bytes = IOUtils.toByteArray((InputStream) variationForField); } catch (Exception ex) { throw new RuntimeException(ex); } } else if (variationForField instanceof Reader) { try { bytes = IOUtils.toByteArray((Reader) variationForField); } catch (Exception ex) { throw new RuntimeException(ex); } } else { bytes = StringUtils.getBytesUtf8(variationForField.toString()); } MutableVariation variation = SmartContentAPI.getInstance().getContentLoader() .createMutableVariation(content.getContentId(), fieldDef); variation.setName(variationName); variation.setMimeType(varDef.getMIMEType()); variation.setVariation(bytes); return variation; }
From source file:de.alpharogroup.crypto.aes.HexDumpTest.java
/** * Test method for {@link de.alpharogroup.crypto.aes.HexDump#encodeHex(byte[])} *///from w w w . j ava2s . co m @Test public void testEncodeHex() { final String secretMessage = "Secret message"; final String expected = "536563726574206d657373616765"; final char[] actualCharArray = HexDump.encodeHex(StringUtils.getBytesUtf8(secretMessage)); final String actual = new String(actualCharArray); assertEquals(expected, actual); }
From source file:microsoft.exchange.webservices.data.misc.IFunctionsTest.java
@Test public void testBase64Encoder() { final byte[] value = StringUtils.getBytesUtf8("123"); final IFunctions.Base64Encoder f = IFunctions.Base64Encoder.INSTANCE; Assert.assertEquals(Base64.encodeBase64String(value), f.func(value)); }
From source file:de.alpharogroup.crypto.hex.HexExtensionsTest.java
/** * Test method for {@link HexExtensions#decodeHexToString(char[])} * * @throws DecoderException//from w w w. j a v a 2 s . com * is thrown if an odd number or illegal of characters is supplied */ @Test public void testDecodeHexToString() throws DecoderException { final String expected = "Secret message"; final char[] actualCharArray = HexExtensions.encodeHex(StringUtils.getBytesUtf8(expected)); final String actual = HexExtensions.decodeHexToString(actualCharArray); assertEquals(expected, actual); }
From source file:de.alpharogroup.crypto.aes.HexDumpTest.java
/** * Test method for {@link de.alpharogroup.crypto.aes.HexDump#encodeHex(byte[], boolean)} *//*w w w. ja v a 2 s. c o m*/ @Test public void testEncodeHexBoolean() { final String secretMessage = "Secret message"; final String expected = "536563726574206d657373616765"; char[] actualCharArray = HexDump.encodeHex(StringUtils.getBytesUtf8(secretMessage), true); String actual = new String(actualCharArray); assertEquals(expected, actual); actualCharArray = HexDump.encodeHex(StringUtils.getBytesUtf8(secretMessage), false); actual = new String(actualCharArray); assertEquals(expected.toUpperCase(), actual); }
From source file:com.smartitengineering.cms.ws.resources.content.ContentsResource.java
@Path(ContentsResource.PATH_TO_CONTENT) public ContentResource getContentResource(@PathParam(PARAM_CONTENT) String contentId) throws UnsupportedEncodingException { final ContentLoader contentLoader = SmartContentAPI.getInstance().getContentLoader(); return new ContentResource(getInjectables(), contentLoader.createContentId(workspace.getId(), StringUtils.getBytesUtf8(contentId))); }