use of org.spf4j.io.ByteArrayBuilder in project spf4j by zolyfarkas.
the class ThreadUsageSampler method getPeakThreadInfo.
@JmxExport
@SuppressFBWarnings({ "DM_DEFAULT_ENCODING", "NP_LOAD_OF_KNOWN_NULL_VALUE" })
public static String getPeakThreadInfo() {
try (ByteArrayBuilder bab = new ByteArrayBuilder()) {
PrintStream ps = new PrintStream(bab);
writePeakThreadInfo(ps);
return bab.toString(Charset.defaultCharset());
}
}
use of org.spf4j.io.ByteArrayBuilder in project spf4j by zolyfarkas.
the class Objects method clone.
@SuppressFBWarnings("OBJECT_DESERIALIZATION")
public static <T extends Serializable> T clone(final T t) {
try (ByteArrayBuilder bos = new ByteArrayBuilder(256);
ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(t);
out.flush();
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.getBuffer(), 0, bos.size()))) {
return (T) in.readObject();
}
} catch (IOException | ClassNotFoundException e) {
throw new CloneFailedException("Failed to clone " + t, e);
}
}
use of org.spf4j.io.ByteArrayBuilder in project spf4j by zolyfarkas.
the class DataFragment method writeTo.
public void writeTo(final RandomAccessFile raf) throws IOException {
try (ByteArrayBuilder bos = new ByteArrayBuilder()) {
DataOutput dos = new DataOutputStream(bos);
writeTo(dos);
raf.seek(location);
raf.write(bos.getBuffer(), 0, bos.size());
}
}
use of org.spf4j.io.ByteArrayBuilder in project spf4j by zolyfarkas.
the class TSTable method writeTo.
void writeTo(final RandomAccessFile raf) throws IOException {
try (ByteArrayBuilder bos = new ByteArrayBuilder()) {
DataOutput dos = new DataOutputStream(bos);
writeTo(dos);
raf.seek(location);
raf.write(bos.getBuffer(), 0, bos.size());
}
}
use of org.spf4j.io.ByteArrayBuilder in project spf4j by zolyfarkas.
the class AvroTest method testRw.
@Test
public void testRw() throws IOException {
DataBlock data = DataBlock.newBuilder().setBaseTimestamp(0).setValues(Collections.EMPTY_LIST).build();
try (ByteArrayBuilder bab = new ByteArrayBuilder()) {
Schema schema = data.getSchema();
SpecificDatumWriter<DataBlock> writer = new SpecificDatumWriter<>(schema);
final BinaryEncoder directBinaryEncoder = EncoderFactory.get().directBinaryEncoder(bab, null);
writer.write(data, directBinaryEncoder);
directBinaryEncoder.flush();
ByteArrayInputStream bis = new ByteArrayInputStream(bab.getBuffer(), 0, bab.size());
SpecificDatumReader<DataBlock> reader = new SpecificDatumReader<>(schema);
BinaryDecoder directBinaryDecoder = DecoderFactory.get().directBinaryDecoder(bis, null);
DataBlock read = reader.read(null, directBinaryDecoder);
Assert.assertEquals(read, data);
}
}
Aggregations