List of usage examples for java.io ByteArrayOutputStream toString
public synchronized String toString()
From source file:ch.windmobile.server.socialmodel.mogodb.FavoritesTest.java
void beforeTest() { Mongo mongo = null;// w ww .j a va2 s.c o m try { mongo = new Mongo(); DB db = mongo.getDB(MongoDBConstants.DATABASE_NAME); InputStream is = getClass().getResourceAsStream("/init-script.js"); ByteArrayOutputStream out = new ByteArrayOutputStream(); FileCopyUtils.copy(is, out); String code = out.toString(); Object result = db.doEval(code); log.info("Create test database: " + result.toString()); } catch (Exception e) { log.error("Error : " + e.getMessage(), e); } finally { if (mongo != null) { mongo.close(); } } }
From source file:de.weltraumschaf.groundzero.opt.commons.CommonsImplementation.java
@Override public String help() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); CONFIGURATION.format(HELP_FORMATTER, new PrintStream(out)); return out.toString(); }
From source file:demo.wseventing.CreateSubscriptionServlet.java
public String convertJAXBElementToStringAndEscapeHTML(Object o) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(Subscribe.class.getPackage().getName()); Marshaller m = jc.createMarshaller(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.marshal(o, baos);//www.j a v a2 s . co m String unescaped = baos.toString(); return StringEscapeUtils.escapeHtml4(unescaped); }
From source file:com.marklogic.mapreduce.DOMDocument.java
public String toString() { if (rootNodeKind == NodeKind.TEXT) { TextImpl textNode = (TextImpl) doc.getFirstChild(); if (textNode != null) { return textNode.getTextContent(); }//from w ww . ja va 2s . c o m } try { ByteArrayOutputStream bos = serialize(doc); return bos.toString(); } catch (TransformerException ex) { LOG.error("Error serializing document", ex); } return null; }
From source file:com.norconex.importer.handler.transformer.impl.ReplaceTransformerTest.java
@Test public void testTransformTextDocument() throws IOException, ImporterHandlerException { String text = "I like to eat cakes and candies."; ReplaceTransformer t = new ReplaceTransformer(); Reader reader = new InputStreamReader(IOUtils.toInputStream(xml)); t.loadFromXML(reader);//from ww w .j av a2s .c om reader.close(); InputStream is = IOUtils.toInputStream(text); ByteArrayOutputStream os = new ByteArrayOutputStream(); t.transformDocument("dummyRef", is, os, new ImporterMetadata(), true); String response = os.toString(); System.out.println(response); Assert.assertEquals("i like to eat fruits and vegetables.", response.toLowerCase()); is.close(); os.close(); }
From source file:com.consol.citrus.admin.service.TestExecutionService.java
/** * Adds failure stack information to test result. * @param result//from w w w.j a va 2s . c om * @param e */ private void setFailureStack(TestResult result, Exception e) { result.setSuccess(false); ByteArrayOutputStream os = new ByteArrayOutputStream(); e.printStackTrace(new PrintStream(os)); result.setStackTrace("Caused by: " + os.toString()); if (e instanceof CitrusRuntimeException) { result.setFailureStack(((CitrusRuntimeException) e).getFailureStackAsString()); } }
From source file:org.kordamp.javatrove.example04.util.ApplicationEventHandler.java
@Handler public void handleThrowable(ThrowableEvent event) { Platform.runLater(() -> {/*from www . j a v a 2s. c om*/ TitledPane pane = new TitledPane(); pane.setCollapsible(false); pane.setText("Stacktrace"); TextArea textArea = new TextArea(); textArea.setEditable(false); pane.setContent(textArea); ByteArrayOutputStream baos = new ByteArrayOutputStream(); event.getThrowable().printStackTrace(new PrintStream(baos)); textArea.setText(baos.toString()); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("An unexpected error occurred"); alert.getDialogPane().setContent(pane); alert.showAndWait(); }); }
From source file:com.ngdata.hbaseindexer.conf.XmlIndexerConfWriterTest.java
@Test public void testWrite() throws Exception { Map<String, String> params = Maps.newHashMap(); params.put("thename", "thevalue"); IndexerConf conf = new IndexerConfBuilder().table("the-table").mappingType(IndexerConf.MappingType.COLUMN) .rowReadMode(IndexerConf.RowReadMode.DYNAMIC).uniqueyKeyField("keyfield").rowField("rf") .columnFamilyField("cf-field").tableNameField("tn-field").globalParams(params) .mapperClass(DefaultResultToSolrMapper.class) .uniqueKeyFormatterClass(StringUniqueKeyFormatter.class) .addFieldDefinition("fieldname", "fieldvalue", FieldDefinition.ValueSource.VALUE, "fieldtype", params)/*from w ww . ja v a 2 s . c o m*/ .addDocumentExtractDefinition("theprefix", "valueexpr", FieldDefinition.ValueSource.VALUE, "deftype", params) .build(); ByteArrayOutputStream os = new ByteArrayOutputStream(); XmlIndexerConfWriter.writeConf(conf, os); String xmlString = os.toString(); IndexerConf conf2 = null; try { IndexerComponentFactory factory = IndexerComponentFactoryUtil.getComponentFactory( DefaultIndexerComponentFactory.class.getName(), IOUtils.toInputStream(xmlString), Maps.<String, String>newHashMap()); conf2 = factory.createIndexerConf(); } catch (Exception e) { e.printStackTrace(); Assert.fail("Xml is not valid"); } Assert.assertEquals(conf.getTable(), conf2.getTable()); Assert.assertEquals(conf.getMappingType(), conf2.getMappingType()); Assert.assertEquals(conf.getRowReadMode(), conf2.getRowReadMode()); Assert.assertEquals(conf.getUniqueKeyField(), conf2.getUniqueKeyField()); Assert.assertEquals(conf.getRowField(), conf2.getRowField()); Assert.assertEquals(conf.getColumnFamilyField(), conf2.getColumnFamilyField()); Assert.assertEquals(conf.getTableNameField(), conf2.getTableNameField()); Assert.assertEquals(conf.getGlobalParams(), conf2.getGlobalParams()); Assert.assertEquals(conf.getMapperClass(), conf2.getMapperClass()); Assert.assertEquals(conf.getUniqueKeyFormatterClass(), conf2.getUniqueKeyFormatterClass()); Assert.assertEquals(conf.getFieldDefinitions().size(), conf2.getFieldDefinitions().size()); Assert.assertEquals(conf.getDocumentExtractDefinitions().size(), conf2.getDocumentExtractDefinitions().size()); }
From source file:net.bpelunit.framework.control.deploy.ode.ODERequestEntityFactory.java
private void prepareDeploySOAP(File file) throws IOException, SOAPException { MessageFactory mFactory = MessageFactory.newInstance(); SOAPMessage message = mFactory.createMessage(); SOAPBody body = message.getSOAPBody(); SOAPElement xmlDeploy = body.addChildElement(ODE_ELEMENT_DEPLOY); SOAPElement xmlZipFilename = xmlDeploy.addChildElement(ODE_ELEMENT_ZIPNAME); xmlZipFilename.setTextContent(FilenameUtils.getName(file.toString()).split("\\.")[0]); SOAPElement xmlZipContent = xmlDeploy.addChildElement(ODE_ELEMENT_PACKAGE); SOAPElement xmlBase64ZipFile = xmlZipContent.addChildElement(ODE_ELEMENT_ZIP, "dep", NS_DEPLOY_SERVICE); xmlBase64ZipFile.addAttribute(new QName(NS_XML_MIME, CONTENT_TYPE_STRING), ZIP_CONTENT_TYPE); StringBuilder content = new StringBuilder(); byte[] arr = FileUtils.readFileToByteArray(file); byte[] encoded = Base64.encodeBase64Chunked(arr); for (int i = 0; i < encoded.length; i++) { content.append((char) encoded[i]); }// w w w . j a v a 2 s . co m xmlBase64ZipFile.setTextContent(content.toString()); ByteArrayOutputStream b = new ByteArrayOutputStream(); message.writeTo(b); fContent = b.toString(); }
From source file:ch.windmobile.server.socialmodel.mogodb.ITTestAuthenticationServiceImpl.java
@Before public void beforeTest() { Mongo mongo = null;/*from w ww . java 2 s . c o m*/ try { mongo = new Mongo(); DB db = mongo.getDB(MongoDBConstants.DATABASE_NAME); InputStream is = getClass().getResourceAsStream("/init-script.js"); ByteArrayOutputStream out = new ByteArrayOutputStream(); FileCopyUtils.copy(is, out); String code = out.toString(); Logger.getLogger("WindoMobile").info("Create test database"); Object result = db.doEval(code); Logger.getLogger("WindoMobile").info("Result : " + result.toString()); } catch (Exception e) { Logger.getLogger("WindoMobile").log(Level.SEVERE, "Error : " + e.getMessage()); e.printStackTrace(); } finally { if (mongo != null) { mongo.close(); } } }