Search in sources :

Example 56 with CharArrayWriter

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

the class Base64Type method readObject.

@Override
public Object readObject(MessageReader mreader, Context context) throws DatabindingException {
    XMLStreamReader reader = mreader.getXMLStreamReader();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        reader.next();
        while (!reader.isCharacters() && !reader.isEndElement() && !reader.isStartElement()) {
            reader.next();
        }
        if (reader.isStartElement() && reader.getName().equals(AbstractXOPType.XOP_INCLUDE)) {
            return optimizedType.readMtoM(mreader, context);
        }
        if (reader.isEndElement()) {
            reader.next();
            return new byte[0];
        }
        CharArrayWriter writer = new CharArrayWriter(2048);
        while (reader.isCharacters()) {
            writer.write(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
            reader.next();
        }
        Base64Utility.decode(writer.toCharArray(), 0, writer.size(), bos);
        while (reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
            reader.next();
        }
        // Advance just past the end element
        reader.next();
        return bos.toByteArray();
    } catch (Base64Exception e) {
        throw new DatabindingException("Could not parse base64Binary data.", e);
    } catch (XMLStreamException e) {
        throw new DatabindingException("Could not parse base64Binary data.", e);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) Base64Exception(org.apache.cxf.common.util.Base64Exception) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CharArrayWriter(java.io.CharArrayWriter)

Example 57 with CharArrayWriter

use of java.io.CharArrayWriter in project xtext-core by eclipse.

the class AbstractAntlrGeneratorFragment2 method cleanupParserTokensFile.

protected void cleanupParserTokensFile(final AntlrGrammar lexerGrammar, final AntlrGrammar parserGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) {
    try {
        final MutableTokenDefProvider provider = this.createLexerTokensProvider(lexerGrammar, helper, fsa);
        Set<Map.Entry<Integer, String>> _entrySet = provider.getTokenDefMap().entrySet();
        for (final Map.Entry<Integer, String> entry : _entrySet) {
            {
                final String value = entry.getValue();
                boolean _isKeywordRule = helper.isKeywordRule(value);
                if (_isKeywordRule) {
                    final String keywordAsAntlrString = AntlrGrammarGenUtil.toAntlrString(helper.getKeywordValue(value));
                    entry.setValue((("\'" + keywordAsAntlrString) + "\'"));
                } else {
                    boolean _startsWith = value.startsWith("\'");
                    if (_startsWith) {
                        String _antlrString = AntlrGrammarGenUtil.toAntlrString(value);
                        String _plus = ("\'" + _antlrString);
                        String _plus_1 = (_plus + "\'");
                        entry.setValue(_plus_1);
                    }
                }
            }
        }
        final CharArrayWriter writer = new CharArrayWriter();
        PrintWriter _printWriter = new PrintWriter(writer);
        provider.writeTokenFile(_printWriter);
        String _tokensFileName = parserGrammar.getTokensFileName();
        char[] _charArray = writer.toCharArray();
        String _string = new String(_charArray);
        fsa.generateFile(_tokensFileName, _string);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : MutableTokenDefProvider(org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider) Map(java.util.Map) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter)

Example 58 with CharArrayWriter

use of java.io.CharArrayWriter in project xtext-core by eclipse.

the class LineSeparatorHarmonizer method replaceLineSeparators.

protected String replaceLineSeparators(CharSequence content, String newLineSeparator) {
    CharArrayWriter writer = new CharArrayWriter(content.length());
    boolean isLookahead = false;
    char ignoreNext = '\u0000';
    for (int i = 0; i < content.length(); ++i) {
        char c = content.charAt(i);
        if (isLookahead) {
            isLookahead = false;
            if (c == ignoreNext)
                continue;
        }
        switch(c) {
            case '\n':
                writer.append(newLineSeparator);
                isLookahead = true;
                ignoreNext = '\r';
                break;
            case '\r':
                writer.append(newLineSeparator);
                isLookahead = true;
                ignoreNext = '\n';
                break;
            default:
                writer.append(c);
        }
    }
    return writer.toString();
}
Also used : CharArrayWriter(java.io.CharArrayWriter)

Example 59 with CharArrayWriter

use of java.io.CharArrayWriter in project vcell by virtualcell.

the class SolverDescriptionRegression method readback.

// @Test
public void readback() throws IOException {
    CharArrayWriter buffer = new CharArrayWriter();
    PrintWriter record = new PrintWriter(buffer);
    for (String name : SolverNames) {
        dumpOne(name, record);
    }
    record.flush();
    char[] b = buffer.toCharArray();
    BufferedReader current = new BufferedReader(new CharArrayReader(b));
    LineNumberReader reference = new LineNumberReader(new FileReader("solvers.ref"));
    boolean nameNext = false;
    String currentSolver = null;
    while (reference.ready()) {
        String currentLine = current.readLine();
        String referenceLine = reference.readLine();
        if (nameNext) {
            currentSolver = currentLine;
            nameNext = false;
        } else if (currentLine.equals(SOLVER_SEP)) {
            nameNext = true;
        }
        if (!currentLine.equals(referenceLine)) {
            System.err.println("mismatch in " + currentSolver + " line " + reference.getLineNumber());
            System.err.println("\treference " + referenceLine);
            System.err.println("\tcurrent " + currentLine);
        }
    }
    reference.close();
}
Also used : CharArrayReader(java.io.CharArrayReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter) LineNumberReader(java.io.LineNumberReader)

Example 60 with CharArrayWriter

use of java.io.CharArrayWriter in project Payara by payara.

the class LoggerBase method log.

/**
 * Writes an explanatory message and a stack trace for a given
 * <code>Throwable</code> exception to the servlet log file.  The name
 * and type of the servlet log file is specific to the servlet container,
 * usually an event log.  This message will be logged unconditionally.
 *
 * @param msg A <code>String</code> that describes the error or
 *  exception
 * @param throwable The <code>Throwable</code> error or exception
 */
public void log(String msg, Throwable throwable) {
    CharArrayWriter buf = new CharArrayWriter();
    PrintWriter writer = new PrintWriter(buf);
    writer.println(msg);
    throwable.printStackTrace(writer);
    Throwable rootCause = null;
    if (throwable instanceof LifecycleException)
        rootCause = ((LifecycleException) throwable).getCause();
    else if (throwable instanceof ServletException)
        rootCause = ((ServletException) throwable).getRootCause();
    if (rootCause != null) {
        writer.println("----- Root Cause -----");
        rootCause.printStackTrace(writer);
    }
    log(buf.toString());
}
Also used : ServletException(javax.servlet.ServletException) LifecycleException(org.apache.catalina.LifecycleException) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter)

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