public void close() { reader.close(); } }
public MappedBuffer(RandomAccessReader file) { this(file.getChannel(), 30); }
public long bytesRemaining() { return length() - getFilePointer(); }
/** * Read data from file starting from current currentOffset to populate buffer. */ public void reBuffer() { if (isEOF()) return; reBufferAt(current()); }
@SuppressWarnings("resource") public SyncSegment nextSegment(final int startPosition, final int nextSectionStartPosition) throws IOException { reader.seek(startPosition); int uncompressedLength = reader.readInt(); int compressedLength = nextSectionStartPosition - (int)reader.getPosition(); if (compressedLength > compressedBuffer.length) compressedBuffer = new byte[(int) (1.2 * compressedLength)]; reader.readFully(compressedBuffer, 0, compressedLength); if (uncompressedLength > uncompressedBuffer.length) uncompressedBuffer = new byte[(int) (1.2 * uncompressedLength)]; int count = compressor.uncompress(compressedBuffer, 0, compressedLength, uncompressedBuffer, 0); nextLogicalStart += SYNC_MARKER_SIZE; FileDataInput input = new FileSegmentInputStream(ByteBuffer.wrap(uncompressedBuffer, 0, count), reader.getPath(), nextLogicalStart); nextLogicalStart += uncompressedLength; return new SyncSegment(input, startPosition, nextSectionStartPosition, (int)nextLogicalStart, tolerateSegmentErrors(nextSectionStartPosition, reader.length())); } }
desc.version, desc.getMessagingVersion()); RandomAccessReader reader = RandomAccessReader.open(new File(file.getAbsolutePath())); assert reader.length() <= Integer.MAX_VALUE; int offset = getStartOffset(segmentId, desc.version); if (offset < 0) reader.seek(offset); while (reader.getPosition() < end && !reader.isEOF()) logger.debug("Reading mutation at {}", reader.getFilePointer()); serializedSize = reader.readInt(); if (serializedSize == LEGACY_END_OF_SEGMENT_MARKER) logger.debug("Encountered end of segment marker at {}", reader.getFilePointer()); break main; claimedSizeChecksum = reader.readLong(); else claimedSizeChecksum = reader.readInt() & 0xffffffffL; checksum.reset(); if (desc.version < CommitLogDescriptor.VERSION_20) reader.readFully(buffer, 0, serializedSize); if (desc.version < CommitLogDescriptor.VERSION_21) claimedCRC32 = reader.readLong();
while (true) int nextByte = read(); switch (nextByte) if (foundTerminator) seek(unreadPosition); return line.toString(); unreadPosition = getPosition(); break; case (byte) '\n': if (foundTerminator) seek(unreadPosition); return line.toString();
@SuppressWarnings("resource") public SyncSegment nextSegment(int startPosition, int nextSectionStartPosition) throws IOException { int totalPlainTextLength = reader.readInt(); currentSegmentEndPosition = nextSectionStartPosition - 1; nextLogicalStart += SYNC_MARKER_SIZE; FileDataInput input = new EncryptedFileSegmentInputStream(reader.getPath(), nextLogicalStart, 0, totalPlainTextLength, chunkProvider); nextLogicalStart += totalPlainTextLength; return new SyncSegment(input, startPosition, nextSectionStartPosition, (int)nextLogicalStart, tolerateSegmentErrors(nextSectionStartPosition, reader.length())); } }
@Override public void seek(long newPosition) { if (newPosition < 0) throw new IllegalArgumentException("new position should not be negative"); if (buffer == null) throw new IllegalStateException("Attempted to seek in a closed RAR"); long bufferOffset = bufferHolder.offset(); if (newPosition >= bufferOffset && newPosition < bufferOffset + buffer.limit()) { buffer.position((int) (newPosition - bufferOffset)); return; } if (newPosition > length()) throw new IllegalArgumentException(String.format("Unable to seek to position %d in %s (%d bytes) in read-only mode", newPosition, getPath(), length())); reBufferAt(newPosition); }
private void maybeInit() { if (in == null) in = RandomAccessReader.open(path); }
@Override // -1 will be returned if there is nothing to read; higher-level methods like readInt // or readFully (from RandomAccessFile) will throw EOFException but this should not public int read(byte[] buff, int offset, int length) { if (buffer == null) throw new AssertionError("Attempted to read from closed RAR"); if (length == 0) return 0; if (isEOF()) return -1; if (current >= bufferOffset + buffer.length || validBufferBytes == -1) reBuffer(); assert current >= bufferOffset && current < bufferOffset + validBufferBytes : String.format("File (%s), current offset %d, buffer offset %d, buffer limit %d", getPath(), current, bufferOffset, validBufferBytes); int toCopy = Math.min(length, validBufferBytes - bufferCursor()); System.arraycopy(buffer, bufferCursor(), buff, offset, toCopy); current += toCopy; return toCopy; }
public CompressedSegmenter(ICompressor compressor, RandomAccessReader reader) { this.compressor = compressor; this.reader = reader; compressedBuffer = new byte[0]; uncompressedBuffer = new byte[0]; nextLogicalStart = reader.getFilePointer(); }
@Override public void seek(long newPosition) { if (newPosition < 0) throw new IllegalArgumentException("new position should not be negative"); if (newPosition > length()) // it is save to call length() in read-only mode throw new IllegalArgumentException(String.format("unable to seek to position %d in %s (%d bytes) in read-only mode", newPosition, getPath(), length())); current = newPosition; if (newPosition > (bufferOffset + validBufferBytes) || newPosition < bufferOffset) reBuffer(); }
private boolean indexAvailable() { return indexFile != null && !indexFile.isEOF(); }
private static RandomAccessReader open(File file, int bufferSize, long overrideSize, PoolingSegmentedFile owner) { try { return new RandomAccessReader(file, bufferSize, overrideSize, owner); } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
/** * Used to iterate through the columns of a row. * @param sstable SSTable we are reading ffrom. * @param file Reading using this file. * @param key Key of this row. * @param dataSize length of row data * @param checkData if true, do its best to deserialize and check the coherence of row data */ public SSTableIdentityIterator(SSTableReader sstable, RandomAccessReader file, DecoratedKey key, long dataSize, boolean checkData) { this(sstable.metadata, file, file.getPath(), key, dataSize, checkData, sstable, ColumnSerializer.Flag.LOCAL); }
public ChecksumValidator(Descriptor descriptor) throws IOException { this.descriptor = descriptor; checksum = descriptor.version.hasAllAdlerChecksums ? new Adler32() : new PureJavaCrc32(); reader = RandomAccessReader.open(new File(descriptor.filenameFor(Component.CRC))); chunkSize = reader.readInt(); }