RoResponse.java
Upload User: demmber
Upload Date: 2007-12-22
Package Size: 717k
Code Size: 7k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * @(#)RoResponse.java 0.3-3 06/05/2001
  3.  *
  4.  *  This file is part of the HTTPClient package
  5.  *  Copyright (C) 1996-2001 Ronald Tschal鋜
  6.  *
  7.  *  This library is free software; you can redistribute it and/or
  8.  *  modify it under the terms of the GNU Lesser General Public
  9.  *  License as published by the Free Software Foundation; either
  10.  *  version 2 of the License, or (at your option) any later version.
  11.  *
  12.  *  This library is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  *  Lesser General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU Lesser General Public
  18.  *  License along with this library; if not, write to the Free
  19.  *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20.  *  MA 02111-1307, USA
  21.  *
  22.  *  For questions, suggestions, bug-reports, enhancement-requests etc.
  23.  *  I may be contacted at:
  24.  *
  25.  *  ronald@innovation.ch
  26.  *
  27.  *  The HTTPClient's home page is located at:
  28.  *
  29.  *  http://www.innovation.ch/java/HTTPClient/ 
  30.  *
  31.  */
  32. package HTTPClient;
  33. import java.io.InputStream;
  34. import java.io.IOException;
  35. import java.util.Date;
  36. /**
  37.  * This interface represents read-only interface of an intermediate http
  38.  * response. It is the compile-time type passed to various handlers which
  39.  * might the response info but musn't modify the response.
  40.  *
  41.  * @version 0.3-3  06/05/2001
  42.  * @author Ronald Tschal鋜
  43.  */
  44. public interface RoResponse
  45. {
  46.     /**
  47.      * give the status code for this request. These are grouped as follows:
  48.      * <UL>
  49.      *   <LI> 1xx - Informational (new in HTTP/1.1)
  50.      *   <LI> 2xx - Success
  51.      *   <LI> 3xx - Redirection
  52.      *   <LI> 4xx - Client Error
  53.      *   <LI> 5xx - Server Error
  54.      * </UL>
  55.      *
  56.      * @return the status code
  57.      * @exception IOException If any exception occurs on the socket.
  58.      */
  59.     public int getStatusCode()  throws IOException;
  60.     /**
  61.      * @return the reason line associated with the status code.
  62.      * @exception IOException If any exception occurs on the socket.
  63.      */
  64.     public String getReasonLine()  throws IOException;
  65.     /**
  66.      * @return the HTTP version returned by the server.
  67.      * @exception IOException If any exception occurs on the socket.
  68.      */
  69.     public String getVersion()  throws IOException;
  70.     /**
  71.      * retrieves the field for a given header.
  72.      *
  73.      * @param  hdr the header name.
  74.      * @return the value for the header, or null if non-existent.
  75.      * @exception IOException If any exception occurs on the socket.
  76.      */
  77.     public String getHeader(String hdr)  throws IOException;
  78.     /**
  79.      * retrieves the field for a given header. The value is parsed as an
  80.      * int.
  81.      *
  82.      * @param  hdr the header name.
  83.      * @return the value for the header if the header exists
  84.      * @exception NumberFormatException if the header's value is not a number
  85.      *                                  or if the header does not exist.
  86.      * @exception IOException if any exception occurs on the socket.
  87.      */
  88.     public int getHeaderAsInt(String hdr)
  89. throws IOException, NumberFormatException;
  90.     /**
  91.      * retrieves the field for a given header. The value is parsed as a
  92.      * date; if this fails it is parsed as a long representing the number
  93.      * of seconds since 12:00 AM, Jan 1st, 1970. If this also fails an
  94.      * IllegalArgumentException is thrown.
  95.      *
  96.      * @param  hdr the header name.
  97.      * @return the value for the header, or null if non-existent.
  98.      * @exception IOException If any exception occurs on the socket.
  99.      * @exception IllegalArgumentException If the header cannot be parsed
  100.      *            as a date or time.
  101.      */
  102.     public Date getHeaderAsDate(String hdr)
  103.     throws IOException, IllegalArgumentException;
  104.     /**
  105.      * Retrieves the field for a given trailer. Note that this should not
  106.      * be invoked until all the response data has been read. If invoked
  107.      * before, it will force the data to be read via <code>getData()</code>.
  108.      *
  109.      * @param  trailer the trailer name.
  110.      * @return the value for the trailer, or null if non-existent.
  111.      * @exception IOException If any exception occurs on the socket.
  112.      */
  113.     public String getTrailer(String trailer)  throws IOException;
  114.     /**
  115.      * Retrieves the field for a given tailer. The value is parsed as an
  116.      * int.
  117.      *
  118.      * @param  trailer the tailer name.
  119.      * @return the value for the trailer if the trailer exists
  120.      * @exception NumberFormatException if the trailer's value is not a number
  121.      *                                  or if the trailer does not exist.
  122.      * @exception IOException if any exception occurs on the socket.
  123.      */
  124.     public int getTrailerAsInt(String trailer)
  125. throws IOException, NumberFormatException;
  126.     /**
  127.      * Retrieves the field for a given trailer. The value is parsed as a
  128.      * date; if this fails it is parsed as a long representing the number
  129.      * of seconds since 12:00 AM, Jan 1st, 1970. If this also fails an
  130.      * IllegalArgumentException is thrown.
  131.      * <br>Note: When sending dates use Util.httpDate().
  132.      *
  133.      * @param  trailer the trailer name.
  134.      * @return the value for the trailer, or null if non-existent.
  135.      * @exception IllegalArgumentException if the trailer's value is neither a
  136.      *            legal date nor a number.
  137.      * @exception IOException if any exception occurs on the socket.
  138.      * @exception IllegalArgumentException If the header cannot be parsed
  139.      *            as a date or time.
  140.      */
  141.     public Date getTrailerAsDate(String trailer)
  142. throws IOException, IllegalArgumentException;
  143.     /**
  144.      * Reads all the response data into a byte array. Note that this method
  145.      * won't return until <em>all</em> the data has been received (so for
  146.      * instance don't invoke this method if the server is doing a server
  147.      * push). If getInputStream() had been previously called then this method
  148.      * only returns any unread data remaining on the stream and then closes
  149.      * it.
  150.      *
  151.      * @see #getInputStream()
  152.      * @return an array containing the data (body) returned. If no data
  153.      *         was returned then it's set to a zero-length array.
  154.      * @exception IOException If any io exception occured while reading
  155.      *       the data
  156.      */
  157.     public byte[] getData()  throws IOException;
  158.     /**
  159.      * Gets an input stream from which the returned data can be read. Note
  160.      * that if getData() had been previously called it will actually return
  161.      * a ByteArrayInputStream created from that data.
  162.      *
  163.      * @see #getData()
  164.      * @return the InputStream.
  165.      * @exception IOException If any exception occurs on the socket.
  166.      */
  167.     public InputStream getInputStream()  throws IOException;
  168. }