Example usage for java.io ByteArrayOutputStream toString

List of usage examples for java.io ByteArrayOutputStream toString

Introduction

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

Prototype

@Deprecated
public synchronized String toString(int hibyte) 

Source Link

Document

Creates a newly allocated string.

Usage

From source file:com.mycontacts.resource.ContactManager.java

public List<VCard> parseMultiple(InputStream inputStream) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    IOUtils.copy(inputStream, bout);//  ww  w. jav a 2s. c  om
    String vcardText = bout.toString("UTF-8");
    VCardEngine cardEngine = new VCardEngine();
    List<VCard> vcards = cardEngine.parseMultiple(vcardText);
    return vcards;
}

From source file:com.kylinolap.common.util.OSCommandExecutor.java

private void runNativeCommand() throws IOException {
    String[] cmd = new String[3];
    String osName = System.getProperty("os.name");
    if (osName.startsWith("Windows")) {
        cmd[0] = "cmd.exe";
        cmd[1] = "/C";
    } else {/*from www . j  a va 2  s. com*/
        cmd[0] = "/bin/bash";
        cmd[1] = "-c";
    }
    cmd[2] = command;

    ProcessBuilder builder = new ProcessBuilder(cmd);
    builder.redirectErrorStream(true);
    Process proc = builder.start();

    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    IOUtils.copy(proc.getInputStream(), buf);
    output = buf.toString("UTF-8");

    try {
        exitCode = proc.waitFor();
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}

From source file:eu.smeny.jpapercut.smtp.Processor.java

private CommandLine decodeCommandLine(ByteArrayOutputStream data) {
    CommandLine commandLine = new CommandLine();
    try {/* w  w w .  j a v  a 2s. c o m*/
        String lineReceived = data.toString(DEFAULT_ENCODING);
        int commandEnd = lineReceived.indexOf(SPACE);
        if (commandEnd > 0) {
            String command = lineReceived.substring(0, commandEnd).toUpperCase();
            String parameter = lineReceived.substring(commandEnd);
            commandLine.setCommand(command);
            commandLine.setParameter(parameter);
        }
    } catch (UnsupportedEncodingException uee) {
        logger.error("Error while encoding data into command", uee);
    }
    return commandLine;
}

From source file:com.arcbees.vcs.AbstractVcsApi.java

protected <T> T readEntity(Class<T> clazz, HttpEntity entity, Gson gson) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    entity.writeTo(outputStream);// w  ww  .  jav a2 s  . co  m
    String json = outputStream.toString(CharEncoding.UTF_8);

    return gson.fromJson(json, clazz);
}

From source file:org.openmrs.module.htmlwidgets.web.handler.PropertiesHandler.java

/** 
 * @see WidgetHandler#render(WidgetConfig)
 *//*w w w.  ja  va  2  s  .  co m*/
