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); } }
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); }