home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / io / OutputStream.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  5.0 KB  |  132 lines

  1. /*
  2.  * @(#)OutputStream.java    1.19 98/03/18
  3.  *
  4.  * Copyright 1994-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17. /**
  18.  * This abstract class is the superclass of all classes representing 
  19.  * an output stream of bytes. An output stream accepts output bytes 
  20.  * and sends them to some sink.
  21.  * <p>
  22.  * Applications that need to define a subclass of 
  23.  * <code>OutputStream</code> must always provide at least a method 
  24.  * that writes one byte of output. 
  25.  *
  26.  * @author  Arthur van Hoff
  27.  * @version 1.19, 03/18/98
  28.  * @see     java.io.BufferedOutputStream
  29.  * @see     java.io.ByteArrayOutputStream
  30.  * @see     java.io.DataOutputStream
  31.  * @see     java.io.FilterOutputStream
  32.  * @see     java.io.InputStream
  33.  * @see     java.io.OutputStream#write(int)
  34.  * @since   JDK1.0
  35.  */
  36. public abstract class OutputStream {
  37.     /**
  38.      * Writes the specified byte to this output stream. The general 
  39.      * contract for <code>write</code> is that one byte is written 
  40.      * to the output stream. The byte to be written is the eight 
  41.      * low-order bits of the argument <code>b</code>. The 24 
  42.      * high-order bits of <code>b</code> are ignored.
  43.      * <p>
  44.      * Subclasses of <code>OutputStream</code> must provide an 
  45.      * implementation for this method. 
  46.      *
  47.      * @param      b   the <code>byte</code>.
  48.      * @exception  IOException  if an I/O error occurs. In particular, 
  49.      *             an <code>IOException</code> may be thrown if the 
  50.      *             output stream has been closed.
  51.      */
  52.     public abstract void write(int b) throws IOException;
  53.  
  54.     /**
  55.      * Writes <code>b.length</code> bytes from the specified byte array 
  56.      * to this output stream. The general contract for <code>write(b)</code> 
  57.      * is that it should have exactly the same effect as the call 
  58.      * <code>write(b, 0, b.length)</code>.
  59.      *
  60.      * @param      b   the data.
  61.      * @exception  IOException  if an I/O error occurs.
  62.      * @see        java.io.OutputStream#write(byte[], int, int)
  63.      */
  64.     public void write(byte b[]) throws IOException {
  65.     write(b, 0, b.length);
  66.     }
  67.  
  68.     /**
  69.      * Writes <code>len</code> bytes from the specified byte array 
  70.      * starting at offset <code>off</code> to this output stream. 
  71.      * The general contract for <code>write(b, off, len)</code> is that 
  72.      * some of the bytes in the array <code>b</code> are written to the 
  73.      * output stream as if one at a time, in order; element 
  74.      * <code>b[off]</code> is the first byte written and 
  75.      * <code>b[off+len-1]</code> is the last byte writeen by this 
  76.      * operation.
  77.      * <p>
  78.      * The <code>write</code> method of <code>OutputStream</code> calls 
  79.      * the write method of one argument on each of the bytes to be 
  80.      * written out. Subclasses are encouraged to override this method and 
  81.      * provide a more efficient implementation. 
  82.      * <p>
  83.      * If <code>b</code> is <code>null</code>, a 
  84.      * <code>NullPointerException</code> is thrown.
  85.      * <p>
  86.      * If <code>off</code> is negative, or <code>len</code> is negative, or 
  87.      * <code>off+len</code> is greater than the length of the array 
  88.      * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
  89.      *
  90.      * @param      b     the data.
  91.      * @param      off   the start offset in the data.
  92.      * @param      len   the number of bytes to write.
  93.      * @exception  IOException  if an I/O error occurs. In particular, 
  94.      *             an <code>IOException</code> is thrown if the output 
  95.      *             stream is closed.
  96.      */
  97.     public void write(byte b[], int off, int len) throws IOException {
  98.     for (int i = 0 ; i < len ; i++) {
  99.         write(b[off + i]);
  100.     }
  101.     }
  102.  
  103.     /**
  104.      * Flushes this output stream and forces any buffered output bytes 
  105.      * to be written out. The general contract of <code>flush</code> is 
  106.      * that calling it is an indication that, if any bytes previously 
  107.      * written have been buffered by the implementation of the output 
  108.      * stream, such bytes should immediately be written to their 
  109.      * intended destination.
  110.      * <p>
  111.      * The <code>flush</code> method of <code>OutputStream</code> does nothing.
  112.      *
  113.      * @exception  IOException  if an I/O error occurs.
  114.      */
  115.     public void flush() throws IOException {
  116.     }
  117.  
  118.     /**
  119.      * Closes this output stream and releases any system resources 
  120.      * associated with this stream. The general contract of <code>close</code> 
  121.      * is that it closes the output stream. A closed stream cannot perform 
  122.      * output operations and cannot be reopened.
  123.      * <p>
  124.      * The <code>close</code> method of <code>OutputStream</code> does nothing.
  125.      *
  126.      * @exception  IOException  if an I/O error occurs.
  127.      */
  128.     public void close() throws IOException {
  129.     }
  130.  
  131. }
  132.