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 Object
A wrapper for the HTTP response.
-
-
Field Summary
Fields Modifier and Type Field Description private ProgressMonitor
monitor
private int
responseCode
private String
responseData
private String
responseMessage
private boolean
uncompress
private boolean
uncompressAccordingToContentDisposition
-
Constructor Summary
Constructors Modifier Constructor Description protected
Response(ProgressMonitor monitor, int responseCode, 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.String
fetchContent()
Fetches the HTTP response as String.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 String
getContentEncoding()
Returns theContent-Encoding
header.abstract long
getContentLength()
Returns theContent-Length
header.BufferedReader
getContentReader()
ReturnsgetContent()
wrapped in a buffered reader.abstract String
getContentType()
Returns theContent-Type
header.abstract long
getExpiration()
Returns theExpire
header.abstract String
getHeaderField(String name)
Returns the value of the named header field.abstract Map<String,List<String>>
getHeaderFields()
Returns an unmodifiable Map mapping header keys to a List of header values.protected abstract InputStream
getInputStream()
abstract long
getLastModified()
Returns theLast-Modified
header.abstract String
getRequestMethod()
Returns the request method.int
getResponseCode()
Gets the response code from this HTTP connection.String
getResponseMessage()
Gets the response message from this HTTP connection.abstract 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 String responseMessage
-
uncompress
private boolean uncompress
-
uncompressAccordingToContentDisposition
private boolean uncompressAccordingToContentDisposition
-
responseData
private String responseData
-
-
Constructor Detail
-
Response
protected Response(ProgressMonitor monitor, int responseCode, String responseMessage)
-
-
Method Detail
-
debugRedirect
protected final void debugRedirect() throws IOException
- Throws:
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 URL getURL()
Returns the URL.- Returns:
- the URL
- Since:
- 9172
- See Also:
URLConnection.getURL()
-
getRequestMethod
public abstract String getRequestMethod()
Returns the request method.- Returns:
- the HTTP request method
- Since:
- 9172
- See Also:
HttpURLConnection.getRequestMethod()
-
getContent
public final InputStream getContent() throws 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:
IOException
- if any I/O error occurs- See Also:
URLConnection.getInputStream()
,HttpURLConnection.getErrorStream()
-
getInputStream
protected abstract InputStream getInputStream() throws IOException
- Throws:
IOException
-
getContentReader
public final BufferedReader getContentReader() throws IOException
ReturnsgetContent()
wrapped in a buffered reader. Detects Unicode charset in use utilizingUTFInputStreamReader
.- Returns:
- buffered reader
- Throws:
IOException
- if any I/O error occurs
-
fetchContent
public final String fetchContent() throws IOException
Fetches the HTTP response as String.- Returns:
- the response
- Throws:
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 String getResponseMessage()
Gets the response message from this HTTP connection.- Returns:
- HTTP response message
- Since:
- 9172
- See Also:
HttpURLConnection.getResponseMessage()
-
getContentEncoding
public abstract String getContentEncoding()
Returns theContent-Encoding
header.- Returns:
Content-Encoding
HTTP header- See Also:
URLConnection.getContentEncoding()
-
getContentType
public abstract 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 String getHeaderField(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 Map<String,List<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()
-
-