home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / FilterOutputStream.java < prev    next >
Text File  |  1997-05-20  |  6KB  |  159 lines

  1. /*
  2.  * @(#)FilterOutputStream.java    1.15 97/01/22
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.io;
  24.  
  25. /**
  26.  * This class is the superclass of all classes that filter output 
  27.  * streams. These streams sit on top of an already existing output 
  28.  * stream (the <i>underlying</i> output stream), but provide 
  29.  * additional functionality. 
  30.  * <p>
  31.  * The class <code>FilterOutputStream</code> itself simply overrides 
  32.  * all methods of <code>OutputStream</code> with versions that pass 
  33.  * all requests to the underlying output stream. Subclasses of 
  34.  * <code>FilterOutputStream</code> may further override some of these 
  35.  * methods as well as provide additional methods and fields. 
  36.  *
  37.  * @author  Jonathan Payne
  38.  * @version 1.15, 01/22/97
  39.  * @since   JDK1.0
  40.  */
  41. public
  42. class FilterOutputStream extends OutputStream {
  43.     /**
  44.      * The underlying output stream. 
  45.      *
  46.      * @since   JDK1.0
  47.      */
  48.     protected OutputStream out;
  49.  
  50.     /**
  51.      * Creates an output stream filter built on top of the specified 
  52.      * underlying output stream. 
  53.      *
  54.      * @param   out   the underlying output stream.
  55.      * @since   JDK1.0
  56.      */
  57.     public FilterOutputStream(OutputStream out) {
  58.     this.out = out;
  59.     }
  60.  
  61.     /**
  62.      * Writes the specified <code>byte</code> to this output stream. 
  63.      * <p>
  64.      * The <code>write</code> method of <code>FilterOutputStream</code> 
  65.      * calls the <code>write</code> method of its underlying output stream. 
  66.      *
  67.      * @param      b   the <code>byte</code>.
  68.      * @exception  IOException  if an I/O error occurs.
  69.      * @since      JDK1.0
  70.      */
  71.     public void write(int b) throws IOException {
  72.     out.write(b);
  73.     }
  74.  
  75.     /**
  76.      * Writes <code>b.length</code> bytes to this output stream. 
  77.      * <p>
  78.      * The <code>write</code> method of <code>FilterOutputStream</code> 
  79.      * calls its <code>write</code> method of three arguments with the 
  80.      * arguments <code>b</code>, <code>0</code>, and 
  81.      * <code>b.length</code>. 
  82.      * <p>
  83.      * Note that this method does not call the one-argument 
  84.      * <code>write</code> method of its underlying stream with the single 
  85.      * argument <code>b</code>. 
  86.      *
  87.      * @param      b   the data to be written.
  88.      * @exception  IOException  if an I/O error occurs.
  89.      * @see        java.io.FilterOutputStream#write(byte[], int, int)
  90.      * @since      JDK1.0
  91.      */
  92.     public void write(byte b[]) throws IOException {
  93.     write(b, 0, b.length);
  94.     }
  95.  
  96.     /**
  97.      * Writes <code>len</code> bytes from the specified 
  98.      * <code>byte</code> array starting at offset <code>off</code> to 
  99.      * this output stream. 
  100.      * <p>
  101.      * The <code>write</code> method of <code>FilterOutputStream</code> 
  102.      * calls the <code>write</code> method of one argument on each 
  103.      * <code>byte</code> to output. 
  104.      * <p>
  105.      * Note that this method does not call the <code>write</code> method 
  106.      * of its underlying input stream with the same arguments. Subclasses 
  107.      * of <code>FilterOutputStream</code> should provide a more efficient 
  108.      * implementation of this method. 
  109.      *
  110.      * @param      b     the data.
  111.      * @param      off   the start offset in the data.
  112.      * @param      len   the number of bytes to write.
  113.      * @exception  IOException  if an I/O error occurs.
  114.      * @see        java.io.FilterOutputStream#write(int)
  115.      * @since      JDK1.0
  116.      */
  117.     public void write(byte b[], int off, int len) throws IOException {
  118.     for (int i = 0 ; i < len ; i++) {
  119.         out.write(b[off + i]);
  120.     }
  121.     }
  122.  
  123.     /**
  124.      * Flushes this output stream and forces any buffered output bytes 
  125.      * to be written out to the stream. 
  126.      * <p>
  127.      * The <code>flush</code> method of <code>FilterOutputStream</code> 
  128.      * calls the <code>flush</code> method of its underlying output stream.
  129.      *
  130.      * @exception  IOException  if an I/O error occurs.
  131.      * @see        java.io.FilterOutputStream#out
  132.      * @since      JDK1.0
  133.      */
  134.     public void flush() throws IOException {
  135.     out.flush();
  136.     }
  137.  
  138.     /**
  139.      * Closes this output stream and releases any system resources 
  140.      * associated with the stream. 
  141.      * <p>
  142.      * The <code>close</code> method of <code>FilterOutputStream</code> 
  143.      * calls its <code>flush</code> method, and then calls the 
  144.      * <code>close</code> method of its underlying output stream. 
  145.      *
  146.      * @exception  IOException  if an I/O error occurs.
  147.      * @see        java.io.FilterOutputStream#flush()
  148.      * @see        java.io.FilterOutputStream#out
  149.      * @since      JDK1.0
  150.      */
  151.     public void close() throws IOException {
  152.     try {
  153.       flush();
  154.     } catch (IOException ignored) {
  155.     }
  156.     out.close();
  157.     }
  158. }
  159.