@Override public void seek(long p) throws IOException { is.seek(p); }
@Override public void seek(long p) throws IOException { is.seek(p); }
/** * Creates a {@link StreamEvent} that will be used as a template for all events consumable from this reader. */ private StreamEvent createEventTemplate(Map<String, String> properties) throws IOException { long timestamp = -1L; // See if all events in the file are of the same timestamp String uniTimestamp = properties.get(StreamDataFileConstants.Property.Key.UNI_TIMESTAMP); if (StreamDataFileConstants.Property.Value.CLOSE_TIMESTAMP.equals(uniTimestamp)) { // Seek to the end - 8 of the stream to read the close timestamp long pos = eventInput.getPos(); eventInput.seek(eventInput.size() - 8); timestamp = Math.abs(readTimestamp()); eventInput.seek(pos); } else if (uniTimestamp != null) { timestamp = Long.parseLong(uniTimestamp); } // Grab the set of default headers for all events ImmutableMap.Builder<String, String> headers = ImmutableMap.builder(); String prefix = StreamDataFileConstants.Property.Key.EVENT_HEADER_PREFIX; for (Map.Entry<String, String> entry : properties.entrySet()) { if (entry.getKey().startsWith(prefix)) { headers.put(entry.getKey().substring(prefix.length()), entry.getValue()); } } return new StreamEvent(headers.build(), ByteBuffers.EMPTY_BUFFER, timestamp); }
private void initByTime(final long time) throws IOException { // If index is provided, lookup the index find the offset closest to start time. // If no offset is found, starts from the beginning of the events StreamDataFileIndex index = getIndex(); long offset = index == null ? 0 : index.floorPositionByTime(time); if (offset > 0) { eventInput.seek(offset); } skipUntil(new SkipCondition() { @Override public boolean apply(long position, long timestamp) { return timestamp >= time; } }); }
private void initByOffset(final long offset) throws IOException { // If index is provided, lookup the position smaller but closest to the offset. StreamDataFileIndex index = getIndex(); long pos = index == null ? 0 : index.floorPosition(offset); if (pos > 0) { eventInput.seek(pos); } skipUntil(new SkipCondition() { @Override public boolean apply(long position, long timestamp) { return position >= offset; } }); }
/** * Opens and initialize this reader. */ private void doOpen() throws IOException { try { eventInput = eventInputSupplier.getInput(); decoder = new BinaryDecoder(eventInput); // If position is <= 0, the reader is not being used yet, hence needs to initialize. if (position <= 0) { init(); } else { // If position > 0, the reader has already been initialized. // We just need to seek to beginning of a data-block, depending on whether there is event in the buffer if (streamEventBuffer.hasEvent()) { // If there is event in the buffer, we seek to the data block that come after the buffered events // to prepare for the reading of the data block after the current buffered events are fully consumed. eventInput.seek(streamEventBuffer.getEndPosition()); } else { // Otherwise, we seek to the current position, which should be pointing to the beginning of a data block eventInput.seek(position); } } } catch (IOException e) { if (eventInput != null) { eventInput.close(); eventInput = null; } throw e; } }
eventInput.seek(position); initByTime(nextTimestamp); return;