@Override public final int skipBytes(int n) throws IOException { if (n < 0) { throw new IllegalArgumentException(); } int toSkip = Math.min(n, remaining()); this.position += toSkip; return toSkip; }
protected void initializeWithPartialLength(NonSpanningWrapper partial) throws IOException { // copy what we have to the length buffer partial.segment.get(partial.position, this.lengthBuffer, partial.remaining()); }
@Override public boolean hasUnfinishedData() { return this.nonSpanningWrapper.remaining() > 0 || this.spanningWrapper.getNumGatheredBytes() > 0; }
@Override public int read(byte[] b, int off, int len) throws IOException { if (b == null){ throw new NullPointerException("Byte array b cannot be null."); } if (off < 0){ throw new IllegalArgumentException("The offset off cannot be negative."); } if (len < 0){ throw new IllegalArgumentException("The length len cannot be negative."); } int toRead = Math.min(len, remaining()); this.segment.get(this.position, b, off, toRead); this.position += toRead; return toRead; }
int nonSpanningRemaining = this.nonSpanningWrapper.remaining(); target.read(this.nonSpanningWrapper); int remaining = this.nonSpanningWrapper.remaining(); if (remaining > 0) { return DeserializationResult.INTERMEDIATE_RECORD_FROM_BUFFER; this.spanningWrapper.clear(); return (this.nonSpanningWrapper.remaining() == 0) ? DeserializationResult.LAST_RECORD_FROM_BUFFER : DeserializationResult.INTERMEDIATE_RECORD_FROM_BUFFER;
protected void initializeWithPartialRecord(NonSpanningWrapper partial, int nextRecordLength) throws IOException { // set the length and copy what is available to the buffer this.recordLength = nextRecordLength; final int numBytesChunk = partial.remaining(); if (nextRecordLength > THRESHOLD_FOR_SPILLING) { // create a spilling channel and put the data there this.spillingChannel = createSpillingChannel(); ByteBuffer toWrite = partial.segment.wrap(partial.position, numBytesChunk); FileUtils.writeCompletely(spillingChannel, toWrite); } else { // collect in memory ensureBufferCapacity(numBytesChunk); partial.segment.get(partial.position, buffer, 0, numBytesChunk); } this.accumulatedRecordBytes = numBytesChunk; }