Java Code Examples for java.io.CharArrayWriter#size()
The following examples show how to use
java.io.CharArrayWriter#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ErrorPage.java From hadoop with Apache License 2.0 | 5 votes |
public static String toStackTrace(Throwable error, int cutoff) { // default initial size is 32 chars CharArrayWriter buffer = new CharArrayWriter(8 * 1024); error.printStackTrace(new PrintWriter(buffer)); return buffer.size() < cutoff ? buffer.toString() : buffer.toString().substring(0, cutoff); }
Example 2
Source File: ErrorPage.java From big-c with Apache License 2.0 | 5 votes |
public static String toStackTrace(Throwable error, int cutoff) { // default initial size is 32 chars CharArrayWriter buffer = new CharArrayWriter(8 * 1024); error.printStackTrace(new PrintWriter(buffer)); return buffer.size() < cutoff ? buffer.toString() : buffer.toString().substring(0, cutoff); }
Example 3
Source File: SyslogAuditService.java From xipki with Apache License 2.0 | 5 votes |
@Override public void logEvent(PciAuditEvent event) { if (!initialized) { LOG.error("syslog audit not initialiazed"); return; } CharArrayWriter msg = event.toCharArrayWriter(prefix); final int n = msg.size(); if (n > maxMessageLength) { LOG.warn("syslog message exceeds the maximal allowed length: {} > {}, ignore it", n, maxMessageLength); return; } SyslogMessage sm = new SyslogMessage(); sm.setFacility(syslog.getDefaultFacility()); if (notEmpty(localname)) { sm.setHostname(localname); } sm.setSeverity(getSeverity(event.getLevel())); sm.setMsg(msg); try { syslog.sendMessage(sm); } catch (Throwable th) { LOG.error("could not send syslog message: {}", th.getMessage()); LOG.debug("could not send syslog message", th); } }
Example 4
Source File: Parser.java From Tomcat8-Source-Read with MIT License | 4 votes |
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); }
Example 5
Source File: Parser.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
private void parseTemplateText(Node parent) throws JasperException { 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); }
Example 6
Source File: CreateResultSet.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
@Override void processPlan(CharArrayWriter out, boolean isLocalPlanExtracted) throws SQLException, IOException { // query node plan if(!ds.isRemote() && !ds.isDerbyActivation()) { createBaseInfo(out); createScatterInfo(out); createBaseIterationInfo(out); createOtherIterationInfo(out); } else { /*if( !createBaseResponseInfo(out) ) { // no possibility of local execution as well. return; } createMsgReceiveAndResultSendInfo(out);*/ } // to avoid recursion further. if (!isLocalPlanExtracted) { BasicUUID locallyExecutedId = new BasicUUID(ds.getQueryID()); // for derby activation, without this flag, local plan will be captured. if (!ds.isDerbyActivation()) { locallyExecutedId.setLocallyExecuted(1); } if (SanityManager.DEBUG) { if (GemFireXDUtils.TracePlanGeneration) { SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_PLAN_GENERATION, "Now determining locally Executed Plan if any for " + ds.getQueryID() + " with local stmtUUID=" + locallyExecutedId.toString()); } } CharArrayWriter tmpXML = new CharArrayWriter(); new CreateXML(ds.getClone(locallyExecutedId.toString()), true, XMLForms.none, null) .processPlan(tmpXML, true); if (SanityManager.DEBUG) { if (GemFireXDUtils.TracePlanGeneration) { SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_PLAN_GENERATION, "CreateResultSet: Got Local Plan as : " + tmpXML.size() + " data " + tmpXML.toString()); } } if(tmpXML.size() > 0) { Element e = CreateXML.transformToXML(tmpXML.toCharArray()); final List<Element> el = new ArrayList<Element> (); el.add(e); out.write(String.valueOf(Misc.serializeXMLAsCharArr(el, "vanilla_text.xsl"))); } tmpXML.close(); /*new CreateResultSet(ds.getClone(locallyExecutedId.toString()), true) .processPlan(out, true);*/ } }
Example 7
Source File: Parser.java From tomcatsrc with Apache License 2.0 | 4 votes |
private void parseTemplateText(Node parent) throws JasperException { 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); }
Example 8
Source File: CreateResultSet.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
@Override void processPlan(CharArrayWriter out, boolean isLocalPlanExtracted) throws SQLException, IOException { // query node plan if(!ds.isRemote() && !ds.isDerbyActivation()) { createBaseInfo(out); createScatterInfo(out); createBaseIterationInfo(out); createOtherIterationInfo(out); } else { /*if( !createBaseResponseInfo(out) ) { // no possibility of local execution as well. return; } createMsgReceiveAndResultSendInfo(out);*/ } // to avoid recursion further. if (!isLocalPlanExtracted) { BasicUUID locallyExecutedId = new BasicUUID(ds.getQueryID()); // for derby activation, without this flag, local plan will be captured. if (!ds.isDerbyActivation()) { locallyExecutedId.setLocallyExecuted(1); } if (SanityManager.DEBUG) { if (GemFireXDUtils.TracePlanGeneration) { SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_PLAN_GENERATION, "Now determining locally Executed Plan if any for " + ds.getQueryID() + " with local stmtUUID=" + locallyExecutedId.toString()); } } CharArrayWriter tmpXML = new CharArrayWriter(); new CreateXML(ds.getClone(locallyExecutedId.toString()), true, XMLForms.none, null) .processPlan(tmpXML, true); if (SanityManager.DEBUG) { if (GemFireXDUtils.TracePlanGeneration) { SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_PLAN_GENERATION, "CreateResultSet: Got Local Plan as : " + tmpXML.size() + " data " + tmpXML.toString()); } } if(tmpXML.size() > 0) { Element e = CreateXML.transformToXML(tmpXML.toCharArray()); final List<Element> el = new ArrayList<Element> (); el.add(e); out.write(String.valueOf(Misc.serializeXMLAsCharArr(el, "vanilla_text.xsl"))); } tmpXML.close(); /*new CreateResultSet(ds.getClone(locallyExecutedId.toString()), true) .processPlan(out, true);*/ } }
Example 9
Source File: SyslogAuditService.java From xipki with Apache License 2.0 | 4 votes |
@Override public void logEvent(AuditEvent event) { if (!initialized) { LOG.error("syslog audit not initialized"); return; } final CharArrayWriter sb = new CharArrayWriter(150); if (notEmpty(prefix)) { sb.append(prefix); } AuditStatus status = event.getStatus(); if (status == null) { status = AuditStatus.UNDEFINED; } sb.append("\tstatus: ").append(status.name()); long duration = event.getDuration(); if (duration >= 0) { sb.append("\tduration: ").append(Long.toString(duration)); } final List<AuditEventData> eventDataArray = event.getEventDatas(); for (final AuditEventData m : eventDataArray) { if (!(duration >= 0 && "duration".equalsIgnoreCase(m.getName()))) { sb.append("\t").append(m.getName()).append(": ").append(m.getValue()); } } final int n = sb.size(); if (n > maxMessageLength) { LOG.warn("syslog message exceeds the maximal allowed length: {} > {}, ignore it", n, maxMessageLength); return; } final SyslogMessage sm = new SyslogMessage(); sm.setFacility(syslog.getDefaultFacility()); if (notEmpty(localname)) { sm.setHostname(localname); } sm.setAppName(event.getApplicationName()); sm.setSeverity(getSeverity(event.getLevel())); Date timestamp = event.getTimestamp(); if (timestamp != null) { sm.setTimestamp(timestamp); } sm.setMsgId(event.getName()); sm.setMsg(sb); try { syslog.sendMessage(sm); } catch (Throwable th) { LOG.error("could not send syslog message: {}", th.getMessage()); LOG.debug("could not send syslog message", th); } }