use of java.nio.channels.WritableByteChannel in project neo4j by neo4j.
the class PageCacheTest method writableByteChannelMustWriteAllBytesInFile.
@Test(timeout = SHORT_TIMEOUT_MILLIS)
public void writableByteChannelMustWriteAllBytesInFile() throws Exception {
File file = file("a");
configureStandardPageCache();
try (PagedFile pf = pageCache.map(file, filePageSize)) {
try (WritableByteChannel channel = pf.openWritableByteChannel()) {
generateFileWithRecords(channel, recordCount, recordSize);
}
try (ReadableByteChannel channel = pf.openReadableByteChannel()) {
verifyRecordsInFile(channel, recordCount);
}
}
}
use of java.nio.channels.WritableByteChannel in project druid by druid-io.
the class CompressedIndexedIntsBenchmark method serialize.
private static ByteBuffer serialize(WritableSupplier<IndexedInts> writableSupplier) throws IOException {
final ByteBuffer buffer = ByteBuffer.allocateDirect((int) writableSupplier.getSerializedSize());
WritableByteChannel channel = new WritableByteChannel() {
@Override
public int write(ByteBuffer src) throws IOException {
int size = src.remaining();
buffer.put(src);
return size;
}
@Override
public boolean isOpen() {
return true;
}
@Override
public void close() throws IOException {
}
};
writableSupplier.writeToChannel(channel);
buffer.rewind();
return buffer;
}
use of java.nio.channels.WritableByteChannel in project druid by druid-io.
the class CompressedVSizeIndexedBenchmark method serialize.
private static ByteBuffer serialize(WritableSupplier<IndexedMultivalue<IndexedInts>> writableSupplier) throws IOException {
final ByteBuffer buffer = ByteBuffer.allocateDirect((int) writableSupplier.getSerializedSize());
WritableByteChannel channel = new WritableByteChannel() {
@Override
public int write(ByteBuffer src) throws IOException {
int size = src.remaining();
buffer.put(src);
return size;
}
@Override
public boolean isOpen() {
return true;
}
@Override
public void close() throws IOException {
}
};
writableSupplier.writeToChannel(channel);
buffer.rewind();
return buffer;
}
use of java.nio.channels.WritableByteChannel in project druid by druid-io.
the class SerializerUtilsTest method testChannelWritelong.
@Test
public void testChannelWritelong() throws IOException {
final int index = 0;
WritableByteChannel channelOutput = Channels.newChannel(outStream);
serializerUtils.writeLong(channelOutput, longs[index]);
ByteArrayInputStream inputstream = new ByteArrayInputStream(outStream.toByteArray());
channelOutput.close();
inputstream.close();
long expected = serializerUtils.readLong(inputstream);
long actuals = longs[index];
Assert.assertEquals(expected, actuals);
}
use of java.nio.channels.WritableByteChannel in project druid by druid-io.
the class SerializerUtilsTest method testChannelWriteString.
@Test
public void testChannelWriteString() throws IOException {
final int index = 0;
WritableByteChannel channelOutput = Channels.newChannel(outStream);
serializerUtils.writeString(channelOutput, strings[index]);
ByteArrayInputStream inputstream = new ByteArrayInputStream(outStream.toByteArray());
channelOutput.close();
inputstream.close();
String expected = serializerUtils.readString(inputstream);
String actuals = strings[index];
Assert.assertEquals(expected, actuals);
}
Aggregations