Search in sources :

Example 66 with CharArrayWriter

use of java.io.CharArrayWriter in project k-9 by k9mail.

the class MessagingController method addErrorMessage.

void addErrorMessage(Account account, String subject, Throwable t) {
    try {
        if (t == null) {
            return;
        }
        CharArrayWriter baos = new CharArrayWriter(t.getStackTrace().length * 10);
        PrintWriter ps = new PrintWriter(baos);
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            ps.format("K9-Mail version: %s\r\n", packageInfo.versionName);
        } catch (Exception e) {
        // ignore
        }
        ps.format("Device make: %s\r\n", Build.MANUFACTURER);
        ps.format("Device model: %s\r\n", Build.MODEL);
        ps.format("Android version: %s\r\n\r\n", Build.VERSION.RELEASE);
        t.printStackTrace(ps);
        ps.close();
        if (subject == null) {
            subject = getRootCauseMessage(t);
        }
        addErrorMessage(account, subject, baos.toString());
    } catch (Throwable it) {
        Timber.e(it, "Could not save error message to %s", account.getErrorFolderName());
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) CharArrayWriter(java.io.CharArrayWriter) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) PrintWriter(java.io.PrintWriter)

Example 67 with CharArrayWriter

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

the class Parser method parseXMLTemplateText.

/*
     * XMLTemplateText ::= ( S? '/>' ) | ( S? '>' ( ( Char* - ( Char* ( '<' |
     * '${' ) ) ) ( '${' ELExpressionBody )? CDSect? )* ETag ) |
     * <TRANSLATION_ERROR>
     */
private void parseXMLTemplateText(Node parent) throws JasperException {
    reader.skipSpaces();
    if (!reader.matches("/>")) {
        if (!reader.matches(">")) {
            err.jspError(start, "jsp.error.unterminated", "&lt;jsp:text&gt;");
        }
        CharArrayWriter ttext = new CharArrayWriter();
        int ch = reader.nextChar();
        while (ch != -1) {
            if (ch == '<') {
                // Check for <![CDATA[
                if (!reader.matches("![CDATA[")) {
                    break;
                }
                start = reader.mark();
                Mark stop = reader.skipUntil("]]>");
                if (stop == null) {
                    err.jspError(start, "jsp.error.unterminated", "CDATA");
                }
                String text = reader.getText(start, stop);
                ttext.write(text, 0, text.length());
            } else if (ch == '\\') {
                int next = reader.peekChar(0);
                if (next == '$' || next == '#') {
                    ttext.write(reader.nextChar());
                } else {
                    ttext.write('\\');
                }
            } else if (ch == '$' || ch == '#') {
                if (reader.peekChar(0) == '{') {
                    // Swallow the '{'
                    reader.nextChar();
                    // Create a template text node
                    @SuppressWarnings("unused") Node unused = new Node.TemplateText(ttext.toString(), start, parent);
                    // Mark and parse the EL expression and create its node:
                    parseELExpression(parent, (char) ch);
                    start = reader.mark();
                    ttext.reset();
                } else {
                    ttext.write(ch);
                }
            } else {
                ttext.write(ch);
            }
            ch = reader.nextChar();
        }
        @SuppressWarnings("unused") Node unused = new Node.TemplateText(ttext.toString(), start, parent);
        if (!reader.hasMoreInput()) {
            err.jspError(start, "jsp.error.unterminated", "&lt;jsp:text&gt;");
        } else if (!reader.matchesETagWithoutLessThan("jsp:text")) {
            err.jspError(start, "jsp.error.jsptext.badcontent");
        }
    }
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 68 with CharArrayWriter

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

the class Parser method parseTemplateText.

/*
     * Parse for a template text string until '<' or "${" or "#{" is encountered,
     * recognizing escape sequences "<\%", "\$", and "\#".
     *
     * Note: JSP uses '\$' as an escape for '$' and '\#' for '#' whereas EL uses
     *       '\${' for '${' and '\#{' for '#{'. We are processing JSP template
     *       test here so the JSP escapes apply.
     */
private void parseTemplateText(Node parent) {
    if (!reader.hasMoreInput())
        return;
    CharArrayWriter ttext = new CharArrayWriter();
    int ch = reader.nextChar();
    while (ch != -1) {
        if (ch == '<') {
            // Check for "<\%"
            if (reader.peekChar(0) == '\\' && reader.peekChar(1) == '%') {
                ttext.write(ch);
                // Swallow the \
                reader.nextChar();
                ttext.write(reader.nextChar());
            } else {
                if (ttext.size() == 0) {
                    ttext.write(ch);
                } else {
                    reader.pushChar();
                    break;
                }
            }
        } else if (ch == '\\' && !pageInfo.isELIgnored()) {
            int next = reader.peekChar(0);
            if (next == '$' || next == '#') {
                ttext.write(reader.nextChar());
            } else {
                ttext.write(ch);
            }
        } else if ((ch == '$' || ch == '#' && !pageInfo.isDeferredSyntaxAllowedAsLiteral()) && !pageInfo.isELIgnored()) {
            if (reader.peekChar(0) == '{') {
                reader.pushChar();
                break;
            } else {
                ttext.write(ch);
            }
        } else {
            ttext.write(ch);
        }
        ch = reader.nextChar();
    }
    @SuppressWarnings("unused") Node unused = new Node.TemplateText(ttext.toString(), start, parent);
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 69 with CharArrayWriter

use of java.io.CharArrayWriter in project grails-core by grails.

the class StreamCharBufferTests method testToReader.

public void testToReader() throws IOException {
    StreamCharBuffer charBuffer = createTestInstance();
    Reader input = charBuffer.getReader();
    CharArrayWriter charsOut = new CharArrayWriter(charBuffer.size());
    copy(input, charsOut, 2048);
    char[] result = charsOut.toCharArray();
    assertTrue(Arrays.equals(testbuffer, result));
    assertEquals(testbuffer.length, charBuffer.size());
}
Also used : Reader(java.io.Reader) CharArrayWriter(java.io.CharArrayWriter)

Example 70 with CharArrayWriter

use of java.io.CharArrayWriter in project j2objc by google.

the class OldCharArrayWriterTest method test_write$CII_Exception.

public void test_write$CII_Exception() {
    char[] target = new char[10];
    cw = new CharArrayWriter();
    try {
        cw.write(target, -1, 1);
        fail("Test 1: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        cw.write(target, 0, -1);
        fail("Test 2: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        cw.write(target, 1, target.length);
        fail("Test 3: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected
    }
    try {
        cw.write((char[]) null, 1, 1);
        fail("Test 4: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected.
    }
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Aggregations

CharArrayWriter (java.io.CharArrayWriter)116 PrintWriter (java.io.PrintWriter)28 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)21 IOException (java.io.IOException)16 BufferedReader (java.io.BufferedReader)7 ArrayList (java.util.ArrayList)7 CharArrayReader (java.io.CharArrayReader)6 Test (org.junit.Test)5 File (java.io.File)4 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 HashMap (java.util.HashMap)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 InputStreamReader (java.io.InputStreamReader)3 StreamResult (javax.xml.transform.stream.StreamResult)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2