Source Code Cross Referenced for FingerClient.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » 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 » Net » Apache commons net 1.4.1 » org.apache.commons.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2005 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.net;
017:
018:        import java.io.BufferedReader;
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.InputStreamReader;
022:        import java.io.BufferedOutputStream;
023:        import java.io.DataOutputStream;
024:
025:        /***
026:         * The FingerClient class implements the client side of the Internet Finger
027:         * Protocol defined in RFC 1288.  To finger a host you create a
028:         * FingerClient instance, connect to the host, query the host, and finally
029:         * disconnect from the host.  If the finger service you want to query is on
030:         * a non-standard port, connect to the host at that port.
031:         * Here's a sample use:
032:         * <pre>
033:         *    FingerClient finger;
034:         *
035:         *    finger = new FingerClient();
036:         *
037:         *    try {
038:         *      finger.connect("foo.bar.com");
039:         *      System.out.println(finger.query("foobar", false));
040:         *      finger.disconnect();
041:         *    } catch(IOException e) {
042:         *      System.err.println("Error I/O exception: " + e.getMessage());
043:         *      return;
044:         *    }
045:         * </pre>
046:         * <p>
047:         * <p>
048:         * @author Daniel F. Savarese
049:         ***/
050:
051:        public class FingerClient extends SocketClient {
052:            /***
053:             * The default FINGER port.  Set to 79 according to RFC 1288.
054:             ***/
055:            public static final int DEFAULT_PORT = 79;
056:
057:            private static final String __LONG_FLAG = "/W ";
058:
059:            private transient StringBuffer __query = new StringBuffer(64);
060:            private transient char[] __buffer = new char[1024];
061:
062:            /***
063:             * The default FingerClient constructor.  Initializes the
064:             * default port to <code> DEFAULT_PORT </code>.
065:             ***/
066:            public FingerClient() {
067:                setDefaultPort(DEFAULT_PORT);
068:            }
069:
070:            /***
071:             * Fingers a user at the connected host and returns the output
072:             * as a String.  You must first connect to a finger server before
073:             * calling this method, and you should disconnect afterward.
074:             * <p>
075:             * @param longOutput Set to true if long output is requested, false if not.
076:             * @param username  The name of the user to finger.
077:             * @return The result of the finger query.
078:             * @exception IOException If an I/O error occurs while reading the socket.
079:             ***/
080:            public String query(boolean longOutput, String username)
081:                    throws IOException {
082:                int read;
083:                StringBuffer result = new StringBuffer(__buffer.length);
084:                BufferedReader input;
085:
086:                input = new BufferedReader(new InputStreamReader(
087:                        getInputStream(longOutput, username)));
088:
089:                while (true) {
090:                    read = input.read(__buffer, 0, __buffer.length);
091:                    if (read <= 0)
092:                        break;
093:                    result.append(__buffer, 0, read);
094:                }
095:
096:                input.close();
097:
098:                return result.toString();
099:            }
100:
101:            /***
102:             * Fingers the connected host and returns the output
103:             * as a String.  You must first connect to a finger server before
104:             * calling this method, and you should disconnect afterward.
105:             * This is equivalent to calling <code> query(longOutput, "") </code>.
106:             * <p>
107:             * @param longOutput Set to true if long output is requested, false if not.
108:             * @return The result of the finger query.
109:             * @exception IOException If an I/O error occurs while reading the socket.
110:             ***/
111:            public String query(boolean longOutput) throws IOException {
112:                return query(longOutput, "");
113:            }
114:
115:            /***
116:             * Fingers a user and returns the input stream from the network connection
117:             * of the finger query.  You must first connect to a finger server before
118:             * calling this method, and you should disconnect after finishing reading
119:             * the stream.
120:             * <p>
121:             * @param longOutput Set to true if long output is requested, false if not.
122:             * @param username  The name of the user to finger.
123:             * @return The InputStream of the network connection of the finger query.
124:             *         Can be read to obtain finger results.
125:             * @exception IOException If an I/O error during the operation.
126:             ***/
127:            public InputStream getInputStream(boolean longOutput,
128:                    String username) throws IOException {
129:                DataOutputStream output;
130:
131:                __query.setLength(0);
132:                if (longOutput)
133:                    __query.append(__LONG_FLAG);
134:                __query.append(username);
135:                __query.append(SocketClient.NETASCII_EOL);
136:
137:                output = new DataOutputStream(new BufferedOutputStream(
138:                        _output_, 1024));
139:                output.writeBytes(__query.toString());
140:                output.flush();
141:
142:                return _input_;
143:            }
144:
145:            /***
146:             * Fingers the connected host and returns the input stream from
147:             * the network connection of the finger query.  This is equivalent to
148:             * calling getInputStream(longOutput, "").  You must first connect to a
149:             * finger server before calling this method, and you should disconnect
150:             * after finishing reading the stream.
151:             * <p>
152:             * @param longOutput Set to true if long output is requested, false if not.
153:             * @return The InputStream of the network connection of the finger query.
154:             *         Can be read to obtain finger results.
155:             * @exception IOException If an I/O error during the operation.
156:             ***/
157:            public InputStream getInputStream(boolean longOutput)
158:                    throws IOException {
159:                return getInputStream(longOutput, "");
160:            }
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.