/*
* @(#)FilterOutputStream.java 1.16 98/07/01
*
* Copyright 1995-1998 by Sun Microsystems, Inc.,
* 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information
* of Sun Microsystems, Inc. ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with Sun.
*/
package acspg;
import java.io.*;
public
class AsciiOutputStream extends OutputStream {
/**
* The underlying output stream.
*
* @since JDK1.0
*/
protected OutputStream out;
/**
* Creates an output stream filter built on top of the specified
* underlying output stream.
*
* @param out the underlying output stream.
* @since JDK1.0
*/
public AsciiOutputStream(OutputStream out) {
this.out = out;
}
/**
* Writes the specified byte
to this output stream.
*
* The write
method of FilterOutputStream
* calls the write
method of its underlying output stream.
*
* @param b the byte
.
* @exception IOException if an I/O error occurs.
* @since JDK1.0
*/
public void write(int b) throws IOException {
out.write(b);
}
/**
* Writes b.length
bytes to this output stream.
*
* The write
method of FilterOutputStream
* calls its write
method of three arguments with the
* arguments b
, 0
, and
* b.length
.
*
* Note that this method does not call the one-argument
* write
method of its underlying stream with the single
* argument b
.
*
* @param b the data to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#write(byte[], int, int)
* @since JDK1.0
*/
public void write(byte b[]) throws IOException {
write(b, 0, b.length);
}
/**
* Writes len
bytes from the specified
* byte
array starting at offset off
to
* this output stream.
*
* The write
method of FilterOutputStream
* calls the write
method of one argument on each
* byte
to output.
*
* Note that this method does not call the write
method
* of its underlying input stream with the same arguments. Subclasses
* of FilterOutputStream
should provide a more efficient
* implementation of this method.
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#write(int)
* @since JDK1.0
*/
public void write(byte b[], int off, int len) throws IOException {
for (int i = 0 ; i < len ; i++) {
out.write(b[off + i]);
}
}
/**
* Flushes this output stream and forces any buffered output bytes
* to be written out to the stream.
*
* The flush
method of FilterOutputStream
* calls the flush
method of its underlying output stream.
*
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
* @since JDK1.0
*/
public void flush() throws IOException {
out.flush();
}
/**
* Closes this output stream and releases any system resources
* associated with the stream.
*
* The close
method of FilterOutputStream
* calls its flush
method, and then calls the
* close
method of its underlying output stream.
*
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#flush()
* @see java.io.FilterOutputStream#out
* @since JDK1.0
*/
public void close() throws IOException {
try {
flush();
} catch (IOException ignored) {
}
out.close();
}
}