13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)/*
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * Copyright (C) 2009 The Guava Authors
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License");
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) * you may not use this file except in compliance with the License.
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * You may obtain a copy of the License at
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
85f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) * http://www.apache.org/licenses/LICENSE-2.0
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) * Unless required by applicable law or agreed to in writing, software
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS,
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * See the License for the specific language governing permissions and
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) * limitations under the License.
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) */
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)package com.google.common.io;
183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)import com.google.common.annotations.Beta;
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)import java.io.IOException;
223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
23f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)/**
24b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) * A callback interface to process bytes from a stream.
25c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch *
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * <p>{@link #processBytes} will be called for each line that is read, and
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * should return {@code false} when you want to stop processing.
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @author Chris Nokleberg
300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * @since 1.0
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch@Beta
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochpublic interface ByteProcessor<T> {
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  /**
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * This method will be called for each chunk of bytes in an
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * input stream. The implementation should process the bytes
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * from {@code buf[off]} through {@code buf[off + len - 1]}
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * (inclusive).
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   *
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * @param buf the byte array containing the data to process
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * @param off the initial offset into the array
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * @param len the length of data to be processed
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   * @return true to continue processing, false to stop
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)   */
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  boolean processBytes(byte[] buf, int off, int len) throws IOException;
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  /** Return the result of processing all the bytes. */
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  T getResult();
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch