Source Code Cross Referenced for finger.java in  » Net » Apache-commons-net-1.4.1 » examples » 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 » examples 
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 examples;
017:
018:        import java.io.IOException;
019:        import java.net.InetAddress;
020:        import java.net.UnknownHostException;
021:        import org.apache.commons.net.FingerClient;
022:
023:        /***
024:         * This is an example of how you would implement the finger command
025:         * in Java using NetComponents.  The Java version is much shorter.
026:         * But keep in mind that the Unix finger command reads all sorts of
027:         * local files to output local finger information.  This program only
028:         * queries the finger daemon.
029:         * <p>
030:         * The -l flag is used to request long output from the server.
031:         * <p>
032:         ***/
033:        public final class finger {
034:
035:            public static final void main(String[] args) {
036:                boolean longOutput = false;
037:                int arg = 0, index;
038:                String handle, host;
039:                FingerClient finger;
040:                InetAddress address = null;
041:
042:                // Get flags.  If an invalid flag is present, exit with usage message.
043:                while (arg < args.length && args[arg].startsWith("-")) {
044:                    if (args[arg].equals("-l"))
045:                        longOutput = true;
046:                    else {
047:                        System.err
048:                                .println("usage: finger [-l] [[[handle][@<server>]] ...]");
049:                        System.exit(1);
050:                    }
051:                    ++arg;
052:                }
053:
054:                finger = new FingerClient();
055:                // We want to timeout if a response takes longer than 60 seconds
056:                finger.setDefaultTimeout(60000);
057:
058:                if (arg >= args.length) {
059:                    // Finger local host
060:
061:                    try {
062:                        address = InetAddress.getLocalHost();
063:                    } catch (UnknownHostException e) {
064:                        System.err.println("Error unknown host: "
065:                                + e.getMessage());
066:                        System.exit(1);
067:                    }
068:
069:                    try {
070:                        finger.connect(address);
071:                        System.out.print(finger.query(longOutput));
072:                        finger.disconnect();
073:                    } catch (IOException e) {
074:                        System.err.println("Error I/O exception: "
075:                                + e.getMessage());
076:                        System.exit(1);
077:                    }
078:
079:                    return;
080:                }
081:
082:                // Finger each argument
083:                while (arg < args.length) {
084:
085:                    index = args[arg].lastIndexOf("@");
086:
087:                    if (index == -1) {
088:                        handle = args[arg];
089:                        try {
090:                            address = InetAddress.getLocalHost();
091:                        } catch (UnknownHostException e) {
092:                            System.err.println("Error unknown host: "
093:                                    + e.getMessage());
094:                            System.exit(1);
095:                        }
096:                    } else {
097:                        handle = args[arg].substring(0, index);
098:                        host = args[arg].substring(index + 1);
099:
100:                        try {
101:                            address = InetAddress.getByName(host);
102:                        } catch (UnknownHostException e) {
103:                            System.err.println("Error unknown host: "
104:                                    + e.getMessage());
105:                            System.exit(1);
106:                        }
107:                    }
108:
109:                    System.out.println("[" + address.getHostName() + "]");
110:
111:                    try {
112:                        finger.connect(address);
113:                        System.out.print(finger.query(longOutput, handle));
114:                        finger.disconnect();
115:                    } catch (IOException e) {
116:                        System.err.println("Error I/O exception: "
117:                                + e.getMessage());
118:                        System.exit(1);
119:                    }
120:
121:                    ++arg;
122:                    if (arg != args.length)
123:                        System.out.print("\n");
124:                }
125:            }
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.