| 1 |
771 |
jeremybenn |
/* OutputStream.java -- Base class for byte output streams
|
| 2 |
|
|
Copyright (C) 1998, 1999, 2001, 2004, 2005 Free Software Foundation, Inc.
|
| 3 |
|
|
|
| 4 |
|
|
This file is part of GNU Classpath.
|
| 5 |
|
|
|
| 6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
| 7 |
|
|
it under the terms of the GNU General Public License as published by
|
| 8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
| 9 |
|
|
any later version.
|
| 10 |
|
|
|
| 11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
| 12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 14 |
|
|
General Public License for more details.
|
| 15 |
|
|
|
| 16 |
|
|
You should have received a copy of the GNU General Public License
|
| 17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
| 18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
| 19 |
|
|
02110-1301 USA.
|
| 20 |
|
|
|
| 21 |
|
|
Linking this library statically or dynamically with other modules is
|
| 22 |
|
|
making a combined work based on this library. Thus, the terms and
|
| 23 |
|
|
conditions of the GNU General Public License cover the whole
|
| 24 |
|
|
combination.
|
| 25 |
|
|
|
| 26 |
|
|
As a special exception, the copyright holders of this library give you
|
| 27 |
|
|
permission to link this library with independent modules to produce an
|
| 28 |
|
|
executable, regardless of the license terms of these independent
|
| 29 |
|
|
modules, and to copy and distribute the resulting executable under
|
| 30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
| 31 |
|
|
independent module, the terms and conditions of the license of that
|
| 32 |
|
|
module. An independent module is a module which is not derived from
|
| 33 |
|
|
or based on this library. If you modify this library, you may extend
|
| 34 |
|
|
this exception to your version of the library, but you are not
|
| 35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
| 36 |
|
|
exception statement from your version. */
|
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
package java.io;
|
| 40 |
|
|
|
| 41 |
|
|
/**
|
| 42 |
|
|
* This abstract class forms the base of the hierarchy of classes that
|
| 43 |
|
|
* write output as a stream of bytes. It provides a common set of methods
|
| 44 |
|
|
* for writing bytes to stream. Subclasses implement and/or extend these
|
| 45 |
|
|
* methods to write bytes in a particular manner or to a particular
|
| 46 |
|
|
* destination such as a file on disk or network connection.
|
| 47 |
|
|
*
|
| 48 |
|
|
* @author Aaron M. Renn (arenn@urbanophile.com)
|
| 49 |
|
|
* @author Tom Tromey (tromey@cygnus.com)
|
| 50 |
|
|
*/
|
| 51 |
|
|
public abstract class OutputStream implements Closeable, Flushable
|
| 52 |
|
|
{
|
| 53 |
|
|
/**
|
| 54 |
|
|
* This is the default no-argument constructor for this class. This method
|
| 55 |
|
|
* does nothing in this class.
|
| 56 |
|
|
*/
|
| 57 |
|
|
public OutputStream ()
|
| 58 |
|
|
{
|
| 59 |
|
|
}
|
| 60 |
|
|
|
| 61 |
|
|
/**
|
| 62 |
|
|
* This method writes a single byte to the output stream. The byte written
|
| 63 |
|
|
* is the low eight bits of the <code>int</code> passed and a argument.
|
| 64 |
|
|
* <p>
|
| 65 |
|
|
* Subclasses must provide an implementation of this abstract method
|
| 66 |
|
|
*
|
| 67 |
|
|
* @param b The byte to be written to the output stream, passed as
|
| 68 |
|
|
* the low eight bits of an <code>int</code>
|
| 69 |
|
|
*
|
| 70 |
|
|
* @exception IOException If an error occurs
|
| 71 |
|
|
*/
|
| 72 |
|
|
public abstract void write (int b) throws IOException;
|
| 73 |
|
|
|
| 74 |
|
|
/**
|
| 75 |
|
|
* This method all the writes bytes from the passed array to the
|
| 76 |
|
|
* output stream. This method is equivalent to <code>write(b, 0,
|
| 77 |
|
|
* buf.length)</code> which is exactly how it is implemented in this
|
| 78 |
|
|
* class.
|
| 79 |
|
|
*
|
| 80 |
|
|
* @param b The array of bytes to write
|
| 81 |
|
|
*
|
| 82 |
|
|
* @exception IOException If an error occurs
|
| 83 |
|
|
*/
|
| 84 |
|
|
public void write (byte[] b) throws IOException, NullPointerException
|
| 85 |
|
|
{
|
| 86 |
|
|
write (b, 0, b.length);
|
| 87 |
|
|
}
|
| 88 |
|
|
|
| 89 |
|
|
/**
|
| 90 |
|
|
* This method writes <code>len</code> bytes from the specified array
|
| 91 |
|
|
* <code>b</code> starting at index <code>off</code> into the array.
|
| 92 |
|
|
* <p>
|
| 93 |
|
|
* This method in this class calls the single byte <code>write()</code>
|
| 94 |
|
|
* method in a loop until all bytes have been written. Subclasses should
|
| 95 |
|
|
* override this method if possible in order to provide a more efficent
|
| 96 |
|
|
* implementation.
|
| 97 |
|
|
*
|
| 98 |
|
|
* @param b The array of bytes to write from
|
| 99 |
|
|
* @param off The index into the array to start writing from
|
| 100 |
|
|
* @param len The number of bytes to write
|
| 101 |
|
|
*
|
| 102 |
|
|
* @exception IOException If an error occurs
|
| 103 |
|
|
*/
|
| 104 |
|
|
public void write (byte[] b, int off, int len)
|
| 105 |
|
|
throws IOException, NullPointerException, IndexOutOfBoundsException
|
| 106 |
|
|
{
|
| 107 |
|
|
if (off < 0 || len < 0 || off + len > b.length)
|
| 108 |
|
|
throw new ArrayIndexOutOfBoundsException ();
|
| 109 |
|
|
for (int i = 0; i < len; ++i)
|
| 110 |
|
|
write (b[off + i]);
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
|
|
/**
|
| 114 |
|
|
* This method forces any data that may have been buffered to be written
|
| 115 |
|
|
* to the underlying output device. Please note that the host environment
|
| 116 |
|
|
* might perform its own buffering unbeknowst to Java. In that case, a
|
| 117 |
|
|
* write made (for example, to a disk drive) might be cached in OS
|
| 118 |
|
|
* buffers instead of actually being written to disk.
|
| 119 |
|
|
* <p>
|
| 120 |
|
|
* This method in this class does nothing.
|
| 121 |
|
|
*
|
| 122 |
|
|
* @exception IOException If an error occurs
|
| 123 |
|
|
*/
|
| 124 |
|
|
public void flush () throws IOException
|
| 125 |
|
|
{
|
| 126 |
|
|
}
|
| 127 |
|
|
|
| 128 |
|
|
/**
|
| 129 |
|
|
* This method closes the stream. Any internal or native resources
|
| 130 |
|
|
* associated with this stream are freed. Any subsequent attempt to
|
| 131 |
|
|
* access the stream might throw an exception.
|
| 132 |
|
|
* <p>
|
| 133 |
|
|
* This method in this class does nothing.
|
| 134 |
|
|
*
|
| 135 |
|
|
* @exception IOException If an error occurs
|
| 136 |
|
|
*/
|
| 137 |
|
|
public void close () throws IOException
|
| 138 |
|
|
{
|
| 139 |
|
|
}
|
| 140 |
|
|
}
|