/** * Appends data to the rolling buffer. * * @param buffer A buffer containing the data to append. * @param length The length of the data to append. */ public void appendData(ParsableByteArray buffer, int length) { while (length > 0) { int thisAppendLength = prepareForAppend(length); buffer.readBytes(lastAllocation.data, lastAllocation.translateOffset(lastAllocationOffset), thisAppendLength); lastAllocationOffset += thisAppendLength; totalBytesWritten += thisAppendLength; length -= thisAppendLength; } }
/** * Appends data to the rolling buffer. * * @param dataSource The source from which to read. * @param length The maximum length of the read. * @param allowEndOfInput True if encountering the end of the input having appended no data is * allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it * should be considered an error, causing an {@link EOFException} to be thrown. * @return The number of bytes appended, or {@link C#RESULT_END_OF_INPUT} if the input has ended. * @throws IOException If an error occurs reading from the source. */ public int appendData(DataSource dataSource, int length, boolean allowEndOfInput) throws IOException { length = prepareForAppend(length); int bytesAppended = dataSource.read(lastAllocation.data, lastAllocation.translateOffset(lastAllocationOffset), length); if (bytesAppended == C.RESULT_END_OF_INPUT) { if (allowEndOfInput) { return C.RESULT_END_OF_INPUT; } throw new EOFException(); } lastAllocationOffset += bytesAppended; totalBytesWritten += bytesAppended; return bytesAppended; }
/** * Appends data to the rolling buffer. * * @param input The source from which to read. * @param length The maximum length of the read. * @param allowEndOfInput True if encountering the end of the input having appended no data is * allowed, and should result in {@link C#RESULT_END_OF_INPUT} being returned. False if it * should be considered an error, causing an {@link EOFException} to be thrown. * @return The number of bytes appended, or {@link C#RESULT_END_OF_INPUT} if the input has ended. * @throws IOException If an error occurs reading from the source. * @throws InterruptedException If the thread has been interrupted. */ public int appendData(ExtractorInput input, int length, boolean allowEndOfInput) throws IOException, InterruptedException { length = prepareForAppend(length); int bytesAppended = input.read(lastAllocation.data, lastAllocation.translateOffset(lastAllocationOffset), length); if (bytesAppended == C.RESULT_END_OF_INPUT) { if (allowEndOfInput) { return C.RESULT_END_OF_INPUT; } throw new EOFException(); } lastAllocationOffset += bytesAppended; totalBytesWritten += bytesAppended; return bytesAppended; }