List of usage examples for java.io OutputStream toString
public String toString()
From source file:hudson.plugins.script_realm_extended.ExtendedScriptSecurityRealm.java
protected GrantedAuthority[] loadGroups(String username) throws AuthenticationException { try {/*w w w . j a v a 2s.c om*/ List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(AUTHENTICATED_AUTHORITY); if (!StringUtils.isBlank(groupsCommandLine)) { StringWriter out = new StringWriter(); LocalLauncher launcher = new LocalLauncher(new StreamTaskListener(out)); OutputStream scriptOut = new ByteArrayOutputStream(); if (launcher.launch().cmds(QuotedStringTokenizer.tokenize(groupsCommandLine)).stdout(scriptOut) .envs("U=" + username).join() == 0) { StringTokenizer tokenizer = new StringTokenizer(scriptOut.toString().trim(), groupsDelimiter); while (tokenizer.hasMoreTokens()) { final String token = tokenizer.nextToken().trim(); String[] args = new String[] { token, username }; LOGGER.log(Level.FINE, "granting: {0} to {1}", args); authorities.add(new GrantedAuthorityImpl(token)); } } else { throw new BadCredentialsException(out.toString()); } } return authorities.toArray(new GrantedAuthority[0]); } catch (InterruptedException e) { throw new AuthenticationServiceException("Interrupted", e); } catch (IOException e) { throw new AuthenticationServiceException("Failed", e); } }
From source file:org.zanata.adapter.JsonAdapterTest.java
@Test public void testTranslatedJSONDocument() throws Exception { Resource resource = parseTestFile("test-json-untranslated.json"); assertThat(resource.getTextFlows().get(1).getContents()).containsExactly("First Source"); assertThat(resource.getTextFlows().get(2).getContents()).containsExactly("Second Source"); String firstSourceId = resource.getTextFlows().get(1).getId(); String secondSourceId = resource.getTextFlows().get(2).getId(); Map<String, TextFlowTarget> translations = new HashMap<>(); TextFlowTarget firstTranslation = new TextFlowTarget(); firstTranslation.setContents("Found metalkcta"); firstTranslation.setState(ContentState.Approved); translations.put(firstSourceId, firstTranslation); TextFlowTarget secondTranslation = new TextFlowTarget(); secondTranslation.setContents("Tbad metalkcta"); secondTranslation.setState(ContentState.Translated); translations.put(secondSourceId, secondTranslation); File originalFile = getTestFile("test-json-untranslated.json"); OutputStream outputStream = new ByteArrayOutputStream(); try (IFilterWriter writer = createWriter(outputStream)) { adapter.generateTranslatedFile(originalFile.toURI(), translations, this.localeId, writer, Optional.absent()); }//from w w w . ja v a 2s . co m assertThat(outputStream.toString()) .isEqualTo("{\n" + " \"test\": {\n" + " \"title\": \"Test\",\n" + " \"test1\": {\n" + " \"title\": \"Found metalkcta\"\n" + " },\n" + " \"test2\": {\n" + " \"title\": \"Tbad metalkcta\"\n" + " }\n" + " }\n" + "}\n"); }
From source file:ape_test.CLITest.java
public void testMainWithEmptyString() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps);// w w w.j av a 2s.co m String[] arg = new String[1]; arg[0] = ""; Main.main(arg); System.setOut(originalOut); assertNotSame("", os.toString()); }
From source file:ape_test.CLITest.java
public void testMissingArgument() { PrintStream originalOut = System.out; OutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps);//from ww w. java 2 s . c o m String[] arg = new String[1]; arg[0] = "R"; Main.main(arg); System.setOut(originalOut); assertNotSame("", os.toString()); }
From source file:org.ebayopensource.turmeric.eclipse.buildsystem.utils.ProjectPropertiesFileUtil.java
/** * Creates the implementation project properties file. The name of the file * is "service_impl_project.properties". This file has information about the * base consumer source directory if there is one. * * @param soaImplProject the soa impl project * @return the i file/*from ww w . j a v a 2 s. c o m*/ * @throws IOException Signals that an I/O exception has occurred. * @throws CoreException the core exception */ public static IFile createPropsFile(SOAImplProject soaImplProject) throws IOException, CoreException { IFile file = soaImplProject.getEclipseMetadata().getProject() .getFile(SOAProjectConstants.PROPS_FILE_SERVICE_IMPL); OutputStream output = null; try { output = new ByteArrayOutputStream(); Properties properties = new Properties(); SOAImplMetadata metadata = soaImplProject.getMetadata(); properties.setProperty(SOAProjectConstants.PROPS_KEY_SIMP_VERSION, SOAProjectConstants.PROPS_DEFAULT_SIMP_VERSION); boolean useServiceFactory = ServiceImplType.SERVICE_IMPL_FACTORY.equals(metadata.getServiceImplType()); properties.setProperty(SOAProjectConstants.PROPS_KEY_USE_EXTERNAL_SERVICE_FACTORY, useServiceFactory ? Boolean.TRUE.toString() : Boolean.FALSE.toString()); if (useServiceFactory == true) { String implClassName = soaImplProject.getMetadata().getServiceImplClassName(); properties.setProperty(SOAProjectConstants.PROPS_KEY_SERVICE_FACTORY_CLASS_NAME, implClassName + SOAProjectConstants.PROPS_DEFAULT_VALUE_SERVICE_FACTORY_CLASS_NAME_POSTFIX); } properties.store(output, SOAProjectConstants.PROPS_COMMENTS); WorkspaceUtil.writeToFile(output.toString(), file, null); } finally { IOUtils.closeQuietly(output); } return file; }
From source file:com.maverick.util.IOStreamConnector.java
/** * * * @param in/*w w w .ja v a 2 s . com*/ * @param out */ public void connect(InputStream in, OutputStream out) { this.in = in; this.out = out; thread = new Thread(new IOStreamConnectorThread()); thread.setDaemon(true); thread.setName("IOStreamConnector " + in.toString() + ">>" + out.toString()); thread.start(); }
From source file:hudson.plugins.script_realm.ScriptSecurityRealm.java
protected GrantedAuthority[] loadGroups(String username) throws AuthenticationException { try {/*from ww w . j av a2s . c om*/ List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(AUTHENTICATED_AUTHORITY); if (!StringUtils.isBlank(groupsCommandLine)) { StringWriter out = new StringWriter(); LocalLauncher launcher = new LoginScriptLauncher(new StreamTaskListener(out)); Map<String, String> overrides = new HashMap<String, String>(); overrides.put("U", username); if (isWindows()) { overrides.put("SystemRoot", System.getenv("SystemRoot")); } OutputStream scriptOut = new ByteArrayOutputStream(); if (launcher.launch().cmds(QuotedStringTokenizer.tokenize(groupsCommandLine)).stdout(scriptOut) .envs(overrides).join() == 0) { StringTokenizer tokenizer = new StringTokenizer(scriptOut.toString().trim(), groupsDelimiter); while (tokenizer.hasMoreTokens()) { final String token = tokenizer.nextToken().trim(); String[] args = new String[] { token, username }; LOGGER.log(Level.FINE, "granting: {0} to {1}", args); authorities.add(new GrantedAuthorityImpl(token)); } } else { throw new BadCredentialsException(out.toString()); } } return authorities.toArray(new GrantedAuthority[0]); } catch (InterruptedException e) { throw new AuthenticationServiceException("Interrupted", e); } catch (IOException e) { throw new AuthenticationServiceException("Failed", e); } }
From source file:FileErrorManager.java
/** * Null safe close method./*from ww w.j a v a 2 s . c o m*/ * * @param out closes the given stream. */ private void close(OutputStream out) { if (out != null) { try { out.close(); } catch (IOException IOE) { super.error(out.toString(), IOE, ErrorManager.CLOSE_FAILURE); } } }
From source file:org.wso2.carbon.identity.sso.saml.servlet.SAMLArtifactResolveServlet.java
/** * All requests are handled by this handleRequest method. Request should come with a soap envelop that * wraps an ArtifactResolve object. First we try to extract resolve object and if successful, call * handle artifact method.// w w w . j a v a 2 s .c o m * * @param req HttpServletRequest object received. * @param resp HttpServletResponse object to be sent. * @throws ServletException * @throws IOException */ private void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { ArtifactResolve artifactResolve = null; try { MessageFactory messageFactory = MessageFactory.newInstance(); InputStream inStream = req.getInputStream(); SOAPMessage soapMessage = messageFactory.createMessage(new MimeHeaders(), inStream); if (log.isDebugEnabled()) { OutputStream outputStream = new ByteArrayOutputStream(); soapMessage.writeTo(outputStream); log.debug("SAML2 Artifact Resolve request received: " + outputStream.toString()); } SOAPBody soapBody = soapMessage.getSOAPBody(); Iterator iterator = soapBody.getChildElements(); while (iterator.hasNext()) { SOAPBodyElement artifactResolveElement = (SOAPBodyElement) iterator.next(); if (StringUtils.equals(SAMLConstants.SAML20P_NS, artifactResolveElement.getNamespaceURI()) && StringUtils.equals(ArtifactResolve.DEFAULT_ELEMENT_LOCAL_NAME, artifactResolveElement.getLocalName())) { DOMSource source = new DOMSource(artifactResolveElement); StringWriter stringResult = new StringWriter(); TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(stringResult)); artifactResolve = (ArtifactResolve) SAMLSSOUtil.unmarshall(stringResult.toString()); } } } catch (SOAPException e) { throw new ServletException("Error while extracting SOAP body from the request.", e); } catch (TransformerException e) { throw new ServletException("Error while extracting ArtifactResponse from the request.", e); } catch (IdentityException e) { throw new ServletException("Error while unmarshalling ArtifactResponse from the request.", e); } if (artifactResolve != null) { handleArtifact(req, resp, artifactResolve); } else { log.error("Invalid SAML Artifact Resolve request received."); } } finally { SAMLSSOUtil.removeSaaSApplicationThreaLocal(); SAMLSSOUtil.removeUserTenantDomainThreaLocal(); SAMLSSOUtil.removeTenantDomainFromThreadLocal(); } }
From source file:podd.triples.SesameOracleUnitTest.java
@Test public void testJSONResult() throws RepositoryException, TripleStoreQueryException, IOException, JSONException { final String context = "http://www.example.org#"; final String queryString = "SELECT * WHERE { ?s ?p ?o }"; addTriplesToRepo(3, context);/* w w w .ja v a 2 s . c om*/ OutputStream out = new ByteArrayOutputStream(512); try { TupleQueryResultWriter writer = new SPARQLResultsJSONWriter(out); oracle.queryContextualGraph(queryString, singleton(context), writer); JSONObject obj = new JSONObject(out.toString()); final Object header = obj.get("head"); assertTrue(header instanceof JSONObject); assertEquals(1, ((JSONObject) header).length()); final Object vars = ((JSONObject) header).get("vars"); assertTrue(vars instanceof JSONArray); assertEquals(3, ((JSONArray) vars).length()); final Object bindings = ((JSONObject) obj.get("results")).get("bindings"); assertTrue(bindings instanceof JSONArray); assertEquals(3, ((JSONArray) bindings).length()); } finally { out.close(); } }