jaroslav@601: /* jaroslav@601: * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved. jaroslav@601: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@601: * jaroslav@601: * This code is free software; you can redistribute it and/or modify it jaroslav@601: * under the terms of the GNU General Public License version 2 only, as jaroslav@601: * published by the Free Software Foundation. Oracle designates this jaroslav@601: * particular file as subject to the "Classpath" exception as provided jaroslav@601: * by Oracle in the LICENSE file that accompanied this code. jaroslav@601: * jaroslav@601: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@601: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@601: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@601: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@601: * accompanied this code). jaroslav@601: * jaroslav@601: * You should have received a copy of the GNU General Public License version jaroslav@601: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@601: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@601: * jaroslav@601: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@601: * or visit www.oracle.com if you need additional information or have any jaroslav@601: * questions. jaroslav@601: */ jaroslav@601: jaroslav@601: package java.io; jaroslav@601: jaroslav@601: /** jaroslav@601: * This abstract class is the superclass of all classes representing jaroslav@601: * an output stream of bytes. An output stream accepts output bytes jaroslav@601: * and sends them to some sink. jaroslav@601: *

jaroslav@601: * Applications that need to define a subclass of jaroslav@601: * OutputStream must always provide at least a method jaroslav@601: * that writes one byte of output. jaroslav@601: * jaroslav@601: * @author Arthur van Hoff jaroslav@601: * @see java.io.BufferedOutputStream jaroslav@601: * @see java.io.ByteArrayOutputStream jaroslav@601: * @see java.io.DataOutputStream jaroslav@601: * @see java.io.FilterOutputStream jaroslav@601: * @see java.io.InputStream jaroslav@601: * @see java.io.OutputStream#write(int) jaroslav@601: * @since JDK1.0 jaroslav@601: */ jaroslav@601: public abstract class OutputStream implements Closeable, Flushable { jaroslav@601: /** jaroslav@601: * Writes the specified byte to this output stream. The general jaroslav@601: * contract for write is that one byte is written jaroslav@601: * to the output stream. The byte to be written is the eight jaroslav@601: * low-order bits of the argument b. The 24 jaroslav@601: * high-order bits of b are ignored. jaroslav@601: *

jaroslav@601: * Subclasses of OutputStream must provide an jaroslav@601: * implementation for this method. jaroslav@601: * jaroslav@601: * @param b the byte. jaroslav@601: * @exception IOException if an I/O error occurs. In particular, jaroslav@601: * an IOException may be thrown if the jaroslav@601: * output stream has been closed. jaroslav@601: */ jaroslav@601: public abstract void write(int b) throws IOException; jaroslav@601: jaroslav@601: /** jaroslav@601: * Writes b.length bytes from the specified byte array jaroslav@601: * to this output stream. The general contract for write(b) jaroslav@601: * is that it should have exactly the same effect as the call jaroslav@601: * write(b, 0, b.length). jaroslav@601: * jaroslav@601: * @param b the data. jaroslav@601: * @exception IOException if an I/O error occurs. jaroslav@601: * @see java.io.OutputStream#write(byte[], int, int) jaroslav@601: */ jaroslav@601: public void write(byte b[]) throws IOException { jaroslav@601: write(b, 0, b.length); jaroslav@601: } jaroslav@601: jaroslav@601: /** jaroslav@601: * Writes len bytes from the specified byte array jaroslav@601: * starting at offset off to this output stream. jaroslav@601: * The general contract for write(b, off, len) is that jaroslav@601: * some of the bytes in the array b are written to the jaroslav@601: * output stream in order; element b[off] is the first jaroslav@601: * byte written and b[off+len-1] is the last byte written jaroslav@601: * by this operation. jaroslav@601: *

jaroslav@601: * The write method of OutputStream calls jaroslav@601: * the write method of one argument on each of the bytes to be jaroslav@601: * written out. Subclasses are encouraged to override this method and jaroslav@601: * provide a more efficient implementation. jaroslav@601: *

jaroslav@601: * If b is null, a jaroslav@601: * NullPointerException is thrown. jaroslav@601: *

jaroslav@601: * If off is negative, or len is negative, or jaroslav@601: * off+len is greater than the length of the array jaroslav@601: * b, then an IndexOutOfBoundsException is thrown. jaroslav@601: * jaroslav@601: * @param b the data. jaroslav@601: * @param off the start offset in the data. jaroslav@601: * @param len the number of bytes to write. jaroslav@601: * @exception IOException if an I/O error occurs. In particular, jaroslav@601: * an IOException is thrown if the output jaroslav@601: * stream is closed. jaroslav@601: */ jaroslav@601: public void write(byte b[], int off, int len) throws IOException { jaroslav@601: if (b == null) { jaroslav@601: throw new NullPointerException(); jaroslav@601: } else if ((off < 0) || (off > b.length) || (len < 0) || jaroslav@601: ((off + len) > b.length) || ((off + len) < 0)) { jaroslav@601: throw new IndexOutOfBoundsException(); jaroslav@601: } else if (len == 0) { jaroslav@601: return; jaroslav@601: } jaroslav@601: for (int i = 0 ; i < len ; i++) { jaroslav@601: write(b[off + i]); jaroslav@601: } jaroslav@601: } jaroslav@601: jaroslav@601: /** jaroslav@601: * Flushes this output stream and forces any buffered output bytes jaroslav@601: * to be written out. The general contract of flush is jaroslav@601: * that calling it is an indication that, if any bytes previously jaroslav@601: * written have been buffered by the implementation of the output jaroslav@601: * stream, such bytes should immediately be written to their jaroslav@601: * intended destination. jaroslav@601: *

jaroslav@601: * If the intended destination of this stream is an abstraction provided by jaroslav@601: * the underlying operating system, for example a file, then flushing the jaroslav@601: * stream guarantees only that bytes previously written to the stream are jaroslav@601: * passed to the operating system for writing; it does not guarantee that jaroslav@601: * they are actually written to a physical device such as a disk drive. jaroslav@601: *

jaroslav@601: * The flush method of OutputStream does nothing. jaroslav@601: * jaroslav@601: * @exception IOException if an I/O error occurs. jaroslav@601: */ jaroslav@601: public void flush() throws IOException { jaroslav@601: } jaroslav@601: jaroslav@601: /** jaroslav@601: * Closes this output stream and releases any system resources jaroslav@601: * associated with this stream. The general contract of close jaroslav@601: * is that it closes the output stream. A closed stream cannot perform jaroslav@601: * output operations and cannot be reopened. jaroslav@601: *

jaroslav@601: * The close method of OutputStream does nothing. jaroslav@601: * jaroslav@601: * @exception IOException if an I/O error occurs. jaroslav@601: */ jaroslav@601: public void close() throws IOException { jaroslav@601: } jaroslav@601: jaroslav@601: }