@Override public void writeFixed(ByteBuffer bytes) throws IOException { ByteBuffer readOnlyBytes = bytes.asReadOnlyBuffer(); if (!bytes.hasArray() && bytes.remaining() > bulkLimit) { flushBuffer(); sink.innerWrite(readOnlyBytes); // bypass the readOnlyBytes } else { super.writeFixed(readOnlyBytes); } }
@Override public void writeBytes(ByteBuffer bytes) throws IOException { int len = bytes.limit() - bytes.position(); if (0 == len) { writeZero(); } else { writeInt(len); writeFixed(bytes); } }
@Override public void writeFixed(ByteBuffer bytes) throws IOException { if (!bytes.hasArray() && bytes.remaining() > bulkLimit) { flushBuffer(); sink.innerWrite(bytes); // bypass the buffer } else { super.writeFixed(bytes); } }
void writeBlockTo(BinaryEncoder e, byte[] sync) throws IOException { e.writeLong(this.numEntries); e.writeLong(this.blockSize); e.writeFixed(this.data, offset, this.blockSize); e.writeFixed(sync); if (flushOnWrite) { e.flush(); } }
@Override public void writeString(String string) throws IOException { if (0 == string.length()) { writeZero(); return; } byte[] bytes = string.getBytes("UTF-8"); writeInt(bytes.length); writeFixed(bytes, 0, bytes.length); }
@Override public void writeBytes(ByteBuffer bytes) throws IOException { int len = bytes.limit() - bytes.position(); if (0 == len) { writeZero(); } else { writeInt(len); writeFixed(bytes); } }
void writeBlockTo(BinaryEncoder e, byte[] sync) throws IOException { e.writeLong(this.numEntries); e.writeLong(this.blockSize); e.writeFixed(this.data, offset, this.blockSize); e.writeFixed(sync); if (flushOnWrite) { e.flush(); } }
@Override public void writeString(String string) throws IOException { if (0 == string.length()) { writeZero(); return; } byte[] bytes = string.getBytes("UTF-8"); writeInt(bytes.length); writeFixed(bytes, 0, bytes.length); }
@Override public void writeBytes(byte[] bytes, int start, int len) throws IOException { if (0 == len) { writeZero(); return; } this.writeInt(len); this.writeFixed(bytes, start, len); }
/** Expert: Append a pre-encoded datum to the file. No validation is * performed to check that the encoding conforms to the file's schema. * Appending non-conforming data may result in an unreadable file. */ public void appendEncoded(ByteBuffer datum) throws IOException { assertOpen(); bufOut.writeFixed(datum); blockCount++; writeIfBlockFull(); }
@Override public void writeBytes(byte[] bytes, int start, int len) throws IOException { if (0 == len) { writeZero(); return; } this.writeInt(len); this.writeFixed(bytes, start, len); }
/** Expert: Append a pre-encoded datum to the file. No validation is * performed to check that the encoding conforms to the file's schema. * Appending non-conforming data may result in an unreadable file. */ public void appendEncoded(ByteBuffer datum) throws IOException { assertOpen(); bufOut.writeFixed(datum); blockCount++; writeIfBlockFull(); }
/** Open a new file for data matching a schema with an explicit sync. */ public DataFileWriter<D> create(Schema schema, OutputStream outs, byte[] sync) throws IOException { assertNotOpen(); this.schema = schema; setMetaInternal(DataFileConstants.SCHEMA, schema.toString()); if (sync == null ) { this.sync = generateSync(); } else if (sync.length == 16) { this.sync = sync; } else { throw new IOException("sync must be exactly 16 bytes"); } init(outs); vout.writeFixed(DataFileConstants.MAGIC); // write magic vout.writeMapStart(); // write metadata vout.setItemCount(meta.size()); for (Map.Entry<String,byte[]> entry : meta.entrySet()) { vout.startItem(); vout.writeString(entry.getKey()); vout.writeBytes(entry.getValue()); } vout.writeMapEnd(); vout.writeFixed(this.sync); // write initial sync vout.flush(); //vout may be buffered, flush before writing to out return this; }
/** Open a new file for data matching a schema with an explicit sync. */ public DataFileWriter<D> create(Schema schema, OutputStream outs, byte[] sync) throws IOException { assertNotOpen(); this.schema = schema; setMetaInternal(DataFileConstants.SCHEMA, schema.toString()); if (sync == null ) { this.sync = generateSync(); } else if (sync.length == 16) { this.sync = sync; } else { throw new IOException("sync must be exactly 16 bytes"); } init(outs); vout.writeFixed(DataFileConstants.MAGIC); // write magic vout.writeMapStart(); // write metadata vout.setItemCount(meta.size()); for (Map.Entry<String,byte[]> entry : meta.entrySet()) { vout.startItem(); vout.writeString(entry.getKey()); vout.writeBytes(entry.getValue()); } vout.writeMapEnd(); vout.writeFixed(this.sync); // write initial sync vout.flush(); //vout may be buffered, flush before writing to out return this; }
@Override public void writeFixed(byte[] bytes, int start, int len) throws IOException { wrappedEncoder.writeFixed(bytes, start, len); }
@Override public void writeBytes(ByteBuffer bytes) throws IOException { int len = bytes.limit() - bytes.position(); if (0 == len) { writeZero(); } else { writeInt(len); writeFixed(bytes); } }
void writeBlockTo(BinaryEncoder e, byte[] sync) throws IOException { e.writeLong(this.numEntries); e.writeLong(this.blockSize); e.writeFixed(this.data, offset, this.blockSize); e.writeFixed(sync); e.flush(); }
@Override public void writeFixed(ByteBuffer bytes) throws IOException { if (!bytes.hasArray() && bytes.remaining() > bulkLimit) { flushBuffer(); sink.innerWrite(bytes); // bypass the buffer } else { super.writeFixed(bytes); } }
/** Expert: Append a pre-encoded datum to the file. No validation is * performed to check that the encoding conforms to the file's schema. * Appending non-conforming data may result in an unreadable file. */ public void appendEncoded(ByteBuffer datum) throws IOException { assertOpen(); bufOut.writeFixed(datum); blockCount++; writeIfBlockFull(); }
/** * Do the serialization of the {@link PersistentBase} object * * @param persistent {@link PersistentBase} object to serialize * @throws IOException if there is an error during serialization */ @Override public void serialize(PersistentBase persistent) throws IOException { datumWriter.setSchema(persistent.getSchema()); datumWriter.write(persistent, encoder); encoder.writeFixed(persistent.getDirtyBytes().array()); } }