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 ProgressMonitormonitorprivate intresponseCodeprivate java.lang.StringresponseDataprivate java.lang.StringresponseMessageprivate booleanuncompressprivate booleanuncompressAccordingToContentDisposition
-
Constructor Summary
Constructors Modifier Constructor Description protectedResponse(ProgressMonitor monitor, int responseCode, java.lang.String responseMessage)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voiddebugRedirect()abstract voiddisconnect()Indicates that other requests to the server are unlikely in the near future.java.lang.StringfetchContent()Fetches the HTTP response as String.java.io.InputStreamgetContent()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.StringgetContentEncoding()Returns theContent-Encodingheader.abstract longgetContentLength()Returns theContent-Lengthheader.java.io.BufferedReadergetContentReader()ReturnsgetContent()wrapped in a buffered reader.abstract java.lang.StringgetContentType()Returns theContent-Typeheader.abstract longgetExpiration()Returns theExpireheader.abstract java.lang.StringgetHeaderField(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.InputStreamgetInputStream()abstract longgetLastModified()Returns theLast-Modifiedheader.abstract java.lang.StringgetRequestMethod()Returns the request method.intgetResponseCode()Gets the response code from this HTTP connection.java.lang.StringgetResponseMessage()Gets the response message from this HTTP connection.abstract java.net.URLgetURL()Returns the URL.HttpClient.Responseuncompress(boolean uncompress)Sets whethergetContent()should uncompress the input stream if necessary.HttpClient.ResponseuncompressAccordingToContentDisposition(boolean uncompressAccordingToContentDisposition)Sets whethergetContent()should uncompress the input stream according toContent-DispositionHTTP 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-DispositionHTTP 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-Encodingheader.- Returns:
Content-EncodingHTTP header- See Also:
URLConnection.getContentEncoding()
-
getContentType
public abstract java.lang.String getContentType()
Returns theContent-Typeheader.- Returns:
Content-TypeHTTP header- See Also:
URLConnection.getContentType()
-
getExpiration
public abstract long getExpiration()
Returns theExpireheader.- Returns:
ExpireHTTP header- Since:
- 9232
- See Also:
URLConnection.getExpiration()
-
getLastModified
public abstract long getLastModified()
Returns theLast-Modifiedheader.- Returns:
Last-ModifiedHTTP header- Since:
- 9232
- See Also:
URLConnection.getLastModified()
-
getContentLength
public abstract long getContentLength()
Returns theContent-Lengthheader.- Returns:
Content-LengthHTTP 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
nullif 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()
-
-