Class ContentCoding
Two static instances NONE
and GZIP
are provided.
It should be completely safe to use either of these in any context,
since an instance of this class represents only an indication to an
HTTP server that a particular coding scheme is supported by the client.
A service is therefore always at liberty to ignore this hint/request
and provide and unencoded response if, for instance, it does not support
the requested compression scheme. Good practice for use of this class
is therefore probably to use GZIP where the response is expected
to be large and reasonably compressible (a long VOTable is a good
example), and NONE where the response is expected to be short or,
especially, not very gzippable (for instance noisy binary floating
point data, or a byte stream that has already been compressed).
The provided instances also include some logging functionality; information about how many bytes (and where applicable the level of compression) is logged for bytestreams read through these instances. The logging level for this information is currently CONFIG.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Name of HTTP request header to request coded response ("Accept-Encoding").static final String
Name of HTTP response header to mark coded response ("Content-Encoding").static final ContentCoding
Gzip encoding is requested.static final ContentCoding
No encoding is requested. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract InputStream
getErrorStream
(URLConnection conn) Returns the error stream response from the given connection, which was prepared using this object'sprepareRequest
method.abstract InputStream
getInputStream
(URLConnection conn) Returns the input stream response from the given connection, which was prepared using this object'sprepareRequest
method.openConnection
(URL url) Convenience method to open a new connection prepared in accordance with this object's encoding policy.openStream
(URL url) Convenience method to return a byte stream from a given URL in accordance with this object's encoding policy.abstract void
prepareRequest
(URLConnection conn) Sets up request headers for the given connection.
-
Field Details
-
NONE
No encoding is requested. -
GZIP
Gzip encoding is requested. -
ACCEPT_ENCODING
Name of HTTP request header to request coded response ("Accept-Encoding").- See Also:
-
CONTENT_ENCODING
Name of HTTP response header to mark coded response ("Content-Encoding").- See Also:
-
-
Constructor Details
-
ContentCoding
protected ContentCoding()Constructor.
-
-
Method Details
-
prepareRequest
Sets up request headers for the given connection. The connection must not have yet been connected.- Parameters:
conn
- unconnected connection
-
getInputStream
Returns the input stream response from the given connection, which was prepared using this object'sprepareRequest
method. Any required decoding will have been done transparently.- Parameters:
conn
- connection- Returns:
- stream decoded as required
- Throws:
IOException
- See Also:
-
getErrorStream
Returns the error stream response from the given connection, which was prepared using this object'sprepareRequest
method. Any required decoding will have been done transparently.- Parameters:
conn
- connection- Returns:
- stream decoded as required
- Throws:
IOException
- See Also:
-
openConnection
Convenience method to open a new connection prepared in accordance with this object's encoding policy. Opens the connection and callsprepareRequest
.- Parameters:
url
- target URL- Returns:
- prepared connection
- Throws:
IOException
-
openStream
Convenience method to return a byte stream from a given URL in accordance with this object's encoding policy. Opens the connection, prepares the request, and decodes the result.- Parameters:
url
- target URL- Returns:
- unencoded stream from the URL
- Throws:
IOException
-