List of usage examples for org.apache.commons.codec.binary StringUtils newStringUsAscii
public static String newStringUsAscii(final byte[] bytes)
String
by decoding the specified array of bytes using the US-ASCII charset. From source file:aiai.apps.gen_keys.GenerateKeys.java
public static String encodeBase64String(final byte[] binaryData) { return StringUtils.newStringUsAscii(Base64.encodeBase64(binaryData, true)); }
From source file:aiai.apps.commons.utils.SecUtils.java
public static String getSignature(String data, PrivateKey privateKey, boolean isChuncked) throws GeneralSecurityException { Signature signer = Signature.getInstance("SHA256withRSA"); signer.initSign(privateKey);//from w w w .ja va 2 s . c o m signer.update(data.getBytes(StandardCharsets.UTF_8)); return StringUtils.newStringUsAscii(Base64.encodeBase64(signer.sign(), isChuncked)); }
From source file:com.mirth.connect.server.util.DICOMMessageUtil.java
public static String getDICOMRawData(ImmutableConnectorMessage message) { String mergedMessage = null;/*ww w . j a va 2s . com*/ List<Attachment> attachments = MessageController.getInstance().getMessageAttachment(message.getChannelId(), message.getMessageId()); if (attachments != null && attachments.size() > 0) { try { if (attachments.get(0).getType().equals("DICOM")) { byte[] mergedMessageBytes = mergeHeaderAttachments(message, attachments); // Replace the raw binary with the encoded binary to free up the memory mergedMessageBytes = Base64Util.encodeBase64(mergedMessageBytes); mergedMessage = StringUtils.newStringUsAscii(mergedMessageBytes); } else { mergedMessage = message.getRaw().getContent(); } } catch (Exception e) { logger.error("Error merging DICOM data", e); mergedMessage = message.getRaw().getContent(); } } else { mergedMessage = message.getRaw().getContent(); } return mergedMessage; }
From source file:com.mirth.connect.server.attachments.dicom.DICOMAttachmentHandler.java
@Override public String shutdown() throws AttachmentException { try {//from w w w . j a v a2s . c om byte[] encodedMessage = Base64Util.encodeBase64(DICOMConverter.dicomObjectToByteArray(dicomObject)); dicomElement = null; dicomObject = null; return StringUtils.newStringUsAscii(encodedMessage); } catch (Throwable t) { throw new AttachmentException(t); } }
From source file:com.mirth.connect.plugins.datatypes.dicom.DICOMSerializer.java
@Override public String fromXML(String source) throws MessageSerializerException { if (source == null || source.length() == 0) { return org.apache.commons.lang3.StringUtils.EMPTY; }//from w ww .j a v a 2 s . c o m try { // re-parse the xml to Mirth format Document document = documentSerializer.fromXML(source); Element element = document.getDocumentElement(); Node node = element.getChildNodes().item(0); // change back to <attr> tag for all tags under <dicom> tag while (node != null) { renameTagToAttr(document, node); node = node.getNextSibling(); } NodeList items = document.getElementsByTagName("item"); // change back to <attr> tag for all tags under <item> tags if (items != null) { for (int i = 0; i < items.getLength(); i++) { Node itemNode = items.item(i); if (itemNode.getChildNodes() != null) { NodeList itemNodes = itemNode.getChildNodes(); for (int j = 0; j < itemNodes.getLength(); j++) { Node nodeItem = itemNodes.item(j); renameTagToAttr(document, nodeItem); } } } } // find the charset String charset = null; Element charsetElement = (Element) document.getElementsByTagName("tag00080005").item(0); if (charsetElement != null) { charset = charsetElement.getNodeValue(); } else { charset = "utf-8"; } // parse the Document into a DicomObject SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); DicomObject dicomObject = new BasicDicomObject(); ContentHandlerAdapter contentHandler = new ContentHandlerAdapter(dicomObject); byte[] documentBytes = documentSerializer.toXML(document).trim().getBytes(charset); parser.parse(new InputSource(new ByteArrayInputStream(documentBytes)), contentHandler); return StringUtils .newStringUsAscii(Base64Util.encodeBase64(DICOMConverter.dicomObjectToByteArray(dicomObject))); } catch (Exception e) { throw new MessageSerializerException("Error converting XML to DICOM", e, ErrorMessageBuilder .buildErrorMessage(this.getClass().getSimpleName(), "Error converting XML to DICOM", e)); } }
From source file:org.apache.abdera2.common.http.Authentication.java
public static Authentication basic(String userid, String password) { return new Authentication(BASIC, StringUtils.newStringUsAscii(Base64.encodeBase64(bytes(userid, ":", password)))); }
From source file:yoyo.framework.standard.shared.commons.codec.StringUtilsTest.java
@Test public void test() { String testee = org.apache.commons.lang3.StringUtils.EMPTY; assertThat(StringUtils.getBytesUnchecked(testee, "UTF-8"), is(ArrayUtils.EMPTY_BYTE_ARRAY)); assertThat(StringUtils.getBytesIso8859_1(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY)); assertThat(StringUtils.getBytesUsAscii(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY)); assertThat(StringUtils.getBytesUtf8(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY)); assertThat(StringUtils.getBytesUtf16(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY)); assertThat(StringUtils.getBytesUtf16Le(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY)); assertThat(StringUtils.getBytesUtf16Be(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY)); assertThat(StringUtils.newString(ArrayUtils.EMPTY_BYTE_ARRAY, "UTF-8"), is(testee)); assertThat(StringUtils.newStringIso8859_1(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee)); assertThat(StringUtils.newStringUsAscii(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee)); assertThat(StringUtils.newStringUtf8(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee)); assertThat(StringUtils.newStringUtf16(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee)); assertThat(StringUtils.newStringUtf16Le(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee)); assertThat(StringUtils.newStringUtf16Be(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee)); }