@SuppressWarnings("CheckReturnValue") // it doesn't matter what processBytes returns here @Override public <T> T read(ByteProcessor<T> processor) throws IOException { processor.processBytes(bytes, offset, length); return processor.getResult(); }
/** * Process the bytes of the given input stream using the given processor. * * @param input the input stream to process * @param processor the object to which to pass the bytes of the stream * @return the result of the byte processor * @throws IOException if an I/O error occurs * @since 14.0 */ @CanIgnoreReturnValue // some processors won't return a useful result public static <T> T readBytes(InputStream input, ByteProcessor<T> processor) throws IOException { checkNotNull(input); checkNotNull(processor); byte[] buf = createBuffer(); int read; do { read = input.read(buf); } while (read != -1 && processor.processBytes(buf, 0, read)); return processor.getResult(); }