Source Code Cross Referenced for FilterOutputStream.java in  » 6.0-JDK-Core » io-nio » java » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » io nio » java.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1994-1999 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.io;
027
028        /**
029         * This class is the superclass of all classes that filter output 
030         * streams. These streams sit on top of an already existing output 
031         * stream (the <i>underlying</i> output stream) which it uses as its 
032         * basic sink of data, but possibly transforming the data along the 
033         * way or providing additional functionality. 
034         * <p>
035         * The class <code>FilterOutputStream</code> itself simply overrides 
036         * all methods of <code>OutputStream</code> with versions that pass 
037         * all requests to the underlying output stream. Subclasses of 
038         * <code>FilterOutputStream</code> may further override some of these 
039         * methods as well as provide additional methods and fields. 
040         *
041         * @author  Jonathan Payne
042         * @version 1.38, 05/05/07
043         * @since   JDK1.0
044         */
045        public class FilterOutputStream extends OutputStream {
046            /**
047             * The underlying output stream to be filtered. 
048             */
049            protected OutputStream out;
050
051            /**
052             * Creates an output stream filter built on top of the specified 
053             * underlying output stream. 
054             *
055             * @param   out   the underlying output stream to be assigned to 
056             *                the field <tt>this.out</tt> for later use, or 
057             *                <code>null</code> if this instance is to be 
058             *                created without an underlying stream.
059             */
060            public FilterOutputStream(OutputStream out) {
061                this .out = out;
062            }
063
064            /**
065             * Writes the specified <code>byte</code> to this output stream. 
066             * <p>
067             * The <code>write</code> method of <code>FilterOutputStream</code> 
068             * calls the <code>write</code> method of its underlying output stream, 
069             * that is, it performs <tt>out.write(b)</tt>.
070             * <p>
071             * Implements the abstract <tt>write</tt> method of <tt>OutputStream</tt>. 
072             *
073             * @param      b   the <code>byte</code>.
074             * @exception  IOException  if an I/O error occurs.
075             */
076            public void write(int b) throws IOException {
077                out.write(b);
078            }
079
080            /**
081             * Writes <code>b.length</code> bytes to this output stream. 
082             * <p>
083             * The <code>write</code> method of <code>FilterOutputStream</code> 
084             * calls its <code>write</code> method of three arguments with the 
085             * arguments <code>b</code>, <code>0</code>, and 
086             * <code>b.length</code>. 
087             * <p>
088             * Note that this method does not call the one-argument 
089             * <code>write</code> method of its underlying stream with the single 
090             * argument <code>b</code>. 
091             *
092             * @param      b   the data to be written.
093             * @exception  IOException  if an I/O error occurs.
094             * @see        java.io.FilterOutputStream#write(byte[], int, int)
095             */
096            public void write(byte b[]) throws IOException {
097                write(b, 0, b.length);
098            }
099
100            /**
101             * Writes <code>len</code> bytes from the specified 
102             * <code>byte</code> array starting at offset <code>off</code> to 
103             * this output stream. 
104             * <p>
105             * The <code>write</code> method of <code>FilterOutputStream</code> 
106             * calls the <code>write</code> method of one argument on each 
107             * <code>byte</code> to output. 
108             * <p>
109             * Note that this method does not call the <code>write</code> method 
110             * of its underlying input stream with the same arguments. Subclasses 
111             * of <code>FilterOutputStream</code> should provide a more efficient 
112             * implementation of this method. 
113             *
114             * @param      b     the data.
115             * @param      off   the start offset in the data.
116             * @param      len   the number of bytes to write.
117             * @exception  IOException  if an I/O error occurs.
118             * @see        java.io.FilterOutputStream#write(int)
119             */
120            public void write(byte b[], int off, int len) throws IOException {
121                if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
122                    throw new IndexOutOfBoundsException();
123
124                for (int i = 0; i < len; i++) {
125                    write(b[off + i]);
126                }
127            }
128
129            /**
130             * Flushes this output stream and forces any buffered output bytes 
131             * to be written out to the stream. 
132             * <p>
133             * The <code>flush</code> method of <code>FilterOutputStream</code> 
134             * calls the <code>flush</code> method of its underlying output stream. 
135             *
136             * @exception  IOException  if an I/O error occurs.
137             * @see        java.io.FilterOutputStream#out
138             */
139            public void flush() throws IOException {
140                out.flush();
141            }
142
143            /**
144             * Closes this output stream and releases any system resources 
145             * associated with the stream. 
146             * <p>
147             * The <code>close</code> method of <code>FilterOutputStream</code> 
148             * calls its <code>flush</code> method, and then calls the 
149             * <code>close</code> method of its underlying output stream. 
150             *
151             * @exception  IOException  if an I/O error occurs.
152             * @see        java.io.FilterOutputStream#flush()
153             * @see        java.io.FilterOutputStream#out
154             */
155            public void close() throws IOException {
156                try {
157                    flush();
158                } catch (IOException ignored) {
159                }
160                out.close();
161            }
162        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.