Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions

An output engine that copies data from a Reader through a OutputStreamWriter 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 ReaderWriterEngine implements OutputEngine {
  private static final int DEFAULT_BUFFER_SIZE = 8192;
  private Reader reader;
  private String encoding;
  private char[] buffer;
  private Writer writer;
  public ReaderWriterEngine (Reader inString encoding) {
    this (inencoding);
  public ReaderWriterEngine (Reader readerString encodingint bufferSize) {
    this. = reader;
    this. = encoding;
     = new char[bufferSize];
  public void initialize (OutputStream outthrows IOException {
    if ( != null) {
      throw new IOException ("Already initialized");
    } else {
       = new OutputStreamWriter (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 ();
New to GrepCode? Check out our FAQ X