use of org.spf4j.io.MemorizingBufferedInputStream in project spf4j by zolyfarkas.
the class Converter method load.
@Nullable
public static SampleNode load(@WillNotClose final InputStream fis) throws IOException {
try (MemorizingBufferedInputStream bis = new MemorizingBufferedInputStream(fis)) {
final PushbackInputStream pis = new PushbackInputStream(bis);
final SpecificDatumReader<StackSampleElement> reader = new SpecificDatumReader<>(StackSampleElement.getClassSchema());
final BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(pis, null);
return convert(new Iterator<StackSampleElement>() {
@Override
public boolean hasNext() {
try {
int read = pis.read();
pis.unread(read);
return read >= 0;
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
@Override
@SuppressFBWarnings
public StackSampleElement next() {
try {
return reader.read(null, decoder);
} catch (IOException ex) {
NoSuchElementException e = new NoSuchElementException();
e.addSuppressed(ex);
throw e;
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
});
}
}
use of org.spf4j.io.MemorizingBufferedInputStream in project spf4j by zolyfarkas.
the class Converter method load.
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public static SampleNode load(final File file) throws IOException {
try (MemorizingBufferedInputStream bis = new MemorizingBufferedInputStream(Files.newInputStream(file.toPath()))) {
final PushbackInputStream pis = new PushbackInputStream(bis);
final SpecificDatumReader<ASample> reader = new SpecificDatumReader<>(ASample.SCHEMA$);
final BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(pis, null);
return convert(new Iterator<ASample>() {
@Override
public boolean hasNext() {
try {
int read = pis.read();
pis.unread(read);
return read >= 0;
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
@Override
@SuppressFBWarnings
public ASample next() {
try {
return reader.read(null, decoder);
} catch (IOException ex) {
NoSuchElementException e = new NoSuchElementException();
e.addSuppressed(ex);
throw e;
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
});
}
}
use of org.spf4j.io.MemorizingBufferedInputStream in project spf4j by zolyfarkas.
the class TSDBReader method resetStream.
private void resetStream(final long position) throws IOException {
byteChannel.position(position);
bis = new CountingInputStream(new MemorizingBufferedInputStream(Channels.newInputStream(byteChannel), bufferSize), position);
decoder = DecoderFactory.get().directBinaryDecoder(bis, decoder);
}
Aggregations