/** * Writes raw bytes to the buffer without encoding. Same as calling * * {@link #writeRaw(byte[], int, int) writeRaw(rawBytes, 0, rawBytes.length)}. */ public Encoder writeRaw(byte[] rawBytes) throws IOException { return writeRaw(rawBytes, 0, rawBytes.length); }
if (encoder.size() == 0) { if (sync && !synced) { sync(eventOutput); lengthEncoder.writeInt(encoder.size()); int size = lengthEncoder.size(); lengthEncoder.writeTo(eventOutput); position += size; size = encoder.size(); encoder.writeTo(eventOutput); position += size; if (sync) { encoder.writeRaw(Bytes.toBytes(currentTimestamp)); encoder.writeRaw(Bytes.toBytes(indexOffset)); encoder.writeTo(indexOutput); if (sync) { sync(indexOutput);
private void init(Map<String, String> properties) throws IOException { // Writes the header for event file encoder.writeRaw(StreamDataFileConstants.MAGIC_HEADER_V2); Map<String, String> headers = Maps.newHashMap(properties); headers.put(StreamDataFileConstants.Property.Key.SCHEMA, StreamEventDataCodec.STREAM_DATA_SCHEMA.toString()); StreamUtils.encodeMap(headers, encoder); long headerSize = encoder.size(); encoder.writeTo(eventOutput); sync(eventOutput); position = headerSize; // Writes the header for index file encoder.writeRaw(StreamDataFileConstants.INDEX_MAGIC_HEADER_V1); // Empty properties map for now. May have properties in future version. StreamUtils.encodeMap(ImmutableMap.<String, String>of(), encoder); encoder.writeTo(indexOutput); sync(indexOutput); }
this.encoder = new BufferedEncoder(BUFFER_SIZE, encoderFactory); this.lengthEncoder = new BufferedEncoder(5, encoderFactory);
private void doAppend(StreamEvent event, int flushLimit) throws IOException { if (closed) { throw new IOException("Writer already closed."); } synced = false; long eventTimestamp = event.getTimestamp(); if (eventTimestamp < currentTimestamp) { throw closeWithException(new IOException("Out of order events written.")); } try { if (eventTimestamp > currentTimestamp) { flushBlock(false); currentTimestamp = eventTimestamp; // Write the timestamp directly to output eventOutput.write(Bytes.toBytes(currentTimestamp)); position += Bytes.SIZEOF_LONG; } // Encodes the event data into buffer. StreamEventDataCodec.encode(event, encoder); // Optionally flush if already filled up the buffer. if (encoder.size() >= flushLimit) { flushBlock(false); } } catch (IOException e) { throw closeWithException(e); } }
/** * Writes raw bytes to the buffer without encoding. Same as calling * * {@link #writeRaw(byte[], int, int) writeRaw(rawBytes, 0, rawBytes.length)}. */ public Encoder writeRaw(byte[] rawBytes) throws IOException { return writeRaw(rawBytes, 0, rawBytes.length); }