Search in sources :

Example 11 with CharArrayWriter

use of java.io.CharArrayWriter in project android_frameworks_base by DirtyUnicorns.

the class DiskInfo method toString.

@Override
public String toString() {
    final CharArrayWriter writer = new CharArrayWriter();
    dump(new IndentingPrintWriter(writer, "    ", 80));
    return writer.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 12 with CharArrayWriter

use of java.io.CharArrayWriter in project android_frameworks_base by DirtyUnicorns.

the class VolumeInfo method toString.

@Override
public String toString() {
    final CharArrayWriter writer = new CharArrayWriter();
    dump(new IndentingPrintWriter(writer, "    ", 80));
    return writer.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter)

Example 13 with CharArrayWriter

use of java.io.CharArrayWriter in project jdk8u_jdk by JetBrains.

the class DriverManagerTests method tests18.

/**
     * Create a PrintWriter and use to to send output via DriverManager.println
     * Validate that if you disable the writer, the output sent is not present
     */
@Test
public void tests18() throws Exception {
    CharArrayWriter cw = new CharArrayWriter();
    PrintWriter pw = new PrintWriter(cw);
    DriverManager.setLogWriter(pw);
    assertTrue(DriverManager.getLogWriter() == pw);
    DriverManager.println(results[0]);
    DriverManager.setLogWriter(null);
    assertTrue(DriverManager.getLogWriter() == null);
    DriverManager.println(noOutput);
    DriverManager.setLogWriter(pw);
    DriverManager.println(results[1]);
    DriverManager.println(results[2]);
    DriverManager.println(results[3]);
    DriverManager.setLogWriter(null);
    DriverManager.println(noOutput);
    /*
         * Check we do not get the output when the stream is disabled
         */
    BufferedReader reader = new BufferedReader(new CharArrayReader(cw.toCharArray()));
    for (String result : results) {
        assertTrue(result.equals(reader.readLine()));
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) BufferedReader(java.io.BufferedReader) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 14 with CharArrayWriter

use of java.io.CharArrayWriter in project intellij-community by JetBrains.

the class Base64 method encode.

public static char[] encode(byte[] content) {
    CharArrayWriter cw = new CharArrayWriter((4 * content.length) / 3);
    int idx = 0;
    int x = 0;
    for (int i = 0; i < content.length; i++) {
        if (idx == 0)
            x = (content[i] & 0xff) << 16;
        else if (idx == 1)
            x = x | ((content[i] & 0xff) << 8);
        else
            x = x | (content[i] & 0xff);
        idx++;
        if (idx == 3) {
            cw.write(alphabet[x >> 18]);
            cw.write(alphabet[(x >> 12) & 0x3f]);
            cw.write(alphabet[(x >> 6) & 0x3f]);
            cw.write(alphabet[x & 0x3f]);
            idx = 0;
        }
    }
    if (idx == 1) {
        cw.write(alphabet[x >> 18]);
        cw.write(alphabet[(x >> 12) & 0x3f]);
        cw.write('=');
        cw.write('=');
    }
    if (idx == 2) {
        cw.write(alphabet[x >> 18]);
        cw.write(alphabet[(x >> 12) & 0x3f]);
        cw.write(alphabet[(x >> 6) & 0x3f]);
        cw.write('=');
    }
    return cw.toCharArray();
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 15 with CharArrayWriter

use of java.io.CharArrayWriter in project intellij-community by JetBrains.

the class XMLOutputterTest method printElement.

private String printElement(Element root) throws IOException {
    XMLOutputter xmlOutputter = JDOMUtil.createOutputter("\n");
    final Format format = xmlOutputter.getFormat().setOmitDeclaration(true).setOmitEncoding(true).setExpandEmptyElements(true);
    xmlOutputter.setFormat(format);
    CharArrayWriter writer = new CharArrayWriter();
    xmlOutputter.output(root, writer);
    String res = new String(writer.toCharArray());
    return res;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Format(org.jdom.output.Format) CharArrayWriter(java.io.CharArrayWriter)

Aggregations

CharArrayWriter (java.io.CharArrayWriter)211 PrintWriter (java.io.PrintWriter)51 IOException (java.io.IOException)39 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)21 Test (org.junit.Test)11 InputStreamReader (java.io.InputStreamReader)9 Map (java.util.Map)9 BufferedReader (java.io.BufferedReader)8 File (java.io.File)8 ArrayList (java.util.ArrayList)8 TitledBorder (javax.swing.border.TitledBorder)8 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)7 Graph (edu.cmu.tetrad.graph.Graph)7 Writable (groovy.lang.Writable)7 CharArrayReader (java.io.CharArrayReader)7 Reader (java.io.Reader)7 Date (java.util.Date)7 InputStream (java.io.InputStream)6 StringReader (java.io.StringReader)6 IKnowledge (edu.cmu.tetrad.data.IKnowledge)5