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


001:        /*
002:         * @(#)SocketOutputStream.java	1.25 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 java.net;
029:
030:        import java.io.FileDescriptor;
031:        import java.io.FileOutputStream;
032:        import java.io.IOException;
033:
034:        /**
035:         * This stream extends FileOutputStream to implement a
036:         * SocketOutputStream. Note that this class should <b>NOT</b> be
037:         * public.
038:         *
039:         * @version     1.17, 02/02/00
040:         * @author 	Jonathan Payne
041:         * @author	Arthur van Hoff
042:         */
043:        class SocketOutputStream extends FileOutputStream {
044:            static {
045:                init();
046:            }
047:
048:            private PlainSocketImpl impl = null;
049:            private byte temp[] = new byte[1];
050:            private Socket socket = null;
051:
052:            /**
053:             * Creates a new SocketOutputStream. Can only be called
054:             * by a Socket. This method needs to hang on to the owner Socket so
055:             * that the fd will not be closed.
056:             * @param impl the socket output stream inplemented
057:             */
058:            SocketOutputStream(PlainSocketImpl impl) throws IOException {
059:                super (impl.getFileDescriptor());
060:                this .impl = impl;
061:                socket = impl.getSocket();
062:            }
063:
064:            /**
065:             * Returns the unique {@link java.nio.channels.FileChannel FileChannel}
066:             * object associated with this file output stream. </p>
067:             *
068:             * The <code>getChannel</code> method of <code>SocketOutputStream</code>
069:             * returns <code>null</code> since it is a socket based stream.</p>
070:             *
071:             * @return  the file channel associated with this file output stream
072:             *
073:             * @since 1.4
074:             * @spec JSR-51
075:             */
076:            /* NOTE: No NIO in CDC
077:            public final FileChannel getChannel() {
078:                return null;
079:            }
080:             */
081:            /**
082:             * Writes to the socket.
083:             * @param fd the FileDescriptor
084:             * @param b the data to be written
085:             * @param off the start offset in the data
086:             * @param len the number of bytes that are written
087:             * @exception IOException If an I/O error has occurred.
088:             */
089:            private native void socketWrite0(FileDescriptor fd, byte[] b,
090:                    int off, int len) throws IOException;
091:
092:            /**
093:             * Writes to the socket with appropriate locking of the 
094:             * FileDescriptor.
095:             * @param b the data to be written
096:             * @param off the start offset in the data
097:             * @param len the number of bytes that are written
098:             * @exception IOException If an I/O error has occurred.
099:             */
100:            private void socketWrite(byte b[], int off, int len)
101:                    throws IOException {
102:
103:                if (len <= 0 || off < 0 | off + len > b.length) {
104:                    if (len == 0) {
105:                        return;
106:                    }
107:                    throw new ArrayIndexOutOfBoundsException();
108:                }
109:
110:                FileDescriptor fd = impl.acquireFD();
111:                try {
112:                    socketWrite0(fd, b, off, len);
113:                } catch (SocketException se) {
114:                    if (se instanceof  sun.net.ConnectionResetException) {
115:                        impl.setConnectionResetPending();
116:                        se = new SocketException("Connection reset");
117:                    }
118:                    if (impl.isClosedOrPending()) {
119:                        throw new SocketException("Socket closed");
120:                    } else {
121:                        throw se;
122:                    }
123:                } finally {
124:                    impl.releaseFD();
125:                }
126:            }
127:
128:            /** 
129:             * Writes a byte to the socket. 
130:             * @param b the data to be written
131:             * @exception IOException If an I/O error has occurred. 
132:             */
133:            public void write(int b) throws IOException {
134:                temp[0] = (byte) b;
135:                socketWrite(temp, 0, 1);
136:            }
137:
138:            /** 
139:             * Writes the contents of the buffer <i>b</i> to the socket.
140:             * @param b the data to be written
141:             * @exception SocketException If an I/O error has occurred. 
142:             */
143:            public void write(byte b[]) throws IOException {
144:                socketWrite(b, 0, b.length);
145:            }
146:
147:            /** 
148:             * Writes <i>length</i> bytes from buffer <i>b</i> starting at 
149:             * offset <i>len</i>.
150:             * @param b the data to be written
151:             * @param off the start offset in the data
152:             * @param len the number of bytes that are written
153:             * @exception SocketException If an I/O error has occurred.
154:             */
155:            public void write(byte b[], int off, int len) throws IOException {
156:                socketWrite(b, off, len);
157:            }
158:
159:            /**
160:             * Closes the stream.
161:             */
162:            private boolean closing = false;
163:
164:            public void close() throws IOException {
165:                // Prevent recursion. See BugId 4484411
166:                if (closing)
167:                    return;
168:                closing = true;
169:                if (socket != null) {
170:                    if (!socket.isClosed())
171:                        socket.close();
172:                } else
173:                    impl.close();
174:                closing = false;
175:            }
176:
177:            /** 
178:             * Overrides finalize, the fd is closed by the Socket.
179:             */
180:            protected void finalize() {
181:            }
182:
183:            /**
184:             * Perform class load-time initializations.
185:             */
186:            private native static void init();
187:
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.