Ignore:
Timestamp:
2015-12-27T15:39:07+01:00 (5 years ago)
Author:
Don-vip
Message:

see #12231 - javadoc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r9174 r9177  
    2626/**
    2727 * Provides a uniform access for a HTTP/HTTPS server. This class should be used in favour of {@link HttpURLConnection}.
     28 * @since 9168
    2829 */
    2930public final class HttpClient {
     
    4647    }
    4748
     49    /**
     50     * Opens the HTTP connection.
     51     * @return HTTP response
     52     * @throws IOException if any I/O error occurs
     53     */
    4854    public Response connect() throws IOException {
    4955        final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     
    146152        }
    147153
     154        /**
     155         * Sets whether {@link #getContent()} should uncompress the input stream according to {@code Content-Disposition}
     156         * HTTP header.
     157         * @param uncompressAccordingToContentDisposition whether the input stream should be uncompressed according to
     158         * {@code Content-Disposition}
     159         * @return {@code this}
     160         */
    148161        public Response uncompressAccordingToContentDisposition(boolean uncompressAccordingToContentDisposition) {
    149162            this.uncompressAccordingToContentDisposition = uncompressAccordingToContentDisposition;
     
    152165
    153166        /**
     167         * Returns the URL.
     168         * @return the URL
    154169         * @see HttpURLConnection#getURL()
    155170         */
     
    159174
    160175        /**
     176         * Returns the request method.
     177         * @return the HTTP request method
    161178         * @see HttpURLConnection#getRequestMethod()
    162179         */
     
    168185         * Returns an input stream that reads from this HTTP connection, or,
    169186         * error stream if the connection failed but the server sent useful data.
    170          *
     187         * <p>
    171188         * Note: the return value can be null, if both the input and the error stream are null.
    172189         * Seems to be the case if the OSM server replies a 401 Unauthorized, see #3887
     190         * @return input or error stream
     191         * @throws IOException if any I/O error occurs
    173192         *
    174193         * @see HttpURLConnection#getInputStream()
     
    205224         *
    206225         * Detects Unicode charset in use utilizing {@link UTFInputStreamReader}.
     226         * @return buffered reader
     227         * @throws IOException if any I/O error occurs
    207228         */
    208229        public BufferedReader getContentReader() throws IOException {
     
    215236         * Fetches the HTTP response as String.
    216237         * @return the response
    217          */
     238         * @throws IOException if any I/O error occurs
     239         */
     240        @SuppressWarnings("resource")
    218241        public String fetchContent() throws IOException {
    219242            try (Scanner scanner = new Scanner(getContentReader()).useDelimiter("\\A")) {
     
    224247        /**
    225248         * Gets the response code from this HTTP connection.
     249         * @return HTTP response code
    226250         *
    227251         * @see HttpURLConnection#getResponseCode()
     
    233257        /**
    234258         * Gets the response message from this HTTP connection.
     259         * @return HTTP response message
    235260         *
    236261         * @see HttpURLConnection#getResponseMessage()
     
    242267        /**
    243268         * Returns the {@code Content-Encoding} header.
     269         * @return {@code Content-Encoding} HTTP header
    244270         */
    245271        public String getContentEncoding() {
     
    249275        /**
    250276         * Returns the {@code Content-Type} header.
     277         * @return {@code Content-Type} HTTP header
    251278         */
    252279        public String getContentType() {
     
    256283        /**
    257284         * Returns the {@code Content-Length} header.
     285         * @return {@code Content-Length} HTTP header
    258286         */
    259287        public long getContentLength() {
     
    262290
    263291        /**
     292         * Returns the value of the named header field.
     293         * @param name the name of a header field
     294         * @return the value of the named header field, or {@code null} if there is no such field in the header
    264295         * @see HttpURLConnection#getHeaderField(String)
    265296         */
     
    269300
    270301        /**
     302         * Returns the list of Strings that represents the named header field values.
     303         * @param name the name of a header field
     304         * @return unmodifiable List of Strings that represents the corresponding field values
    271305         * @see HttpURLConnection#getHeaderFields()
    272306         */
     
    316350    /**
    317351     * Returns the URL set for this connection.
     352     * @return the URL
    318353     * @see #create(URL)
    319354     * @see #create(URL, String)
     
    325360    /**
    326361     * Returns the request method set for this connection.
     362     * @return the HTTP request method
    327363     * @see #create(URL, String)
    328364     */
     
    333369    /**
    334370     * Returns the set value for the given {@code header}.
     371     * @param header HTTP header name
     372     * @return HTTP header value
    335373     */
    336374    public String getRequestHeader(String header) {
     
    364402
    365403    /**
     404     * Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced
     405     * by this URLConnection. If the timeout expires before the connection can be established, a
     406     * {@link java.net.SocketTimeoutException} is raised. A timeout of zero is interpreted as an infinite timeout.
     407     * @param connectTimeout an {@code int} that specifies the connect timeout value in milliseconds
    366408     * @return {@code this}
    367409     * @see HttpURLConnection#setConnectTimeout(int)
     
    373415
    374416    /**
     417     * Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from
     418     * input stream when a connection is established to a resource. If the timeout expires before there is data available for
     419     * read, a {@link java.net.SocketTimeoutException} is raised. A timeout of zero is interpreted as an infinite timeout.
     420     * @param readTimeout an {@code int} that specifies the read timeout value in milliseconds
    375421     * @return {@code this}
    376422     * @see HttpURLConnection#setReadTimeout(int) (int)
    377423     */
    378 
    379424    public HttpClient setReadTimeout(int readTimeout) {
    380425        this.readTimeout = readTimeout;
     
    384429    /**
    385430     * Sets the {@code Accept} header.
     431     * @param accept header value
    386432     *
    387433     * @return {@code this}
     
    393439    /**
    394440     * Sets the request body for {@code PUT}/{@code POST} requests.
     441     * @param requestBody request body
    395442     *
    396443     * @return {@code this}
     
    403450    /**
    404451     * Sets the {@code If-Modified-Since} header.
     452     * @param ifModifiedSince header value
    405453     *
    406454     * @return {@code this}
     
    416464     * Set {@code maxRedirects} to {@code -1} in order to ignore redirects, i.e.,
    417465     * to not throw an {@link IOException} in {@link #connect()}.
     466     * @param maxRedirects header value
    418467     *
    419468     * @return {@code this}
     
    426475    /**
    427476     * Sets an arbitrary HTTP header.
     477     * @param key header name
     478     * @param value header value
    428479     *
    429480     * @return {@code this}
     
    436487    /**
    437488     * Sets arbitrary HTTP headers.
     489     * @param headers HTTP headers
    438490     *
    439491     * @return {@code this}
     
    446498    /**
    447499     * Sets a reason to show on console. Can be {@code null} if no reason is given.
     500     * @param reasonForRequest Reason to show
     501     * @return {@code this}
    448502     */
    449503    public HttpClient setReasonForRequest(String reasonForRequest) {
     
    464518        }
    465519    }
    466 
    467520}
Note: See TracChangeset for help on using the changeset viewer.