Search in sources :

Example 56 with UncheckedIOException

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;
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 57 with UncheckedIOException

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);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 58 with UncheckedIOException

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);
}
Also used : Schema(org.apache.avro.Schema) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) UncheckedIOException(java.io.UncheckedIOException) JMXBeanMapping(org.spf4j.jmx.JMXBeanMapping) NotSerializableException(java.io.NotSerializableException) CompositeType(javax.management.openmbean.CompositeType)

Example 59 with UncheckedIOException

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());
        }
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 60 with UncheckedIOException

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();
}
Also used : MeasurementAccumulator(org.spf4j.perf.MeasurementAccumulator) StringWriter(java.io.StringWriter) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MeasurementsInfo(org.spf4j.perf.MeasurementsInfo) HashMap(java.util.HashMap) Map(java.util.Map) TObjectLongMap(gnu.trove.map.TObjectLongMap) TObjectLongHashMap(gnu.trove.map.hash.TObjectLongHashMap) JmxExport(org.spf4j.jmx.JmxExport)

Aggregations

UncheckedIOException (java.io.UncheckedIOException)826 IOException (java.io.IOException)786 File (java.io.File)109 Path (java.nio.file.Path)106 ArrayList (java.util.ArrayList)70 InputStream (java.io.InputStream)58 Map (java.util.Map)58 List (java.util.List)55 HashMap (java.util.HashMap)44 Test (org.junit.Test)38 Files (java.nio.file.Files)37 Collectors (java.util.stream.Collectors)37 Stream (java.util.stream.Stream)31 URL (java.net.URL)29 StringWriter (java.io.StringWriter)27 CursorContext (org.neo4j.io.pagecache.context.CursorContext)25 FileInputStream (java.io.FileInputStream)23 HashSet (java.util.HashSet)23 PageCursor (org.neo4j.io.pagecache.PageCursor)22 Optional (java.util.Optional)21