KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > vfs > QSocket


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.vfs;
30
31 import java.io.IOException JavaDoc;
32 import java.net.InetAddress JavaDoc;
33 import java.nio.channels.SelectableChannel JavaDoc;
34 import java.security.cert.X509Certificate JavaDoc;
35
36 /**
37  * Abstract socket to handle both normal sockets and JNI sockets.
38  */

39 abstract public class QSocket {
40   /**
41    * Returns the server inet address that accepted the request.
42    */

43   abstract public InetAddress JavaDoc getLocalAddress();
44   
45   /**
46    * Returns the server port that accepted the request.
47    */

48   abstract public int getLocalPort();
49
50   /**
51    * Returns the remote client's inet address.
52    */

53   abstract public InetAddress JavaDoc getRemoteAddress();
54
55   /**
56    * Returns the remote client's inet address.
57    */

58   public String JavaDoc getRemoteHost()
59   {
60     return getRemoteAddress().getHostAddress();
61   }
62
63   /**
64    * Returns the remote client's inet address.
65    */

66   public int getRemoteAddress(byte []buffer, int offset, int length)
67   {
68     String JavaDoc name = getRemoteHost();
69     int len = name.length();
70
71     for (int i = 0; i < len; i++)
72       buffer[i + offset] = (byte) name.charAt(i);
73
74     return len;
75   }
76   
77   /**
78    * Returns the remote client's port.
79    */

80   abstract public int getRemotePort();
81
82   /**
83    * Returns true if the connection is secure.
84    */

85   public boolean isSecure()
86   {
87     return false;
88   }
89
90   /**
91    * Returns any selectable channel.
92    */

93   public SelectableChannel JavaDoc getSelectableChannel()
94   {
95     return null;
96   }
97
98   /**
99    * Read non-blocking
100    */

101   public boolean readNonBlock(int ms)
102   {
103     return false;
104   }
105
106   /**
107    * Returns the secure cipher algorithm.
108    */

109   public String JavaDoc getCipherSuite()
110   {
111     return null;
112   }
113
114   /**
115    * Returns the bits in the socket.
116    */

117   public int getCipherBits()
118   {
119     return 0;
120   }
121
122   /**
123    * Returns the client certificate.
124    */

125   public X509Certificate JavaDoc getClientCertificate()
126     throws java.security.cert.CertificateException JavaDoc
127   {
128     return null;
129   }
130
131   /**
132    * Returns the client certificate chain.
133    */

134   public X509Certificate JavaDoc []getClientCertificates()
135     throws java.security.cert.CertificateException JavaDoc
136   {
137     X509Certificate JavaDoc cert = getClientCertificate();
138
139     if (cert != null)
140       return new X509Certificate JavaDoc[] { cert };
141     else
142       return null;
143   }
144   
145   /**
146    * Returns a stream impl for the socket encapsulating the
147    * input and output stream.
148    */

149   abstract public StreamImpl getStream()
150     throws IOException JavaDoc;
151
152
153   /**
154    * Returns the total number of bytes read from the socket connection.
155    */

156   abstract public long getTotalReadBytes();
157
158   /**
159    * Returns the total number of bytes written to the socket connection.
160    */

161   abstract public long getTotalWriteBytes();
162
163   /**
164    * returns true if it's closed.
165    */

166   abstract public boolean isClosed();
167   
168   abstract public void close()
169     throws IOException JavaDoc;
170
171 }
172
173
Popular Tags