use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.
the class Util method logError.
private static void logError(String errorMessage, Throwable t) {
HeaderPrintWriter errorStream = Monitor.getStream();
if (errorStream == null) {
t.printStackTrace();
return;
}
ErrorStringBuilder errorStringBuilder = new ErrorStringBuilder(errorStream.getHeader());
errorStringBuilder.append(errorMessage);
errorStringBuilder.stackTrace(t);
errorStream.print(errorStringBuilder.get().toString());
errorStream.flush();
errorStringBuilder.reset();
}
use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.
the class SingleStream method makeStyleHPW.
private HeaderPrintWriter makeStyleHPW(String style, PrintWriterGetHeader header) {
HeaderPrintWriter res = null;
if ("rollingFile".equals(style)) {
String className = "org.apache.derby.impl.services.stream.RollingFileStreamProvider.getOutputStream";
res = makeMethodHPW(className, header, true);
} else {
try {
IllegalArgumentException ex = new IllegalArgumentException("unknown derby.stream.error.style: " + style);
throw ex;
} catch (IllegalArgumentException t) {
res = useDefaultStream(header, t);
} catch (Exception t) {
res = useDefaultStream(header, t);
}
}
return res;
}
use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.
the class SingleStream method makeFieldHPW.
private HeaderPrintWriter makeFieldHPW(String fieldAccess, PrintWriterGetHeader header) {
int lastDot = fieldAccess.lastIndexOf('.');
String className = fieldAccess.substring(0, lastDot);
String fieldName = fieldAccess.substring(lastDot + 1, fieldAccess.length());
Throwable t;
try {
Class theClass = Class.forName(className);
try {
Field theField = theClass.getField(fieldName);
if (!Modifier.isStatic(theField.getModifiers())) {
HeaderPrintWriter hpw = useDefaultStream(header);
hpw.printlnWithHeader(theField.toString() + " is not static");
return hpw;
}
try {
return makeValueHPW(theField, theField.get((Object) null), header, fieldAccess, false);
} catch (IllegalAccessException iae) {
t = iae;
} catch (IllegalArgumentException iarge) {
t = iarge;
}
} catch (NoSuchFieldException nsfe) {
t = nsfe;
}
} catch (ClassNotFoundException cnfe) {
t = cnfe;
} catch (SecurityException se) {
t = se;
}
return useDefaultStream(header, t);
/*
If we decide it is a bad idea to use reflect and need
an alternate implementation, we can hard-wire those
fields that we desire to give configurations access to,
like so:
if ("java.lang.System.out".equals(fieldAccess))
os = System.out;
else if ("java.lang.System.err".equals(fieldAccess))
os = System.err;
*/
}
use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.
the class SingleStream method useDefaultStream.
private HeaderPrintWriter useDefaultStream(PrintWriterGetHeader header, Throwable t) {
HeaderPrintWriter hpw = useDefaultStream(header);
while (t != null) {
Throwable causedBy = t.getCause();
String causedByStr = MessageService.getTextMessage(MessageId.CAUSED_BY);
hpw.printlnWithHeader(t.toString() + (causedBy != null ? " " + causedByStr : ""));
t = causedBy;
}
return hpw;
}
use of org.apache.derby.shared.common.stream.HeaderPrintWriter in project derby by apache.
the class SingleStream method makeStream.
//
// class interface
//
/**
* Make the stream; note that service properties override
* application and system properties.
*/
private HeaderPrintWriter makeStream() {
// get the header
PrintWriterGetHeader header = makeHeader();
HeaderPrintWriter hpw = makeHPW(header);
// so use/create the default stream.
if (hpw == null)
hpw = createDefaultStream(header);
return hpw;
}
Aggregations