Source Code Cross Referenced for InputStreamReader.java in  » 6.0-JDK-Modules » j2me » java » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        import com.sun.cldc.i18n.*;
030:
031:        /**
032:         * An InputStreamReader is a bridge from byte streams to character streams: 
033:         * It reads bytes and translates them into characters.
034:         * The encoding that it uses may be specified by name, or the platform's
035:         * default encoding may be accepted.
036:         *
037:         * <p> Each invocation of one of an InputStreamReader's read() methods may
038:         * cause one or more bytes to be read from the underlying byte input stream.
039:         * To enable the efficient conversion of bytes to characters, more bytes may
040:         * be read ahead from the underlying stream than are necessary to satisfy the
041:         * current read operation.
042:         *
043:         * @version 12/17/01 (CLDC 1.1)
044:         * @see     java.io.Reader
045:         * @see     java.io.UnsupportedEncodingException
046:         * @since   CLDC 1.0
047:         */
048:
049:        public class InputStreamReader extends Reader {
050:
051:            /**
052:             * The underlying character input stream.
053:             */
054:            private Reader in;
055:
056:            /**
057:             * Create an InputStreamReader that uses the default character encoding.
058:             *
059:             * @param  is   An InputStream
060:             */
061:            public InputStreamReader(InputStream is) {
062:                in = Helper.getStreamReader(is);
063:            }
064:
065:            /**
066:             * Create an InputStreamReader that uses the named character encoding.
067:             *
068:             * @param  is   An InputStream
069:             * @param  enc  The name of a supported character encoding
070:             *
071:             * @exception  UnsupportedEncodingException
072:             *             If the named encoding is not supported
073:             */
074:            public InputStreamReader(InputStream is, String enc)
075:                    throws UnsupportedEncodingException {
076:                in = Helper.getStreamReader(is, enc);
077:            }
078:
079:            /** 
080:             * Check to make sure that the stream has not been closed
081:             */
082:            private void ensureOpen() throws IOException {
083:                if (in == null) {
084:                    throw new IOException(
085:                    /* #ifdef VERBOSE_EXCEPTIONS */
086:                    /// skipped                       "Stream closed"
087:                    /* #endif */
088:                    );
089:                }
090:            }
091:
092:            /**
093:             * Read a single character.
094:             *
095:             * @return     The character read, or -1 if the end of the stream has
096:             *             been reached
097:             * 
098:             * @exception  IOException  If an I/O error occurs
099:             */
100:            public int read() throws IOException {
101:                ensureOpen();
102:                return in.read();
103:            }
104:
105:            /**
106:             * Read characters into a portion of an array.
107:             *
108:             * @param      cbuf  Destination buffer
109:             * @param      off   Offset at which to start storing characters
110:             * @param      len   Maximum number of characters to read
111:             *
112:             * @return     The number of characters read, or -1 if the end of
113:             *             the stream has been reached
114:             *
115:             * @exception  IOException  If an I/O error occurs
116:             */
117:            public int read(char cbuf[], int off, int len) throws IOException {
118:                ensureOpen();
119:                if ((off < 0) || (off > cbuf.length) || (len < 0)
120:                        || ((off + len) > cbuf.length) || ((off + len) < 0)) {
121:                    throw new IndexOutOfBoundsException();
122:                } else if (len == 0) {
123:                    return 0;
124:                }
125:                return in.read(cbuf, off, len);
126:            }
127:
128:            /**
129:             * Skip characters.
130:             *
131:             * @param  n   The number of characters to skip
132:             *
133:             * @return     The number of characters actually skipped
134:             *
135:             * @exception  IllegalArgumentException  If <code>n</code> is negative.
136:             * @exception  IOException  If an I/O error occurs
137:             */
138:            public long skip(long n) throws IOException {
139:                ensureOpen();
140:                return in.skip(n);
141:            }
142:
143:            /**
144:             * Tell whether this stream is ready to be read.
145:             *
146:             * @return True if the next read() is guaranteed not to block for input,
147:             * false otherwise.  Note that returning false does not guarantee that the
148:             * next read will block.
149:             *
150:             * @exception  IOException  If an I/O error occurs
151:             */
152:            public boolean ready() throws IOException {
153:                ensureOpen();
154:                return in.ready();
155:            }
156:
157:            /**
158:             * Tell whether this stream supports the mark() operation.
159:             *
160:             * @return true if and only if this stream supports the mark operation.
161:             */
162:            public boolean markSupported() {
163:                if (in == null) {
164:                    return false;
165:                }
166:                return in.markSupported();
167:            }
168:
169:            /**
170:             * Mark the present position in the stream.
171:             *
172:             * @param  readAheadLimit  Limit on the number of characters that may be
173:             *                         read while still preserving the mark.  After
174:             *                         reading this many characters, attempting to
175:             *                         reset the stream may fail.
176:             *
177:             * @exception  IOException  If the stream does not support mark(),
178:             *                          or if some other I/O error occurs
179:             */
180:            public void mark(int readAheadLimit) throws IOException {
181:                ensureOpen();
182:                if (in.markSupported()) {
183:                    in.mark(readAheadLimit);
184:                } else {
185:                    throw new IOException(
186:                    /* #ifdef VERBOSE_EXCEPTIONS */
187:                    /// skipped                       "mark() not supported"
188:                    /* #endif */
189:                    );
190:                }
191:            }
192:
193:            /**
194:             * Reset the stream.
195:             *
196:             * @exception  IOException  If an I/O error occurs
197:             */
198:            public void reset() throws IOException {
199:                ensureOpen();
200:                in.reset();
201:            }
202:
203:            /**
204:             * Close the stream.  Closing a previously closed stream
205:             * has no effect.
206:             *
207:             * @exception  IOException  If an I/O error occurs
208:             */
209:            public void close() throws IOException {
210:                if (in != null) {
211:                    in.close();
212:                    in = null;
213:                }
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.