Example usage for java.io InputStream toString

List of usage examples for java.io InputStream toString

Introduction

In this page you can find the example usage for java.io InputStream toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractorTest.java

private static InputStream getInputStream(String content) {
    InputStream inputStream = Mockito.mock(InputStream.class);
    Mockito.when(inputStream.toString()).thenReturn(content);
    return inputStream;
}

From source file:Main.java

public static Document parseDom(InputStream byteArrayInputStream) {

    try {/*from   www  .  j a  v  a 2 s. c  o m*/
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new org.xml.sax.InputSource(byteArrayInputStream));
    } catch (Exception e) {
        throw new RuntimeException("Could not parse DOM for '" + byteArrayInputStream.toString() + "'!", e);
    }

}

From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractor.java

private static String getPaylod(Message message) {
    InputStream inputStream = message.getContent(InputStream.class);
    if (inputStream == null) {
        return "";
    }//from  w ww  .j  a v  a  2  s .c om
    try {
        return inputStream.toString();
    } catch (Exception exception) {
        LogUtils.error(LOGGER, exception, "Error reading payload.");
    }
    return "";
}

From source file:som.helper.GenericHelper.java

/**
 * /*from w  w w .j  av  a  2s.  com*/
 * @param path
 * @return the inputstream from Servlet Resource
 */
public static InputStream getFileFromServerUsingUrl(String path) {
    InputStream inputStream = null;
    try {
        inputStream = ServletActionContext.getServletContext().getResourceAsStream(path);
        System.out.println("The File Url :" + inputStream.toString());

    } catch (Exception e) {
        e.printStackTrace();
    }

    return inputStream;
}

From source file:info.magnolia.module.workflow.jcr.JCRWorkItemAPI.java

/**
 * load a work item from a JCR content//from w  ww  . ja v  a 2 s.  co m
 * @param ct the content node
 * @return
 * @throws Exception
 */
public static InFlowWorkItem loadWorkItem(Content ct) throws Exception {
    InFlowWorkItem wi;
    InputStream s = ct.getNodeData(WorkflowConstants.NODEDATA_VALUE).getStream();
    if (log.isDebugEnabled()) {
        log.debug("retrieve work item: value = " + s.toString());
    }
    final org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder();
    Document doc = builder.build(s);
    wi = (InFlowWorkItem) XmlCoder.decode(doc);

    Iterator itt = wi.getAttributes().alphaStringIterator();
    while (itt.hasNext()) {
        Object o = itt.next();
        String name1 = (String) o;
        if (log.isDebugEnabled()) {
            log.debug(name1 + "=" + wi.getAttribute(name1).toString());
        }
    }
    return wi;
}

From source file:org.opensubsystems.pattern.parameter.util.XMLConfig.java

/**
 * Read configuration from a specified input stream
 * //from w  ww .j a  va 2s  .c o m
 * @param streamConfig - stream from which to read configuration
 * @return ConfigurableObject 
 * @throws OSSConfigException - an error has occurred
 */
public static ConfigurationImpl read(InputStream streamConfig) throws OSSConfigException {
    Digester digester = DigesterLoader.newLoader(new ConfigurationRulesModule()).newDigester();
    ConfigurationImpl config = null;

    try {
        config = digester.parse(streamConfig);
        s_logger.log(Level.FINE, "Read configuration {0}", config);
    } catch (IOException | SAXException exc) {
        throw new OSSConfigException("Error reading input stream " + streamConfig.toString(), exc);
    }

    return config;
}

From source file:com.test.springmvc.springmvcproject.BookDetailsController.java

@RequestMapping(value = "/{bookId}/get", method = RequestMethod.GET)
public void getBook(HttpServletRequest request, HttpServletResponse response, @PathVariable Integer bookId,
        @ModelAttribute("bookModel") BookBean bean) {
    try {/* www .  j  a  v a 2s.c  om*/
        final BookBean found = searchService.findById(bookId);
        final String url_totale_to_book = request.getServletContext()
                .getRealPath(found.getEmplacement().replaceAll(request.getContextPath(), ""));
        try {
            InputStream stream = new FileInputStream(url_totale_to_book);
            System.out.println(stream.toString());
            response.setHeader("Content-Disposition", "attachment;filename=" + found.getNomLivre());
            IOUtils.copy(stream, response.getOutputStream());
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }
    } catch (NoDataFoundException e) {
    }
}

From source file:org.jboss.on.common.jbossas.JmxInvokerServiceConfiguration.java

public JmxInvokerServiceConfiguration(InputStream jmxInvokerServiceXmlInputStream) throws Exception {
    this.source = jmxInvokerServiceXmlInputStream.toString();
    DocumentBuilder builder = getDocumentBuilder();
    Document doc = builder.parse(jmxInvokerServiceXmlInputStream);
    parseDocument(doc);//from w  w  w. j a va 2s  . c  o  m
}

From source file:com.company.millenium.iwannask.RegistrationIntentService.java

/**
 * Persist registration to third-party servers.
 *
 * Modify this method to associate the user's GCM registration token with any server-side account
 * maintained by your application.//www .  j  a  v  a  2 s  . c  o m
 *
 * @param token The new token.
 */
private void sendRegistrationToServer(String token) {
    // Add custom implementation, as needed.
    try {
        // Prepare JSON containing the GCM message content. What to send and where to send.
        JSONObject jGcmData = new JSONObject();
        // What to send in GCM message.
        jGcmData.put("token", token);

        String session = getCookie(Constants.SERVER_URL, "session");

        // Create connection to send GCM Message request.
        URL url = new URL(Constants.SERVER_URL + "/register_token");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Content-Type", "application/json");
        if (session == null) {
            // we couldn't get a cookie, try later
            throw new NoCookieException();
        }
        conn.setRequestProperty("Cookie", "session=" + session);
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);

        // Send GCM message content.
        OutputStream outputStream = conn.getOutputStream();
        outputStream.write(jGcmData.toString().getBytes());

        // Read GCM response.
        InputStream inputStream = conn.getInputStream();
        String resp = inputStream.toString();
        if (resp.contentEquals("success")) {

        }
        //String resp1 = IOUtils.toString(inputStream);

    } catch (NoCookieException e) {
        System.out.println("Unable to get the session cookie");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("Unable to send GCM message.");
        System.out.println("Please ensure that API_KEY has been replaced by the server "
                + "API key, and that the device's registration token is correct (if specified).");
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.exquance.jenkins.plugins.conduit.ConduitAPIClient.java

/**
 * Call the conduit API of Phabricator//w  w  w. j  a v a2 s . co  m
 * @param action Name of the API call
 * @param params The data to send to Harbormaster
 * @return The result as a JSONObject
 * @throws IOException If there was a problem reading the response
 * @throws ConduitAPIException If there was an error calling conduit
 */
public JSONObject perform(String action, JSONObject params) throws IOException, ConduitAPIException {
    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpUriRequest request = createRequest(action, params);

    HttpResponse response;
    try {
        response = client.execute(request);
    } catch (ClientProtocolException e) {
        throw new ConduitAPIException(e.getMessage());
    }

    InputStream responseBody = response.getEntity().getContent();

    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        throw new ConduitAPIException(responseBody.toString(), response.getStatusLine().getStatusCode());
    }

    JsonSlurper jsonParser = new JsonSlurper();
    return (JSONObject) jsonParser.parse(responseBody);
}