List of usage examples for org.apache.commons.io.output ByteArrayOutputStream toString
public String toString(String enc) throws UnsupportedEncodingException
From source file:eu.peppol.as2.evidence.TransmissionEvidenceTransformerAs2WithRemImplTest.java
@Test public void loadTransmissionEvidenceTransformerInstance() throws Exception { TransmissionEvidenceTransformer transformer = TransmissionEvidenceTransformerAs2WithRemImpl.INSTANCE; assertNotNull(transformer);//from ww w.j a v a 2 s . c o m TransmissionEvidence sample = sampleTransmissionEvidenceGenerator .createSampleTransmissionEvidenceWithRemAndMdn(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(transformer.getInputStream(sample), outputStream); System.out.println(outputStream.toString("UTF-8")); java.security.cert.X509Certificate x509Certificate = XmldsigVerifier .verify(DomUtils.parse(new ByteArrayInputStream(outputStream.toByteArray()))); }
From source file:com.bradmcevoy.http.webdav.PropFindXmlGeneratorHelper.java
void write(ByteArrayOutputStream out, OutputStream outputStream) { try {/* ww w . jav a 2 s. co m*/ String xml = out.toString("UTF-8"); outputStream.write(xml.getBytes()); // note: this can and should write to the outputstream directory. but if it aint broke, dont fix it... } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:io.milton.http.webdav.PropFindXmlGeneratorHelper.java
void write(ByteArrayOutputStream out, OutputStream outputStream) { try {//from w ww.j a va 2 s .c o m String xml = out.toString("UTF-8"); outputStream.write(xml.getBytes("UTF-8")); // note: this can and should write to the outputstream directory. but if it aint broke, dont fix it... } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:io.github.kahowell.xformsvc.util.TransformUtil.java
public String transform(String transformationName, String source) throws TransformerConfigurationException, TransformerException, UnsupportedEncodingException { TransformerFactory factory = TransformerFactory.newInstance(); factory.setURIResolver(getURIResolver()); Transformer transformer = factory.newTransformer(lookupTransformer(transformationName)); transformer.setOutputProperty(OutputKeys.INDENT, prettyPrint ? "yes" : "no"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); ByteArrayOutputStream out = new ByteArrayOutputStream(); transformer.transform(new StreamSource(new ByteArrayInputStream(source.getBytes("UTF-8"))), new StreamResult(out)); return out.toString("UTF-8"); }
From source file:at.ac.tuwien.big.moea.print.PopulationWriter.java
@Override public String write(final Iterable<S> population) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream ps = new PrintStream(baos); write(ps, population);// www . ja v a2 s. c o m ps.close(); try { return baos.toString("UTF-8"); } catch (final UnsupportedEncodingException e) { return e.getMessage(); } }
From source file:at.ac.tuwien.big.moea.print.PopulationWriter.java
@Override public String write(final Population population) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream ps = new PrintStream(baos); write(ps, population);//from w w w.j a v a 2 s.co m ps.close(); try { return baos.toString("UTF-8"); } catch (final UnsupportedEncodingException e) { return e.getMessage(); } }
From source file:net.sf.jooreports.templates.TemplatePreProcessor.java
private void applyXmlFilters(InputStream input, OutputStream output) throws DocumentTemplateException, IOException { Builder builder = new Builder(); Document document = null;/* www . ja v a2 s . co m*/ try { document = builder.build(input); } catch (ParsingException parsingException) { throw new DocumentTemplateException(parsingException); } for (int i = 0; i < xmlEntryFilters.length; i++) { xmlEntryFilters[i].applyConfigurations(configurations); xmlEntryFilters[i].doFilter(document); } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Serializer serializer = new Serializer(byteArrayOutputStream, UTF_8); serializer.write(document); output.write(contentWrapper.wrapContent(byteArrayOutputStream.toString(UTF_8)).getBytes(UTF_8)); }
From source file:net.sf.jooreports.openoffice.converter.OpenOfficeDocumentConverterTest.java
public void testConversionWithEmulatedStreams() throws IOException { DocumentFormatRegistry registry = new XmlDocumentFormatRegistry(); InputStream inputStream = new FileInputStream(getTestFile("hello.odt")); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); getDocumentConverter().convert(inputStream, registry.getFormatByFileExtension("odt"), outputStream, registry.getFormatByFileExtension("txt")); inputStream.close();/* w w w. ja v a 2 s.com*/ assertEquals("output content", "Hello from an OpenDocument Text!", stripByteOrderMarkChar(outputStream.toString("UTF-8"))); }
From source file:com.moz.fiji.mapreduce.framework.JobHistoryFijiTable.java
/** * Writes details of a job into the JobHistoryFijiTable. * * @param jobId unique identifier for the job. * @param jobName name of the job.//w w w.ja v a2 s . c o m * @param startTime time in milliseconds since the epoch at which the job started. * @param endTime time in milliseconds since the epoch at which the job ended. * @param jobSuccess whether the job completed successfully. * @param counters map of counters from the job. Keys should be of the form 'group:name'. * @param conf Configuration of the job. * @param extendedInfo any additional information which should be stored about the job. * @throws IOException in case of an error writing to the table. */ // CSOFF: ParameterNumberCheck public void recordJob(final String jobId, final String jobName, final long startTime, final long endTime, final boolean jobSuccess, final Configuration conf, final Map<String, Long> counters, final Map<String, String> extendedInfo) throws IOException { // CSON: ParameterNumberCheck final EntityId eid = mFijiTable.getEntityId(jobId); final AtomicFijiPutter putter = mFijiTable.getWriterFactory().openAtomicPutter(); try { putter.begin(eid); putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_ID_QUALIFIER, startTime, jobId); putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_NAME_QUALIFIER, startTime, jobName); putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_START_TIME_QUALIFIER, startTime, startTime); putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_END_TIME_QUALIFIER, startTime, endTime); putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_END_STATUS_QUALIFIER, startTime, (jobSuccess) ? SUCCEEDED : FAILED); putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_COUNTERS_QUALIFIER, startTime, counters.toString()); if (null != conf) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); conf.writeXml(baos); putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_CONFIGURATION_QUALIFIER, startTime, baos.toString("UTF-8")); } else { putter.put(JOB_HISTORY_FAMILY, JOB_HISTORY_CONFIGURATION_QUALIFIER, startTime, JOB_HISTORY_NO_CONFIGURATION_VALUE); } writeCounters(putter, startTime, counters); writeExtendedInfo(putter, startTime, extendedInfo); putter.commit(); } finally { putter.close(); } }
From source file:at.ac.tuwien.big.moea.print.SolutionWriter.java
@Override public String write(final S solution) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintStream ps = new PrintStream(baos); write(ps, solution);/*from w w w . j a v a2 s . c om*/ ps.close(); try { return baos.toString("UTF-8"); } catch (final UnsupportedEncodingException e) { return e.getMessage(); } }