private static void writeBinary(final Stream<Record> records, final File file)
throws IOException {
final String base = file.getAbsolutePath();
final Dictionary<URI> dictionary = Dictionary.createLocalDictionary(URI.class, new File(
base + ".dict"));
final Serializer serializer = new Serializer(false, dictionary, Statements.VALUE_FACTORY);
final CountingOutputStream stream = new CountingOutputStream(IO.write(base + ".gz"));
try {
records.toHandler(new Handler<Record>() {
private int records = 0;
@Override
public void handle(final Record record) throws Throwable {
if (record == null || this.records > 0 && this.records % 1000 == 0) {
LOGGER.info("{} records, {} bytes processed ({} bytes/record)",
this.records, stream.getCount(), stream.getCount() / this.records);
}
if (record != null) {
serializer.toStream(stream, record);
++this.records;
}
}
});
} finally {
IO.closeQuietly(records);
IO.closeQuietly(stream);
}
}