DefaultExtractorInput implements ExtractorInput { @Override public int peek(byte[] target, int offset, int length) throws IOException, InterruptedException { ensureSpaceForPeek(length); int peekBufferRemainingBytes = peekBufferLength - peekBufferPosition; int bytesPeeked; if (peekBufferRemainingBytes == 0) { bytesPeeked = readFromDataSource( peekBuffer, peekBufferPosition, length, 0, true); if (bytesPeeked == C.RESULT_END_OF_INPUT) { return C.RESULT_END_OF_INPUT; } peekBufferLength += bytesPeeked; } else { bytesPeeked = Math.min(length, peekBufferRemainingBytes); } System.arraycopy(peekBuffer, peekBufferPosition, target, offset, bytesPeeked); peekBufferPosition += bytesPeeked; return bytesPeeked; } DefaultExtractorInput(DataSource dataSource, long position, long length); @Override int read(byte[] target, int offset, int length); @Override boolean readFully(byte[] target, int offset, int length, boolean allowEndOfInput); @Override void readFully(byte[] target, int offset, int length); @Override int skip(int length); @Override boolean skipFully(int length, boolean allowEndOfInput); @Override void skipFully(int length); @Override int peek(byte[] target, int offset, int length); @Override boolean peekFully(byte[] target, int offset, int length, boolean allowEndOfInput); @Override void peekFully(byte[] target, int offset, int length); @Override boolean advancePeekPosition(int length, boolean allowEndOfInput); @Override void advancePeekPosition(int length); @Override void resetPeekPosition(); @Override long getPeekPosition(); @Override long getPosition(); @Override long getLength(); @Override void setRetryPosition(long position, E e);  }
@Test public void testPeekZeroLength() throws Exception { DefaultExtractorInput input = createDefaultExtractorInput(); byte[] target = new byte[TEST_DATA.length]; int bytesPeeked = input.peek(target, 0, 0); assertThat(bytesPeeked).isEqualTo(0); }