Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions

An output engine that copies data from an InputStream through a FilterOutputStream to the target OutputStream.

Copyright (c) 2002 Merlin Hughes <> was released by its author under the Apache License, Version 2.0 (the "License") on 9 April 2008; you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
public class IOStreamEngine implements OutputEngine {
  private static final int DEFAULT_BUFFER_SIZE = 8192;
  private InputStream in;
  private byte[] buffer;
  private OutputStream out;
  public IOStreamEngine (InputStream inOutputStreamFactory factory) {
    this (infactory);
  public IOStreamEngine (InputStream inOutputStreamFactory factoryint bufferSize) {
    this. = in;
    this. = factory;
     = new byte[bufferSize];
  public void initialize (OutputStream outthrows IOException {
    if (this. != null) {
      throw new IOException ("Already initialized");
    } else {
      this. = .getOutputStream (out);
  public void execute () throws IOException {
    if ( == null) {
      throw new IOException ("Not yet initialized");
    } else {
      int amount = .read ();
      if (amount < 0) {
        .close ();
      } else {
        .write (, 0, amount);
  public void finish () throws IOException {
    .close ();
  public static interface OutputStreamFactory {
    public OutputStream getOutputStream (OutputStream outthrows IOException;
New to GrepCode? Check out our FAQ X