@Override
public void render(WidgetConfig config, Writer w) throws IOException {
    TextAreaWidget widget = WidgetFactory.getInstance(TextAreaWidget.class, config);
    Properties p = (Properties) config.getDefaultValue();
    if (p != null && !p.isEmpty()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OpenmrsUtil.storeProperties(p, baos, null);
        try {
            config.setDefaultValue(baos.toString("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Unable to load properties from string", e);
        }
    } else {
        config.setDefaultValue(null);
    }
    widget.render(config, w);
}

From source file:eu.europeana.corelib.edm.utils.EdmUtils.java

/**
 * Convert a FullBean to an EDM String/*from   ww w.  j a v a2 s .  c  o m*/
 *
 * @param fullBean The FullBean to convert
 * @return The resulting EDM string in RDF-XML
 */
public static synchronized String toEDM(FullBeanImpl fullBean, boolean isUim) {

    RDF rdf = new RDF();
    String type = getType(fullBean);
    appendCHO(rdf, fullBean.getProvidedCHOs());
    appendAggregation(rdf, fullBean.getAggregations());
    appendProxy(rdf, fullBean.getProxies(), type);
    appendEuropeanaAggregation(rdf, fullBean);
    appendAgents(rdf, fullBean.getAgents());
    appendConcepts(rdf, fullBean.getConcepts());
    appendPlaces(rdf, fullBean.getPlaces());
    appendTimespans(rdf, fullBean.getTimespans());
    appendLicenses(rdf, fullBean.getLicenses());
    appendServices(rdf, fullBean.getServices());
    IMarshallingContext marshallingContext;
    try {
        if (bfact == null) {
            bfact = BindingDirectory.getFactory(RDF.class);
        }
        marshallingContext = bfact.createMarshallingContext();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        marshallingContext.setOutput(out, null);
        marshallingContext.marshalDocument(rdf, "UTF-8", true);
        return out.toString("UTF-8");
    } catch (JiBXException | UnsupportedEncodingException e) {
        log.severe(e.getClass().getSimpleName() + "  " + e.getMessage());
    }
    return null;
}

From source file:org.sikuli.script.App.java

/**
 * issue a http(s) request/*from   w ww  .  j  av  a  2 s.  c  om*/
 * @param url a valid url as used in a browser
 * @return textual content of the response or empty (UTF-8)
 * @throws IOException
 */
public static String wwwGet(String url) throws IOException {
    HttpGet httpget = new HttpGet(url);
    CloseableHttpResponse response = null;
    ResponseHandler rh = new ResponseHandler() {
        @Override
        public String handleResponse(final HttpResponse response) throws IOException {
            StatusLine statusLine = response.getStatusLine();
            HttpEntity entity = response.getEntity();
            if (statusLine.getStatusCode() >= 300) {
                throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
            }
            if (entity == null) {
                throw new ClientProtocolException("Response has no content");
            }
            InputStream is = entity.getContent();
            ByteArrayOutputStream result = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int length;
            while ((length = is.read(buffer)) != -1) {
                result.write(buffer, 0, length);
            }
            return result.toString("UTF-8");
        }
    };
    boolean oneTime = false;
    if (httpclient == null) {
        wwwStart();
        oneTime = true;
    }
    Object content = httpclient.execute(httpget, rh);
    if (oneTime) {
        wwwStop();
    }
    return (String) content;
}

From source file:com.wantez.eregparser.Parser.java

public String parse(final String document) throws TransformerException, UnsupportedEncodingException {
    Source streamSource = new StreamSource(IOUtils.toInputStream(document));
    String result;/* ww  w .  j  a  va 2s  .c om*/
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Result streamResult = new StreamResult(baos);
    this.transformer.transform(streamSource, streamResult);
    result = baos.toString("ISO-8859-1");
    return result;
}

From source file:guru.nidi.atlassian.remote.meta.client.JiraExportClient.java

private void throwClientException(String message, HttpResponse response) throws IOException {
    message += ": " + response.getStatusLine().toString();
    final Header encoding = response.getEntity().getContentEncoding();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    copy(response.getEntity().getContent(), out);
    String body = out.toString(encoding == null ? "utf-8" : encoding.getValue());
    try {//  w w  w.j a  va 2s .  co  m
        throw new JiraExportClientException(message, mapper.readValue(body, ResponseMessage.class));
    } catch (JsonProcessingException e) {
        throw new JiraExportClientException(message + body, e);
    }
}

From source file:org.deshang.content.indexing.util.jdbc.AbstractRowMapper.java

protected String getBlobContent(Blob blob) throws SQLException {

    LOGGER.debug("Enter getBlobContent(Blob)");
    String blobContent = null;/*w w w . jav a2s .  c  om*/
    try {
        InputStream in = blob.getBinaryStream();
        BufferedInputStream bis = new BufferedInputStream(in);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        int data = -1;
        while ((data = bis.read()) != -1) {
            baos.write(data);
        }
        blobContent = baos.toString("UTF-8");
    } catch (IOException e) {
        throw new SQLException("Can't read blob conent", e);
    }

    LOGGER.debug("Exit getBlobContent(Blob)");
    return blobContent;
}