public class SunHttpTransport extends HttpTransport
BUFFER_SIZE
Constructor and Description |
---|
SunHttpTransport()
Constructs a new SunHttpTransport object.
|
Modifier and Type | Method and Description |
---|---|
void |
addTextType(String texttype)
Add a MIME type to the list of text types.
|
byte[] |
downloadURL(String url)
Retrieve large response from the URL and returns the data read.
|
String |
dumpResponseHeaders()
Utility class to get responseHeaders as a string.
|
StringBuilder |
fetchPage(String page,
String[] images,
String postRequest)
Makes a POST request, fetches the main page and all other image or
resource pages.
|
StringBuilder |
fetchResponse(HttpURLConnection connection)
Fetches http response data from an already established connection.
|
StringBuilder |
fetchResponseData(InputStream stream)
Fetches the data from the stream, converts to char, and returns it as
a StringBuilder.
|
StringBuilder |
fetchResponseData(Reader reader)
Fetches the data from the reader and returns it as a StringBuilder.
|
StringBuilder |
fetchURL(String url)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(String url,
Map<String,String> headers)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(String url,
String postRequest)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(String url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(URL url)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(URL url,
Map<String,String> headers)
Reads data from the URL and returns the data read.
|
StringBuilder |
fetchURL(URL url,
String postRequest)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(URL url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
StringBuilder |
fetchURL(URL page,
URL[] images,
String postRequest)
Method not implemented.
|
int |
getContentSize()
Obtains the size of the last read page or resource.
|
String[] |
getCookieValuesByName(String name)
Obtains the list of cookie values by the name of the cookies.
|
StringBuilder |
getResponseBuffer()
Obtains the reference of the current response buffer.
|
int |
getResponseCode()
Obtains the response code of the previous request.
|
String[] |
getResponseHeader(String name)
Obtains the header fields of the last request's response.
|
boolean |
isFollowRedirects()
Checks whether the connections managed by this transport follows
redirects or not.
|
boolean |
matchResponse(InputStream stream,
String regex)
Matches the regular expression against the data read from the stream.
|
boolean |
matchResponse(Reader reader,
String regex)
Matches the regular expression against the data read from the reader.
|
boolean |
matchResponse(String regex)
Maches the regular expression against the data in the current buffer.
|
boolean |
matchResponse(URLConnection connection,
String regex,
Map<String,String> headers)
Matches the regular expression against the data read from the connection.
|
boolean |
matchURL(String url,
String regex)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(String url,
String regex,
Map<String,String> headers)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(String url,
String postRequest,
String regex)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
boolean |
matchURL(String url,
String postRequest,
String regex,
Map<String,String> headers)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
boolean |
matchURL(URL url,
String regex)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(URL url,
String regex,
Map<String,String> headers)
Matches the regular expression against the response fetched from the
URL.
|
boolean |
matchURL(URL url,
String postRequest,
String regex)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
boolean |
matchURL(URL url,
String postRequest,
String regex,
Map<String,String> headers)
Mathces the regular expression against the response fetched from the
post request made to the URL.
|
int |
readURL(String url)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(String url,
byte[] postRequest)
Makes a POST request to the URL without encoding the data (the
header type is application/octet-stream).
|
int |
readURL(String url,
Map<String,String> headers)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(String url,
String postRequest)
Makes a POST request to the URL.
|
int |
readURL(String url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
int |
readURL(URL url)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(URL url,
byte[] postRequest,
Map<String,String> headers)
Makes a POST request to the URL without encoding the data (the
header type is application/octet-stream).
|
int |
readURL(URL url,
Map<String,String> headers)
Reads data from the URL and discards it, keeping just the size of the
total read.
|
int |
readURL(URL url,
String postRequest)
Makes a POST request to the URL.
|
int |
readURL(URL url,
String postRequest,
Map<String,String> headers)
Makes a POST request to the URL.
|
void |
setFollowRedirects(boolean follow)
Sets the http connections managed by this transport to follow or
not follow HTTP redirects.
|
getCookies, newInstance, setDownloadSpeed, setProvider, setUploadSpeed
public SunHttpTransport()
public void setFollowRedirects(boolean follow)
setFollowRedirects
in class HttpTransport
follow
- True if HTTP redirects should be automatically followed,
false otherwisepublic void addTextType(String texttype)
addTextType
in class HttpTransport
texttype
- The content type of a HTTP response that contains text.public boolean isFollowRedirects()
isFollowRedirects
in class HttpTransport
public StringBuilder getResponseBuffer()
getResponseBuffer
in class HttpTransport
public int readURL(URL url, Map<String,String> headers) throws IOException
readURL
in class HttpTransport
url
- The URL to read fromheaders
- The request headersIOException
public int readURL(URL url) throws IOException
readURL
in class HttpTransport
url
- The URL to read fromIOException
public int readURL(String url, Map<String,String> headers) throws IOException
readURL
in class HttpTransport
url
- The URL to read fromheaders
- The request headersIOException
public int readURL(String url) throws IOException
readURL
in class HttpTransport
url
- The URL to read fromIOException
public int readURL(URL url, String postRequest) throws IOException
readURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringIOException
public int readURL(URL url, String postRequest, Map<String,String> headers) throws IOException
readURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
public int readURL(URL url, byte[] postRequest, Map<String,String> headers) throws IOException
readURL
in class HttpTransport
url
- The URL to read frompostRequest
- The binary data to sendheaders
- The request headersIOException
public int readURL(String url, byte[] postRequest) throws IOException
readURL
in class HttpTransport
url
- The URL to read frompostRequest
- The binary data to sendIOException
public int readURL(String url, String postRequest) throws IOException
readURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringIOException
public int readURL(String url, String postRequest, Map<String,String> headers) throws IOException
readURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
public StringBuilder fetchURL(URL url, Map<String,String> headers) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read fromheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL url) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read fromIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(String url, Map<String,String> headers) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read fromheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(String url) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read fromIOException
addTextType(String)
,
getContentSize()
public byte[] downloadURL(String url) throws IOException
downloadURL
in class HttpTransport
url
- The URL to read fromIOException
getContentSize()
public StringBuilder fetchURL(String url, String postRequest) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(String url, String postRequest, Map<String,String> headers) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL url, String postRequest, Map<String,String> headers) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringheaders
- The request headersIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL url, String postRequest) throws IOException
fetchURL
in class HttpTransport
url
- The URL to read frompostRequest
- The post request stringIOException
addTextType(String)
,
getContentSize()
public StringBuilder fetchURL(URL page, URL[] images, String postRequest) throws IOException
fetchURL
in class HttpTransport
page
- The page URLimages
- The image or other resource URLs to fetch with pagepostRequest
- The post stringIOException
- If an I/O error occurredpublic StringBuilder fetchPage(String page, String[] images, String postRequest) throws IOException
fetchPage
in class HttpTransport
page
- The page URLimages
- The image or other resource URLs to fetch with pagepostRequest
- The post stringIOException
- If an I/O error occurredpublic StringBuilder fetchResponse(HttpURLConnection connection) throws IOException
connection
- The connection to fetch fromIOException
addTextType(String)
,
getContentSize()
public int getContentSize()
getContentSize
in class HttpTransport
public StringBuilder fetchResponseData(InputStream stream) throws IOException
fetchResponseData
in class HttpTransport
stream
- The stream to read fromIOException
public StringBuilder fetchResponseData(Reader reader) throws IOException
fetchResponseData
in class HttpTransport
reader
- The reader to read fromIOException
public boolean matchResponse(String regex)
matchResponse
in class HttpTransport
regex
- The regular expression to matchpublic boolean matchResponse(URLConnection connection, String regex, Map<String,String> headers) throws IOException
connection
- The source of the dataregex
- The regular expression to matchheaders
- The request headersIOException
public boolean matchResponse(InputStream stream, String regex) throws IOException
matchResponse
in class HttpTransport
stream
- The source of the dataregex
- The regular expression to matchIOException
public boolean matchResponse(Reader reader, String regex) throws IOException
matchResponse
in class HttpTransport
reader
- The source of the dataregex
- The regular expression to matchIOException
public boolean matchURL(String url, String regex) throws IOException
matchURL
in class HttpTransport
url
- The source of the dataregex
- THe regular expression to matchIOException
public boolean matchURL(String url, String regex, Map<String,String> headers) throws IOException
matchURL
in class HttpTransport
url
- The source of the dataregex
- The regular expression to matchheaders
- The request headersIOException
public boolean matchURL(URL url, String regex) throws IOException
matchURL
in class HttpTransport
url
- The source of the dataregex
- The regular expression to matchIOException
public boolean matchURL(URL url, String regex, Map<String,String> headers) throws IOException
matchURL
in class HttpTransport
url
- The source of the dataregex
- The regular expression to matchheaders
- The request headersIOException
public boolean matchURL(URL url, String postRequest, String regex) throws IOException
matchURL
in class HttpTransport
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchIOException
public boolean matchURL(URL url, String postRequest, String regex, Map<String,String> headers) throws IOException
matchURL
in class HttpTransport
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchheaders
- The request headersIOException
public boolean matchURL(String url, String postRequest, String regex) throws IOException
matchURL
in class HttpTransport
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchIOException
public boolean matchURL(String url, String postRequest, String regex, Map<String,String> headers) throws IOException
matchURL
in class HttpTransport
url
- The source of the datapostRequest
- The post request stringregex
- The regular expression to matchheaders
- The request headersIOException
public String[] getCookieValuesByName(String name)
getCookieValuesByName
in class HttpTransport
name
- The cookie namepublic String[] getResponseHeader(String name)
getResponseHeader
in class HttpTransport
name
- The response header field of interestpublic String dumpResponseHeaders()
dumpResponseHeaders
in class HttpTransport
public int getResponseCode()
getResponseCode
in class HttpTransport