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());
}
}
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", "<jsp:text>");
}
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", "<jsp:text>");
} else if (!reader.matchesETagWithoutLessThan("jsp:text")) {
err.jspError(start, "jsp.error.jsptext.badcontent");
}
}
}
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);
}
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());
}
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.
}
}
Aggregations