1 16 package org.apache.commons.net; 17 18 import java.io.BufferedReader ; 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.InputStreamReader ; 22 import java.io.BufferedOutputStream ; 23 import java.io.DataOutputStream ; 24 25 50 51 public class FingerClient extends SocketClient 52 { 53 56 public static final int DEFAULT_PORT = 79; 57 58 private static final String __LONG_FLAG = "/W "; 59 60 private transient StringBuffer __query = new StringBuffer (64); 61 private transient char[] __buffer = new char[1024]; 62 63 67 public FingerClient() 68 { 69 setDefaultPort(DEFAULT_PORT); 70 } 71 72 73 83 public String query(boolean longOutput, String username) throws IOException 84 { 85 int read; 86 StringBuffer result = new StringBuffer (__buffer.length); 87 BufferedReader input; 88 89 input = 90 new BufferedReader (new InputStreamReader (getInputStream(longOutput, 91 username))); 92 93 while (true) 94 { 95 read = input.read(__buffer, 0, __buffer.length); 96 if (read <= 0) 97 break; 98 result.append(__buffer, 0, read); 99 } 100 101 input.close(); 102 103 return result.toString(); 104 } 105 106 107 117 public String query(boolean longOutput) throws IOException 118 { 119 return query(longOutput, ""); 120 } 121 122 123 135 public InputStream getInputStream(boolean longOutput, String username) 136 throws IOException 137 { 138 DataOutputStream output; 139 140 __query.setLength(0); 141 if (longOutput) 142 __query.append(__LONG_FLAG); 143 __query.append(username); 144 __query.append(SocketClient.NETASCII_EOL); 145 146 output = 147 new DataOutputStream (new BufferedOutputStream (_output_, 1024)); 148 output.writeBytes(__query.toString()); 149 output.flush(); 150 151 return _input_; 152 } 153 154 155 167 public InputStream getInputStream(boolean longOutput) throws IOException 168 { 169 return getInputStream(longOutput, ""); 170 } 171 172 } 173 | Popular Tags |