/[classpath]/inetlib/source/gnu/inet/finger/FingerConnection.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/finger/FingerConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by dog, Thu Oct 21 15:21:54 2004 UTC revision 1.3 by dog, Thu Nov 25 22:15:05 2004 UTC
# Line 1  Line 1 
1  /*  /*
2   * $Id$   * FingerConnection.java
3   * Copyright (C) 2003 The Free Software Foundation   * Copyright (C) 2003 The Free Software Foundation
4   *   *
5   * This file is part of GNU inetlib, a library.   * This file is part of GNU inetlib, a library.
# Line 35  Line 35 
35   * obliged to do so.  If you do not wish to do so, delete this   * obliged to do so.  If you do not wish to do so, delete this
36   * exception statement from your version.   * exception statement from your version.
37   */   */
38    
39  package gnu.inet.finger;  package gnu.inet.finger;
40    
41  import java.io.BufferedOutputStream;  import java.io.BufferedOutputStream;
# Line 76  public class FingerConnection Line 77  public class FingerConnection
77     * Creates a new finger connection.     * Creates a new finger connection.
78     * @param host the name of the internet host to connect to     * @param host the name of the internet host to connect to
79     */     */
80    public FingerConnection (String host)    public FingerConnection(String host)
81      throws IOException      throws IOException
82      {    {
83        this (host, DEFAULT_PORT);      this(host, DEFAULT_PORT);
84      }    }
85    
86    /**    /**
87     * Creates a new finger connection.     * Creates a new finger connection.
88     * @param host the name of the internet host to connect to     * @param host the name of the internet host to connect to
89     * @param port the port to connect to     * @param port the port to connect to
90     */     */
91    public FingerConnection (String host, int port)    public FingerConnection(String host, int port)
92      throws IOException      throws IOException
93      {    {
94        socket = new Socket (host, port);      socket = new Socket(host, port);
95      }    }
96    
97    /**    /**
98     * Retrieves the verbose flag.     * Retrieves the verbose flag.
99     * If true, the server should provide more output.     * If true, the server should provide more output.
100     */     */
101    public boolean isVerbose ()    public boolean isVerbose()
102      {    {
103        return verbose;      return verbose;
104      }    }
105    
106    /**    /**
107     * Sets the verbose flag.     * Sets the verbose flag.
108     * If true, the server should provide more output.     * If true, the server should provide more output.
109     * @param verbose true for more verbose, false otherwise     * @param verbose true for more verbose, false otherwise
110     */     */
111    public void setVerbose (boolean verbose)    public void setVerbose(boolean verbose)
112      {    {
113        this.verbose = verbose;      this.verbose = verbose;
114      }    }
115    
116    /**    /**
117     * Lists the available users.     * Lists the available users.
118     */     */
119    public String list ()    public String list()
120      throws IOException      throws IOException
121      {    {
122        return finger (null, null);      return finger(null, null);
123      }    }
124    
125    /**    /**
126     * Fingers the specified user.     * Fingers the specified user.
127     * @param username the user to finger     * @param username the user to finger
128     * @return information about all matching users     * @return information about all matching users
129     */     */
130    public String finger (String username)    public String finger(String username)
131      throws IOException      throws IOException
132      {    {
133        return finger (username, null);      return finger(username, null);
134      }    }
135    
136    /**    /**
137     * Fingers the specified user at the specified host.     * Fingers the specified user at the specified host.
# Line 138  public class FingerConnection Line 139  public class FingerConnection
139     * @param hostname the domain of the user (null for any domain)     * @param hostname the domain of the user (null for any domain)
140     * @return information about all matching users     * @return information about all matching users
141     */     */
142    public String finger (String username, String hostname)    public String finger(String username, String hostname)
143      throws IOException      throws IOException
144      {    {
145        // Send the command      // Send the command
146        OutputStream out = socket.getOutputStream ();      OutputStream out = socket.getOutputStream();
147        out = new BufferedOutputStream (out);      out = new BufferedOutputStream(out);
148        if (verbose)      if (verbose)
149          {        {
150            out.write ('/');          out.write('/');
151            out.write ('W');          out.write('W');
152            if (username != null || hostname != null)          if (username != null || hostname != null)
153              {            {
154                out.write (' ');              out.write(' ');
155              }            }
156          }        }
157        if (username != null)      if (username != null)
158          {        {
159            out.write (username.getBytes (US_ASCII));          out.write(username.getBytes(US_ASCII));
160          }        }
161        if (hostname != null)      if (hostname != null)
162          {        {
163            out.write ('@');          out.write('@');
164            out.write (hostname.getBytes (US_ASCII));          out.write(hostname.getBytes(US_ASCII));
165          }        }
166        out.write ('\r');      out.write('\r');
167        out.write ('\n');      out.write('\n');
168        out.flush ();      out.flush();
169                
170        // Read the response      // Read the response
171        InputStream in = socket.getInputStream ();      InputStream in = socket.getInputStream();
172        ByteArrayOutputStream acc = new ByteArrayOutputStream ();      ByteArrayOutputStream acc = new ByteArrayOutputStream();
173        byte[] buf = new byte[4096];      byte[] buf = new byte[4096];
174        for (int len = in.read (buf); len != -1; len = in.read (buf))      for (int len = in.read(buf); len != -1; len = in.read(buf))
175          {        {
176            acc.write (buf, 0, len);          acc.write(buf, 0, len);
177          }        }
178        return acc.toString (US_ASCII);      return acc.toString(US_ASCII);
179      }    }
180    
181  }  }
182    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26