use of java.io.UncheckedIOException in project spf4j by zolyfarkas.
the class LogPrinter method handle.
/**
* {@inheritDoc}
*/
@SuppressFBWarnings({ "CFS_CONFUSING_FUNCTION_SEMANTICS", "EXS_EXCEPTION_SOFTENING_NO_CHECKED" })
@Override
public LogRecord handle(final LogRecord record) {
if (record.hasAttachment(PRINTED)) {
return record;
}
try {
Buffer buff = TL_BUFFER.get();
buff.clear();
print(record, buff.getWriter(), buff.getWriterEscaper(), "");
if (record.getLevel() == Level.ERROR) {
System.err.write(buff.getBytes(), 0, buff.size());
System.err.flush();
} else {
System.out.write(buff.getBytes(), 0, buff.size());
System.out.flush();
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
record.attach(PRINTED);
return record;
}
use of java.io.UncheckedIOException in project spf4j by zolyfarkas.
the class LogPrinter method printTo.
public static void printTo(final PrintStream stream, final LogRecord record, final String annotate) {
Buffer buff = TL_BUFFER.get();
buff.clear();
try {
print(record, buff.getWriter(), buff.getWriterEscaper(), annotate);
stream.write(buff.getBytes(), 0, buff.size());
stream.flush();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
use of java.io.UncheckedIOException in project spf4j by zolyfarkas.
the class SpecificRecordOpenTypeMapping method fromSpecificRecord.
private CompositeData fromSpecificRecord(final SpecificRecordBase r) throws OpenDataException {
CompositeType ctype;
try {
ctype = typeFromSpecificRecord(r, typeMapper);
} catch (NotSerializableException ex) {
// this should never happen
throw new UncheckedIOException(ex);
}
Schema schema = r.getSchema();
List<Schema.Field> fields = schema.getFields();
int size = fields.size();
String[] names = new String[size];
Object[] values = new Object[size];
for (Schema.Field field : fields) {
int pos = field.pos();
names[pos] = field.name();
Object val = r.get(pos);
JMXBeanMapping mapping;
try {
mapping = typeMapper.get(getGenericType(field.schema()));
} catch (NotSerializableException ex) {
// this should never happen
throw new UncheckedIOException(ex);
}
values[pos] = mapping.toOpenValue(val);
}
return new CompositeDataSupport(ctype, names, values);
}
use of java.io.UncheckedIOException in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorder method close.
@Override
@SuppressFBWarnings("EXS_EXCEPTION_SOFTENING_NO_CHECKED")
public void close() {
synchronized (shutdownHook) {
if (!samplingFuture.isCancelled()) {
org.spf4j.base.Runtime.removeQueuedShutdownHook(shutdownHook);
samplingFuture.cancel(false);
try {
persister.persist(false);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
Registry.unregister("org.spf4j.perf.recorders", processorTemplate.getInfo().getMeasuredEntity().toString());
}
}
}
use of java.io.UncheckedIOException in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorderSource method getMeasurementsAsString.
@JmxExport(description = "measurements as csv")
public String getMeasurementsAsString() {
StringWriter sw = new StringWriter(128);
Map<Object, MeasurementAccumulator> entitiesMeasurements = getEntitiesMeasurements();
MeasurementsInfo info = this.processorTemplate.getInfo();
try {
Csv.writeCsvRow2(sw, "Measured", (Object[]) info.getMeasurementNames());
Csv.writeCsvRow2(sw, "string", (Object[]) info.getMeasurementUnits());
for (Map.Entry<Object, MeasurementAccumulator> entry : entitiesMeasurements.entrySet()) {
Csv.writeCsvElement(entry.getKey().toString(), sw);
sw.write(',');
final long[] measurements = entry.getValue().get();
if (measurements != null) {
Csv.writeCsvRow(sw, measurements);
}
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return sw.toString();
}
Aggregations