Package org.openstreetmap.josm.tools
Class HttpClient.Response
- java.lang.Object
-
- org.openstreetmap.josm.tools.HttpClient.Response
-
- Direct Known Subclasses:
Http1Client.Http1Response
- Enclosing class:
- HttpClient
public abstract static class HttpClient.Response extends java.lang.Object
A wrapper for the HTTP response.
-
-
Field Summary
Fields Modifier and Type Field Description private ProgressMonitor
monitor
private int
responseCode
private java.lang.String
responseData
private java.lang.String
responseMessage
private boolean
uncompress
private boolean
uncompressAccordingToContentDisposition
-
Constructor Summary
Constructors Modifier Constructor Description protected
Response(ProgressMonitor monitor, int responseCode, java.lang.String responseMessage)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
debugRedirect()
abstract void
disconnect()
Indicates that other requests to the server are unlikely in the near future.java.lang.String
fetchContent()
Fetches the HTTP response as String.java.io.InputStream
getContent()
Returns an input stream that reads from this HTTP connection, or, error stream if the connection failed but the server sent useful data.abstract java.lang.String
getContentEncoding()
Returns theContent-Encoding
header.abstract long
getContentLength()
Returns theContent-Length
header.java.io.BufferedReader
getContentReader()
ReturnsgetContent()
wrapped in a buffered reader.abstract java.lang.String
getContentType()
Returns theContent-Type
header.abstract long
getExpiration()
Returns theExpire
header.abstract java.lang.String
getHeaderField(java.lang.String name)
Returns the value of the named header field.abstract java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getHeaderFields()
Returns an unmodifiable Map mapping header keys to a List of header values.protected abstract java.io.InputStream
getInputStream()
abstract long
getLastModified()
Returns theLast-Modified
header.abstract java.lang.String
getRequestMethod()
Returns the request method.int
getResponseCode()
Gets the response code from this HTTP connection.java.lang.String
getResponseMessage()
Gets the response message from this HTTP connection.abstract java.net.URL
getURL()
Returns the URL.HttpClient.Response
uncompress(boolean uncompress)
Sets whethergetContent()
should uncompress the input stream if necessary.HttpClient.Response
uncompressAccordingToContentDisposition(boolean uncompressAccordingToContentDisposition)
Sets whethergetContent()
should uncompress the input stream according toContent-Disposition
HTTP header.
-
-
-
Field Detail
-
monitor
private final ProgressMonitor monitor
-
responseCode
private final int responseCode
-
responseMessage
private final java.lang.String responseMessage
-
uncompress
private boolean uncompress
-
uncompressAccordingToContentDisposition
private boolean uncompressAccordingToContentDisposition
-
responseData
private java.lang.String responseData
-
-
Constructor Detail
-
Response
protected Response(ProgressMonitor monitor, int responseCode, java.lang.String responseMessage)
-
-
Method Detail
-
debugRedirect
protected final void debugRedirect() throws java.io.IOException
- Throws:
java.io.IOException
-
uncompress
public final HttpClient.Response uncompress(boolean uncompress)
Sets whethergetContent()
should uncompress the input stream if necessary.- Parameters:
uncompress
- whether the input stream should be uncompressed if necessary- Returns:
this
-
uncompressAccordingToContentDisposition
public final HttpClient.Response uncompressAccordingToContentDisposition(boolean uncompressAccordingToContentDisposition)
Sets whethergetContent()
should uncompress the input stream according toContent-Disposition
HTTP header.- Parameters:
uncompressAccordingToContentDisposition
- whether the input stream should be uncompressed according toContent-Disposition
- Returns:
this
- Since:
- 9172
-
getURL
public abstract java.net.URL getURL()
Returns the URL.- Returns:
- the URL
- Since:
- 9172
- See Also:
URLConnection.getURL()
-
getRequestMethod
public abstract java.lang.String getRequestMethod()
Returns the request method.- Returns:
- the HTTP request method
- Since:
- 9172
- See Also:
HttpURLConnection.getRequestMethod()
-
getContent
public final java.io.InputStream getContent() throws java.io.IOException
Returns an input stream that reads from this HTTP connection, or, error stream if the connection failed but the server sent useful data.Note: the return value can be null, if both the input and the error stream are null. Seems to be the case if the OSM server replies a 401 Unauthorized, see #3887
- Returns:
- input or error stream
- Throws:
java.io.IOException
- if any I/O error occurs- See Also:
URLConnection.getInputStream()
,HttpURLConnection.getErrorStream()
-
getInputStream
protected abstract java.io.InputStream getInputStream() throws java.io.IOException
- Throws:
java.io.IOException
-
getContentReader
public final java.io.BufferedReader getContentReader() throws java.io.IOException
ReturnsgetContent()
wrapped in a buffered reader. Detects Unicode charset in use utilizingUTFInputStreamReader
.- Returns:
- buffered reader
- Throws:
java.io.IOException
- if any I/O error occurs
-
fetchContent
public final java.lang.String fetchContent() throws java.io.IOException
Fetches the HTTP response as String.- Returns:
- the response
- Throws:
java.io.IOException
- if any I/O error occurs
-
getResponseCode
public final int getResponseCode()
Gets the response code from this HTTP connection.- Returns:
- HTTP response code
- See Also:
HttpURLConnection.getResponseCode()
-
getResponseMessage
public final java.lang.String getResponseMessage()
Gets the response message from this HTTP connection.- Returns:
- HTTP response message
- Since:
- 9172
- See Also:
HttpURLConnection.getResponseMessage()
-
getContentEncoding
public abstract java.lang.String getContentEncoding()
Returns theContent-Encoding
header.- Returns:
Content-Encoding
HTTP header- See Also:
URLConnection.getContentEncoding()
-
getContentType
public abstract java.lang.String getContentType()
Returns theContent-Type
header.- Returns:
Content-Type
HTTP header- See Also:
URLConnection.getContentType()
-
getExpiration
public abstract long getExpiration()
Returns theExpire
header.- Returns:
Expire
HTTP header- Since:
- 9232
- See Also:
URLConnection.getExpiration()
-
getLastModified
public abstract long getLastModified()
Returns theLast-Modified
header.- Returns:
Last-Modified
HTTP header- Since:
- 9232
- See Also:
URLConnection.getLastModified()
-
getContentLength
public abstract long getContentLength()
Returns theContent-Length
header.- Returns:
Content-Length
HTTP header- See Also:
URLConnection.getContentLengthLong()
-
getHeaderField
public abstract java.lang.String getHeaderField(java.lang.String name)
Returns the value of the named header field.- Parameters:
name
- the name of a header field- Returns:
- the value of the named header field, or
null
if there is no such field in the header - Since:
- 9172
- See Also:
URLConnection.getHeaderField(String)
-
getHeaderFields
public abstract java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaderFields()
Returns an unmodifiable Map mapping header keys to a List of header values. As per RFC 2616, section 4.2 header names are case insensitive, so returned map is also case insensitive- Returns:
- unmodifiable Map mapping header keys to a List of header values
- Since:
- 9232
- See Also:
URLConnection.getHeaderFields()
-
disconnect
public abstract void disconnect()
Indicates that other requests to the server are unlikely in the near future.- See Also:
HttpURLConnection.disconnect()
-
-