Source Code Cross Referenced for FDInputStream.java in  » 6.0-JDK-Modules » j2me » sun » 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 » sun.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)FDInputStream.java	1.44 06/10/10
003:         *
004:         * Copyright  1990-2006 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:
028:        package sun.io;
029:
030:        import java.io.*;
031:
032:        /**
033:         * A file input stream is an input stream for reading data from a 
034:         * <code>File</code> or from a <code>FileDescriptor</code>. 
035:         *
036:         * @author  Arthur van Hoff
037:         * @version 1.40, 08/19/02
038:         * @see     java.io.File
039:         * @see     java.io.FileDescriptor
040:         * @see	    java.io.FileOutputStream
041:         * @since   JDK1.0
042:         */
043:        public class FDInputStream extends InputStream {
044:            static {
045:                java.security.AccessController
046:                        .doPrivileged(new sun.security.action.LoadLibraryAction(
047:                                "javafile"));
048:            }
049:            /* File Descriptor - handle to the open file */
050:            private FileDescriptor fd;
051:
052:            /**
053:             * Creates an input file stream to read from a file with the 
054:             * specified name. 
055:             *
056:             * @param      name   the system-dependent file name.
057:             * @exception  SecurityException      if a security manager exists, its
058:             *               <code>checkRead</code> method is called with the name
059:             *               argument to see if the application is allowed read access
060:             *               to the file.
061:             * @see        java.lang.SecurityManager#checkRead(java.lang.String)
062:             * @since      JDK1.0
063:             */
064:            public FDInputStream(String name) throws IOException {
065:                SecurityManager security = System.getSecurityManager();
066:                if (security != null) {
067:                    security.checkRead(name);
068:                }
069:                try {
070:                    fd = new FileDescriptor();
071:                    open(name);
072:                } catch (IOException e) {
073:                    throw new IOException(name);
074:                }
075:            }
076:
077:            /**
078:             * Creates an input file stream to read from the specified file descriptor.
079:             *
080:             * @param      fdObj   the file descriptor to be opened for reading.
081:             * @exception  SecurityException  if a security manager exists, its
082:             *               <code>checkRead</code> method is called with the file
083:             *               descriptor to see if the application is allowed to read
084:             *               from the specified file descriptor.
085:             * @see        java.lang.SecurityManager#checkRead(java.io.FileDescriptor)
086:             * @since      JDK1.0
087:             */
088:            public FDInputStream(FileDescriptor fdObj) {
089:                SecurityManager security = System.getSecurityManager();
090:                if (fdObj == null) {
091:                    throw new NullPointerException();
092:                }
093:                if (security != null) {
094:                    security.checkRead(fdObj);
095:                }
096:                fd = fdObj;
097:            }
098:
099:            /**
100:             * Opens the specified file for reading.
101:             * @param name the name of the file
102:             */
103:            public native void open(String name) throws IOException;
104:
105:            /**
106:             * Reads a byte of data from this input stream. This method blocks 
107:             * if no input is yet available. 
108:             *
109:             * @return     the next byte of data, or <code>-1</code> if the end of the
110:             *             file is reached.
111:             * @exception  IOException  if an I/O error occurs.
112:             * @since      JDK1.0
113:             */
114:            public native int read() throws IOException;
115:
116:            /** 
117:             * Reads a subarray as a sequence of bytes. 
118:             * @param b the data to be written
119:             * @param off the start offset in the data
120:             * @param len the number of bytes that are written
121:             * @exception IOException If an I/O error has occurred. 
122:             */
123:            public native int readBytes(byte b[], int off, int len)
124:                    throws IOException;
125:
126:            /**
127:             * Reads up to <code>b.length</code> bytes of data from this input 
128:             * stream into an array of bytes. This method blocks until some input 
129:             * is available. 
130:             *
131:             * @param      b   the buffer into which the data is read.
132:             * @return     the total number of bytes read into the buffer, or
133:             *             <code>-1</code> if there is no more data because the end of
134:             *             the file has been reached.
135:             * @exception  IOException  if an I/O error occurs.
136:             * @since      JDK1.0
137:             */
138:            public int read(byte b[]) throws IOException {
139:                return readBytes(b, 0, b.length);
140:            }
141:
142:            /**
143:             * Reads up to <code>len</code> bytes of data from this input stream 
144:             * into an array of bytes. This method blocks until some input is 
145:             * available. 
146:             *
147:             * @param      b     the buffer into which the data is read.
148:             * @param      off   the start offset of the data.
149:             * @param      len   the maximum number of bytes read.
150:             * @return     the total number of bytes read into the buffer, or
151:             *             <code>-1</code> if there is no more data because the end of
152:             *             the file has been reached.
153:             * @exception  IOException  if an I/O error occurs.
154:             * @since      JDK1.0
155:             */
156:            public int read(byte b[], int off, int len) throws IOException {
157:                return readBytes(b, off, len);
158:            }
159:
160:            /**
161:             * Skips over and discards <code>n</code> bytes of data from the 
162:             * input stream. The <code>skip</code> method may, for a variety of 
163:             * reasons, end up skipping over some smaller number of bytes, 
164:             * possibly <code>0</code>. The actual number of bytes skipped is returned.
165:             *
166:             * @param      n   the number of bytes to be skipped.
167:             * @return     the actual number of bytes skipped.
168:             * @exception  IOException  if an I/O error occurs.
169:             * @since      JDK1.0
170:             */
171:            public native long skip(long n) throws IOException;
172:
173:            /**
174:             * Returns the number of bytes that can be read from this file input
175:             * stream without blocking.
176:             *
177:             * @return     the number of bytes that can be read from this file input
178:             *             stream without blocking.
179:             * @exception  IOException  if an I/O error occurs.
180:             * @since      JDK1.0
181:             */
182:            public native int available() throws IOException;
183:
184:            /**
185:             * Closes this file input stream and releases any system resources 
186:             * associated with the stream. 
187:             *
188:             * @exception  IOException  if an I/O error occurs.
189:             * @since      JDK1.0
190:             */
191:            public native void close() throws IOException;
192:
193:            /**
194:             * Returns the opaque file descriptor object associated with this stream.
195:             *
196:             * @return     the file descriptor object associated with this stream.
197:             * @exception  IOException  if an I/O error occurs.
198:             * @see        java.io.FileDescriptor
199:             * @since      JDK1.0
200:             */
201:            public final FileDescriptor getFD() throws IOException {
202:                if (fd != null)
203:                    return fd;
204:                throw new IOException();
205:            }
206:
207:            /**
208:             * Ensures that the <code>close</code> method of this file input stream is
209:             * called when there are no more references to it. 
210:             *
211:             * @exception  IOException  if an I/O error occurs.
212:             * @see        java.io.FileInputStream#close()
213:             * @since      JDK1.0
214:             */
215:            protected void finalize() throws IOException {
216:                if (fd != null) {
217:                    if (fd != fd.in) {
218:                        close();
219:                    }
220:                }
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.