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);
}
}
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);
}
}
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();
}
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();
}
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());
}
Aggregations