001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package java.io;
028:
029: /**
030: * This abstract class is the superclass of all classes representing
031: * an output stream of bytes. An output stream accepts output bytes
032: * and sends them to some sink.
033: * <p>
034: * Applications that need to define a subclass of
035: * <code>OutputStream</code> must always provide at least a method
036: * that writes one byte of output.
037: *
038: * @version 12/17/01 (CLDC 1.1)
039: * @see java.io.ByteArrayOutputStream
040: * @see java.io.DataOutputStream
041: * @see java.io.InputStream
042: * @see java.io.OutputStream#write(int)
043: * @since JDK1.0, CLDC 1.0
044: */
045: public abstract class OutputStream {
046:
047: /**
048: * Writes the specified byte to this output stream. The general
049: * contract for <code>write</code> is that one byte is written
050: * to the output stream. The byte to be written is the eight
051: * low-order bits of the argument <code>b</code>. The 24
052: * high-order bits of <code>b</code> are ignored.
053: * <p>
054: * Subclasses of <code>OutputStream</code> must provide an
055: * implementation for this method.
056: *
057: * @param b the <code>byte</code>.
058: * @exception IOException if an I/O error occurs. In particular,
059: * an <code>IOException</code> may be thrown if the
060: * output stream has been closed.
061: */
062: public abstract void write(int b) throws IOException;
063:
064: /**
065: * Writes <code>b.length</code> bytes from the specified byte array
066: * to this output stream. The general contract for <code>write(b)</code>
067: * is that it should have exactly the same effect as the call
068: * <code>write(b, 0, b.length)</code>.
069: *
070: * @param b the data.
071: * @exception IOException if an I/O error occurs.
072: * @see java.io.OutputStream#write(byte[], int, int)
073: */
074: public void write(byte b[]) throws IOException {
075: write(b, 0, b.length);
076: }
077:
078: /**
079: * Writes <code>len</code> bytes from the specified byte array
080: * starting at offset <code>off</code> to this output stream.
081: * The general contract for <code>write(b, off, len)</code> is that
082: * some of the bytes in the array <code>b</code> are written to the
083: * output stream in order; element <code>b[off]</code> is the first
084: * byte written and <code>b[off+len-1]</code> is the last byte written
085: * by this operation.
086: * <p>
087: * The <code>write</code> method of <code>OutputStream</code> calls
088: * the write method of one argument on each of the bytes to be
089: * written out. Subclasses are encouraged to override this method and
090: * provide a more efficient implementation.
091: * <p>
092: * If <code>b</code> is <code>null</code>, a
093: * <code>NullPointerException</code> is thrown.
094: * <p>
095: * If <code>off</code> is negative, or <code>len</code> is negative, or
096: * <code>off+len</code> is greater than the length of the array
097: * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
098: *
099: * @param b the data.
100: * @param off the start offset in the data.
101: * @param len the number of bytes to write.
102: * @exception IOException if an I/O error occurs. In particular,
103: * an <code>IOException</code> is thrown if the output
104: * stream is closed.
105: */
106: public void write(byte b[], int off, int len) throws IOException {
107: if (b == null) {
108: throw new NullPointerException();
109: } else if ((off < 0) || (off > b.length) || (len < 0)
110: || ((off + len) > b.length) || ((off + len) < 0)) {
111: throw new IndexOutOfBoundsException();
112: } else if (len == 0) {
113: return;
114: }
115: for (int i = 0; i < len; i++) {
116: write(b[off + i]);
117: }
118: }
119:
120: /**
121: * Flushes this output stream and forces any buffered output bytes
122: * to be written out. The general contract of <code>flush</code> is
123: * that calling it is an indication that, if any bytes previously
124: * written have been buffered by the implementation of the output
125: * stream, such bytes should immediately be written to their
126: * intended destination.
127: * <p>
128: * The <code>flush</code> method of <code>OutputStream</code> does nothing.
129: *
130: * @exception IOException if an I/O error occurs.
131: */
132: public void flush() throws IOException {
133: }
134:
135: /**
136: * Closes this output stream and releases any system resources
137: * associated with this stream. The general contract of <code>close</code>
138: * is that it closes the output stream. A closed stream cannot perform
139: * output operations and cannot be reopened.
140: * <p>
141: * The <code>close</code> method of <code>OutputStream</code> does nothing.
142: *
143: * @exception IOException if an I/O error occurs.
144: */
145: public void close() throws IOException {
146: }
147:
148: }
|