Search in sources :

Example 96 with CharArrayWriter

use of java.io.CharArrayWriter in project sling by apache.

the class JspReader method getText.

String getText(Mark start, Mark stop) throws JasperException {
    Mark oldstart = mark();
    reset(start);
    CharArrayWriter caw = new CharArrayWriter();
    while (!stop.equals(mark())) caw.write(nextChar());
    caw.close();
    reset(oldstart);
    return caw.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 97 with CharArrayWriter

use of java.io.CharArrayWriter in project tika by apache.

the class IOUtils method toCharArray.

// read char[]
//-----------------------------------------------------------------------
/**
     * Get the contents of an <code>InputStream</code> as a character array
     * using the default character encoding of the platform.
     * <p>
     * This method buffers the input internally, so there is no need to use a
     * <code>BufferedInputStream</code>.
     * 
     * @param is  the <code>InputStream</code> to read from
     * @return the requested character array
     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     * @since Commons IO 1.1
     */
public static char[] toCharArray(InputStream is) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    copy(is, output);
    return output.toCharArray();
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 98 with CharArrayWriter

use of java.io.CharArrayWriter in project tika by apache.

the class IOUtils method toCharArray.

/**
     * Get the contents of an <code>InputStream</code> as a character array
     * using the specified character encoding.
     * <p>
     * Character encoding names can be found at
     * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
     * <p>
     * This method buffers the input internally, so there is no need to use a
     * <code>BufferedInputStream</code>.
     * 
     * @param is  the <code>InputStream</code> to read from
     * @param encoding  the encoding to use, null means platform default
     * @return the requested character array
     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     * @since Commons IO 1.1
     */
public static char[] toCharArray(InputStream is, String encoding) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    copy(is, output, encoding);
    return output.toCharArray();
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 99 with CharArrayWriter

use of java.io.CharArrayWriter in project tika by apache.

the class MagicDetector method decodeString.

private static byte[] decodeString(String value, String type) {
    if (value.startsWith("0x")) {
        byte[] vals = new byte[(value.length() - 2) / 2];
        for (int i = 0; i < vals.length; i++) {
            vals[i] = (byte) Integer.parseInt(value.substring(2 + i * 2, 4 + i * 2), 16);
        }
        return vals;
    }
    CharArrayWriter decoded = new CharArrayWriter();
    for (int i = 0; i < value.length(); i++) {
        if (value.charAt(i) == '\\') {
            if (value.charAt(i + 1) == '\\') {
                decoded.write('\\');
                i++;
            } else if (value.charAt(i + 1) == 'x') {
                decoded.write(Integer.parseInt(value.substring(i + 2, i + 4), 16));
                i += 3;
            } else if (value.charAt(i + 1) == 'r') {
                decoded.write((int) '\r');
                i++;
            } else if (value.charAt(i + 1) == 'n') {
                decoded.write((int) '\n');
                i++;
            } else {
                int j = i + 1;
                while ((j < i + 4) && (j < value.length()) && (Character.isDigit(value.charAt(j)))) {
                    j++;
                }
                decoded.write(Short.decode("0" + value.substring(i + 1, j)).byteValue());
                i = j - 1;
            }
        } else {
            decoded.write(value.charAt(i));
        }
    }
    // Now turn the chars into bytes
    char[] chars = decoded.toCharArray();
    byte[] bytes;
    if ("unicodeLE".equals(type)) {
        bytes = new byte[chars.length * 2];
        for (int i = 0; i < chars.length; i++) {
            bytes[i * 2] = (byte) (chars[i] & 0xff);
            bytes[i * 2 + 1] = (byte) (chars[i] >> 8);
        }
    } else if ("unicodeBE".equals(type)) {
        bytes = new byte[chars.length * 2];
        for (int i = 0; i < chars.length; i++) {
            bytes[i * 2] = (byte) (chars[i] >> 8);
            bytes[i * 2 + 1] = (byte) (chars[i] & 0xff);
        }
    } else {
        // Copy with truncation
        bytes = new byte[chars.length];
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = (byte) chars[i];
        }
    }
    return bytes;
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 100 with CharArrayWriter

use of java.io.CharArrayWriter in project jgnash by ccavanaugh.

the class MessageBusClient method sendRemoteMessage.

synchronized void sendRemoteMessage(final Message message) {
    CharArrayWriter writer = new CharArrayWriter();
    xstream.marshal(message, new CompactWriter(writer));
    sendRemoteMessage(writer.toString());
    logger.log(Level.FINE, "sent: {0}", writer.toString());
}
Also used : CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) CharArrayWriter(java.io.CharArrayWriter)

Aggregations

CharArrayWriter (java.io.CharArrayWriter)104 PrintWriter (java.io.PrintWriter)23 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)21 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)7 BufferedReader (java.io.BufferedReader)6 Test (org.junit.Test)5 CharArrayReader (java.io.CharArrayReader)4 File (java.io.File)4 FeatureVector (com.airbnb.aerosolve.core.FeatureVector)3 ModelHeader (com.airbnb.aerosolve.core.ModelHeader)3 ModelRecord (com.airbnb.aerosolve.core.ModelRecord)3 BufferedWriter (java.io.BufferedWriter)3 Reader (java.io.Reader)3 StringReader (java.io.StringReader)3 HashMap (java.util.HashMap)3 Transformer (javax.xml.transform.Transformer)3 StreamResult (javax.xml.transform.stream.StreamResult)3 InputStream (java.io.InputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2