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

public synchronized String toString() 

Source Link

Document

Converts the buffer's contents into a string decoding bytes using the platform's default character set.

Usage

From source file:imagingbook.lib.math.Matrix.java

public static String toString(double[] A) {
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    PrintStream strm = new PrintStream(bas);
    printToStream(A, strm);//from w  ww.  j  a v  a 2s.c  om
    return bas.toString();
}

From source file:imagingbook.lib.math.Matrix.java

public static String toString(double[][] A) {
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    PrintStream strm = new PrintStream(bas);
    printToStream(A, strm);/* w ww  .  java  2  s  .c om*/
    return bas.toString();
}

From source file:imagingbook.lib.math.Matrix.java

public static String toString(float[] A) {
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    PrintStream strm = new PrintStream(bas);
    printToStream(A, strm);//  w  w w  .j  a  v a 2  s .  c o  m
    return bas.toString();
}

From source file:imagingbook.lib.math.Matrix.java

public static String toString(float[][] A) {
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    PrintStream strm = new PrintStream(bas);
    printToStream(A, strm);/*from   www . j a  v a 2 s  . c o  m*/
    return bas.toString();
}

From source file:com.xebialabs.overthere.cifs.telnet.CifsTelnetConnection.java

private static void receive(final InputStream stdout, final ByteArrayOutputStream outputBuf,
        final PipedOutputStream toCallersStdout, final String expectedString, final String unexpectedString)
        throws IOException {
    boolean lastCharWasCr = false;
    boolean lastCharWasEsc = false;
    for (;;) {// w w w  .  j  a  v a  2  s  .c  o m
        int cInt = stdout.read();
        if (cInt == -1) {
            throw new IOException("End of stream reached");
        }

        outputBuf.write(cInt);
        final String outputBufStr = outputBuf.toString();
        char c = (char) cInt;
        switch (c) {
        case '\r':
            handleReceivedLine(outputBuf, outputBufStr, toCallersStdout);
            break;
        case '\n':
            if (!lastCharWasCr) {
                handleReceivedLine(outputBuf, outputBufStr, toCallersStdout);
            }
            break;
        case '[':
            if (lastCharWasEsc) {
                throw new RuntimeIOException(
                        "VT100/ANSI escape sequence found in output stream. Please configure the Windows Telnet server to use stream mode (tlntadmn config mode=stream).");
            }
        }
        lastCharWasCr = (c == '\r');
        lastCharWasEsc = (c == 27);

        if (unexpectedString != null && outputBufStr.length() >= unexpectedString.length()) {
            String s = outputBufStr.substring(outputBufStr.length() - unexpectedString.length(),
                    outputBufStr.length());
            if (s.equals(unexpectedString)) {
                logger.debug("Unexpected string [{}] found in Windows Telnet output", unexpectedString);
                throw new IOException(
                        format("Unexpected string [%s] found in Windows Telnet output", unexpectedString));
            }
        }

        if (outputBufStr.length() >= expectedString.length()) {
            String s = outputBufStr.substring(outputBufStr.length() - expectedString.length(),
                    outputBufStr.length());
            if (s.equals(expectedString)) {
                logger.debug("Expected string [{}] found in Windows Telnet output", expectedString);
                return;
            }
        }
    }
}

From source file:com.netscape.cmsutil.util.Utils.java

public static String SpecialURLDecode(String s) {
    if (s == null)
        return null;
    ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());

    for (int i = 0; i < s.length(); i++) {
        int c = s.charAt(i);

        if (c == '+') {
            out.write(' ');
        } else if (c == '#') {
            int c1 = Character.digit(s.charAt(++i), 16);
            int c2 = Character.digit(s.charAt(++i), 16);

            out.write((char) (c1 * 16 + c2));
        } else {/*from   w  ww  .  j  a v a2s .  co m*/
            out.write(c);
        }
    } // end for
    return out.toString();
}

From source file:com.ikanow.aleph2.graph.titan.utils.TestMiscTitanProperties.java

protected static String showElement(final TitanGraph titan, final Element element) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (Vertex.class.isAssignableFrom(element.getClass())) {
        titan.io(IoCore.graphson()).writer().create().writeVertex(baos, (Vertex) element);
    } else {/*from ww  w. jav a 2s .  co  m*/
        titan.io(IoCore.graphson()).writer().create().writeEdge(baos, (Edge) element);
    }
    return baos.toString();
}

From source file:Main.java

public static String doGet(String urlStr) {
    URL url = null;//  ww w.  j a  v a  2 s.  c  o  m
    HttpURLConnection conn = null;
    InputStream is = null;
    ByteArrayOutputStream baos = null;
    try {
        url = new URL(urlStr);
        conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(TIMEOUT_IN_MILLIONS);
        conn.setConnectTimeout(TIMEOUT_IN_MILLIONS);
        conn.setRequestMethod("GET");
        conn.setRequestProperty("accept", "*/*");
        conn.setRequestProperty("connection", "Keep-Alive");
        if (conn.getResponseCode() == 200) {
            is = conn.getInputStream();
            baos = new ByteArrayOutputStream();
            int len = -1;
            byte[] buf = new byte[128];

            while ((len = is.read(buf)) != -1) {
                baos.write(buf, 0, len);
            }
            baos.flush();
            return baos.toString();
        } else {
            throw new RuntimeException(" responseCode is not 200 ... ");
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException e) {
        }
        try {
            if (baos != null)
                baos.close();
        } catch (IOException e) {
        }
        conn.disconnect();
    }

    return null;

}

From source file:com.cloverstudio.spika.couchdb.ConnectionHandler.java

public static void print(HttpEntity entity) throws IOException {
    ByteArrayOutputStream outstream = new ByteArrayOutputStream();
    entity.writeTo(outstream);//from   w  w w .j a v a 2  s . c  o  m
    String content = outstream.toString();
    Logger.debug("content", content);
}

From source file:com.khepry.utilities.GenericUtilities.java

public static String transformLogViaXSLT(String logFilePath, String xslFilePath)
        throws TransformerConfigurationException, TransformerException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    File logFile = new File(logFilePath);
    if (logFile.exists()) {
        File xslFile = new File(xslFilePath);
        if (xslFile.exists()) {
            TransformerFactory factory = TransformerFactory.newInstance();
            Source xslt = new StreamSource(new File(xslFilePath));
            Transformer transformer = factory.newTransformer(xslt);
            Source logXmlText = new StreamSource(new File(logFilePath));
            transformer.transform(logXmlText, new StreamResult(baos));
            return baos.toString();
        } else {// w  ww  . j  av a  2s  .  c o  m
            return new String(Files.readAllBytes(Paths.get(logFilePath)));
        }
    } else {
        return baos.toString();
    }
}