View Javadoc

1   /*
2    * Copyright 1999,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.commons.feedparser.network;
18  
19  import java.io.*;
20  import java.net.*;
21  import java.util.*;
22  
23  /***
24   * A ResourceRequest is a generic interface to a network resource such as an
25   * HTTP URL.
26   * 
27   * @author <a href="mailto:burton@openprivacy.org">Kevin A. Burton</a>
28   * @version $Id: ResourceRequest.java 159213 2005-03-27 23:32:01Z burton $
29   */
30  public interface ResourceRequest {
31  
32      /***
33       * Perform all initialization and connection to the remote server.  This
34       * should always be called BEFORE network getInputStream() if you want to
35       * perform other operations first.  When using a HEAD request this must be
36       * used and not getInputStream()
37       *
38       * 
39       */
40      public void init() throws IOException;
41      
42      /***
43       * Get an input stream for this content.
44       *
45       * 
46       */
47      public InputStream getInputStream() throws IOException;
48  
49      /***
50       * Set the resource for this request.
51       *
52       * 
53       */
54      public String getResource();
55      public void setResource( String resource );
56  
57      /***
58       * Get the resource but make sure all redirects are taken into
59       * consideration.
60       *
61       * 
62       */
63      public String getResourceFromRedirect();
64      
65      /***
66       * Get the given Input Stream as a String by calling read() until we have
67       * all the data locally.
68       *
69       * 
70       */
71      public String getInputStreamAsString() throws IOException;
72      public byte[] getInputStreamAsByteArray() throws IOException;
73      public InputStream getLocalInputStream() throws NetworkException;
74      public byte[] getLocalInputStreamAsByteArray() throws IOException;
75  
76      /***
77       * When true we cache getLocalInputStream() so that multiple requests are
78       * returned from local data.  Provides more flexibility but uses more
79       * memory.
80       */
81      public void setLocalCache( boolean v );
82  
83      /***
84       * Copy this input stream to an OutputStream
85       *
86       * 
87       */
88      public void toOutputStream( OutputStream out ) throws IOException;
89  
90      /***
91       * Set the If-Modified-Since header for HTTP URL connections and protocols
92       * that support similar operation.
93       *
94       * A value of -1 means do not use the If-Modified-Since header
95       *
96       * Fri Jun 06 2003 08:34 PM (burton@peerfear.org): Currently just URLResourceRequest     
97       *
98       * 
99       */
100     public long getIfModifiedSince();
101     public void setIfModifiedSince( long ifModifiedSince );
102 
103     /***
104      * The HTTP ETag to use with If-None-Match
105      *
106      * 
107      */
108     public String getEtag();
109     public void setEtag( String etag );
110     
111     /***
112      * Get and set an HTTP style response code.  Only used with HTTP URLs.
113      *
114      * 
115      */
116     public long getResponseCode();
117     public void setResponseCode( int responseCode );
118 
119     /***
120      * Return the conent length of this request or -1 if not known.
121      *
122      * 
123      */
124     public int getContentLength() throws IOException;
125 
126     public void setEventListener( NetworkEventListener eventListener );
127 
128     /***
129      * Get a given response header.
130      *
131      * 
132      */
133     public String getHeaderField( String name );
134 
135     /***
136      * Set a given request header such as UserAgent, ETag, etc.
137      *
138      * 
139      */
140     public void setRequestHeaderField( String name, String value );
141 
142     /***
143      * Get the names of all set request headers.
144      *
145      * 
146      */
147     public Iterator getRequestHeaderFields();
148 
149     public String getRequestHeaderField( String name );
150 
151     public void setRequestMethod( String method ) throws NetworkException;
152 
153     public boolean getFollowRedirects();
154     public void setFollowRedirects( boolean v );
155     
156 }