public abstract class ContentCoding extends Object implements UrlConnector
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.
Modifier and Type | Field and Description |
---|---|
static String |
ACCEPT_ENCODING
Name of HTTP request header to request coded response ("Accept-Encoding").
|
static String |
CONTENT_ENCODING
Name of HTTP response header to mark coded response ("Content-Encoding").
|
static ContentCoding |
GZIP
Gzip encoding is requested.
|
static ContentCoding |
NONE
No encoding is requested.
|
Modifier | Constructor and Description |
---|---|
protected |
ContentCoding()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
connect(HttpURLConnection hconn)
Opens communication to an HTTP resource.
|
abstract InputStream |
getErrorStream(URLConnection conn)
Returns the error stream response from the given connection,
which was prepared using this object's
prepareRequest
method. |
abstract InputStream |
getInputStream(URLConnection conn)
Returns the input stream response from the given connection,
which was prepared using this object's
prepareRequest
method. |
URLConnection |
openConnection(URL url)
Convenience method to open a new connection prepared in accordance
with this object's encoding policy.
|
InputStream |
openStream(URL url)
Convenience method to return a byte stream from a given URL
in accordance with this object's encoding policy.
|
InputStream |
openStreamAuth(URL url,
AuthManager authManager)
Convenience method to return a byte stream from a given URL
in accordance with this object's encoding policy and with
authentication and redirects handled by a given AuthManager
(typically
AuthManager.getInstance() ). |
abstract void |
prepareRequest(URLConnection conn)
Sets up request headers for the given connection.
|
public static final ContentCoding NONE
public static final ContentCoding GZIP
public static final String ACCEPT_ENCODING
public static final String CONTENT_ENCODING
public abstract void prepareRequest(URLConnection conn)
conn
- unconnected connectionpublic abstract InputStream getInputStream(URLConnection conn) throws IOException
prepareRequest
method. Any required decoding will have been done transparently.conn
- connectionIOException
URLConnection.getInputStream()
public abstract InputStream getErrorStream(URLConnection conn) throws IOException
prepareRequest
method. Any required decoding will have been done transparently.conn
- connectionIOException
URLConnection.getInputStream()
public URLConnection openConnection(URL url) throws IOException
prepareRequest
.url
- target URLIOException
public InputStream openStream(URL url) throws IOException
url
- target URLIOException
public InputStream openStreamAuth(URL url, AuthManager authManager) throws IOException
AuthManager.getInstance()
).url
- target URLauthManager
- authentication managerIOException
public void connect(HttpURLConnection hconn) throws IOException
UrlConnector
URLConnection.connect()
,
but it may optionally perform other actions as well,
such as configuring the request headers as required
and writing to the connection's output stream,
before returning.
If this object is being used with AuthManager,
it will typically be a good idea to call
setInstanceFollowRedirects(false)
,
since redirection can be handled by AuthManager.
connect
in interface UrlConnector
hconn
- URL connection; on entry connect() has not yet
been called, but on exit it hasIOException
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.