List of usage examples for java.io OutputStream toString
public String toString()
From source file:org.eclipse.om2m.datamapping.jaxb.Mapper.java
/** * Converts a resource Java object into resource XML representation. * /*from w w w . ja v a 2 s. co m*/ * @param object * - resource Java object * @return resource XML representation */ @Override public String objToString(Object obj) { try { Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); OutputStream outputStream = new ByteArrayOutputStream(); marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, mediaType); marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); marshaller.marshal(obj, outputStream); return outputStream.toString(); } catch (JAXBException e) { LOGGER.error("JAXB marshalling error!", e); } return null; }
From source file:org.apache.hive.beeline.cli.TestHiveCli.java
/** * This method is used for verifying CMD to see whether the output contains the keywords provided. * * @param CMD// w w w .j a va 2s. c o m * @param keywords * @param os * @param options * @param retCode * @param contains */ private void verifyCMD(String CMD, String keywords, OutputStream os, String[] options, int retCode, boolean contains) { executeCMD(options, CMD, retCode); String output = os.toString(); LOG.debug(output); if (contains) { Assert.assertTrue("The expected keyword \"" + keywords + "\" occur in the output: " + output, output.contains(keywords)); } else { Assert.assertFalse("The expected keyword \"" + keywords + "\" should be excluded occurred in the output: " + output, output.contains(keywords)); } }
From source file:ape_test.CLITest.java
public void testMainWithNullArg() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps);/*from ww w .j a v a 2s .c o m*/ String[] arg = null; Main.main(arg); System.setOut(originalOut); assertNotSame("", os.toString()); }
From source file:org.duracloud.stitch.impl.FileStitcherImplTest.java
@Test public void testGetContentFromManifestUnordered() throws Exception { createMocks(VALID_CHUNKS);/*from w w w .j a va2 s .com*/ replayMocks(); stitcher = new FileStitcherImpl(dataSource); Content content = stitcher.getContentFromManifest(spaceId, contentId); Assert.assertNotNull(content); InputStream contentStream = content.getStream(); Assert.assertNotNull(contentStream); OutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(contentStream, outputStream); String fullContent = outputStream.toString(); contentStream.close(); outputStream.close(); // verify order of chunks. String chunkText; for (int i = 0; i < NUM_CHUNKS; ++i) { chunkText = getChunkContent(i); Assert.assertTrue(fullContent.startsWith(chunkText)); fullContent = fullContent.substring(chunkText.length()); } Assert.assertEquals("All chunks should be found and pruned.", 0, fullContent.length()); }
From source file:org.apache.wiki.util.CryptoUtilTest.java
public void testCommandLineNoVerify() throws Exception { // Save old printstream PrintStream oldOut = System.out; // Swallow System out and get command output OutputStream out = new ByteArrayOutputStream(); System.setOut(new PrintStream(out)); // Supply a bogus password CryptoUtil.main(new String[] { "--verify", "password", "{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=" }); String output = new String(out.toString()); // Restore old printstream System.setOut(oldOut);// ww w .jav a 2s . c o m // Run our tests assertTrue(output.startsWith("false")); }
From source file:org.ebayopensource.turmeric.eclipse.errorlibrary.properties.providers.PropertiesContentErrorLibraryCreator.java
private IFile createPropsFile(IProject project, IProgressMonitor monitor) throws IOException, CoreException { IFile file = TurmericErrorLibraryUtils.getDomainListPropsFile(project); OutputStream output = null; try {//from www .j a v a2 s . c o m output = new ByteArrayOutputStream(); final Properties properties = new Properties(); properties.setProperty(PropertiesSOAConstants.PROPS_LIST_OF_DOMAINS, ""); properties.store(output, SOAProjectConstants.PROPS_COMMENTS); WorkspaceUtil.writeToFile(output.toString(), file, monitor); } finally { IOUtils.closeQuietly(output); } return file; }
From source file:ape_test.CLITest.java
public void testMainWithEmptyArray() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps);/*from w w w. j a v a 2 s. co m*/ String[] arg = new String[0]; Main.main(arg); System.setOut(originalOut); assertNotSame("", os.toString()); }
From source file:com.linkedin.gradle.python.tasks.action.pip.PipWheelAction.java
@Override void doPipOperation(PackageInfo packageInfo, List<String> extraArgs) { throwIfPythonVersionIsNotSupported(packageInfo); if (!packageSettings.requiresSourceBuild(packageInfo) && doesWheelExist(packageInfo)) { return;//from w ww.j a v a 2s .com } if (PythonHelpers.isPlainOrVerbose(project)) { logger.lifecycle("Building {} wheel", packageInfo.toShortHand()); } Map<String, String> mergedEnv = environmentMerger .mergeEnvironments(Arrays.asList(baseEnvironment, packageSettings.getEnvironment(packageInfo))); List<String> commandLine = makeCommandLine(packageInfo, extraArgs); OutputStream stream = new ByteArrayOutputStream(); ExecResult installResult = execCommand(mergedEnv, commandLine, stream); if (installResult.getExitValue() != 0) { logger.error("Error installing package using `{}`", commandLine); logger.error(stream.toString().trim()); throw PipExecutionException.failedWheel(packageInfo, stream.toString().trim()); } else { logger.info(stream.toString().trim()); } }
From source file:org.kawanfw.sql.servlet.sql.ServerCallableStatement.java
/** * Execute the query/update for the statement and return the result (or * result set) as as string//from w ww. jav a 2s . com * * @throws SQLException * * @return the string containing the result set output, null if no result * set is produced */ public String execute() throws SQLException, IOException { OutputStream bos = new ByteArrayOutputStream(); callStatement(bos); return bos.toString(); }
From source file:net.sf.jasperreports.olap.Olap4jMondrianQueryExecuter.java
@Override public JRDataSource createDatasource() throws JRException { JRDataSource dataSource = null;//from w w w . j a v a2s . c om Properties connectProps = new Properties(); connectProps.put(OLAP4J_JDBC_DRIVERS, getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_DRIVERS)); connectProps.put(OLAP4J_JDBC_URL, getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_URL)); connectProps.put(OLAP4J_JDBC_CATALOG, getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_CATALOG)); String user = (String) getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_USER); if (user != null) { connectProps.put(OLAP4J_JDBC_USER, user); } String password = (String) getParameterValue(Olap4jMondrianQueryExecuterFactory.PARAMETER_JDBC_PASSWORD); if (password != null) { connectProps.put(OLAP4J_JDBC_PASSWORD, password); } connectProps.put(OLAP4J_DRIVER, OLAP4J_MONDRIAN_DRIVER_CLASS); connectProps.put(OLAP4J_URL_PREFIX, OLAP4J_MONDRIAN_URL_PREFIX); // load driver and Connection rConnection = null; try { Class.forName(OLAP4J_MONDRIAN_DRIVER_CLASS); rConnection = java.sql.DriverManager.getConnection(OLAP4J_MONDRIAN_URL_PREFIX, connectProps); } catch (Throwable t) { throw new JRException(EXCEPTION_MESSAGE_KEY_CONNECTION_ERROR, new Object[] { OLAP4J_MONDRIAN_DRIVER_CLASS }, t); } OlapConnection connection = (OlapConnection) rConnection; String queryStr = getQueryString(); if (connection != null && queryStr != null) { if (log.isDebugEnabled()) { log.debug("MDX query: " + queryStr); } CellSet result = null; try { OlapStatement statement = connection.createStatement(); result = statement.executeOlapQuery(getQueryString()); } catch (OlapException e) { throw new JRException(EXCEPTION_MESSAGE_KEY_EXECUTE_QUERY_ERROR, new Object[] { getQueryString() }, e); } if (log.isDebugEnabled()) { OutputStream bos = new ByteArrayOutputStream(); CellSetFormatter formatter = new RectangularCellSetFormatter(true); formatter.format(result, new PrintWriter(bos, true)); log.debug("Result:\n" + bos.toString()); } dataSource = new Olap4jDataSource(dataset, result); } return dataSource; }