mobile/android/thirdparty/ch/boye/httpclientandroidlib/params/HttpConnectionParams.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/params/HttpConnectionParams.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,244 @@
     1.4 +/*
     1.5 + * ====================================================================
     1.6 + * Licensed to the Apache Software Foundation (ASF) under one
     1.7 + * or more contributor license agreements.  See the NOTICE file
     1.8 + * distributed with this work for additional information
     1.9 + * regarding copyright ownership.  The ASF licenses this file
    1.10 + * to you under the Apache License, Version 2.0 (the
    1.11 + * "License"); you may not use this file except in compliance
    1.12 + * with the License.  You may obtain a copy of the License at
    1.13 + *
    1.14 + *   http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + * Unless required by applicable law or agreed to in writing,
    1.17 + * software distributed under the License is distributed on an
    1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    1.19 + * KIND, either express or implied.  See the License for the
    1.20 + * specific language governing permissions and limitations
    1.21 + * under the License.
    1.22 + * ====================================================================
    1.23 + *
    1.24 + * This software consists of voluntary contributions made by many
    1.25 + * individuals on behalf of the Apache Software Foundation.  For more
    1.26 + * information on the Apache Software Foundation, please see
    1.27 + * <http://www.apache.org/>.
    1.28 + *
    1.29 + */
    1.30 +
    1.31 +package ch.boye.httpclientandroidlib.params;
    1.32 +
    1.33 +/**
    1.34 + * Utility class for accessing connection parameters in {@link HttpParams}.
    1.35 + *
    1.36 + * @since 4.0
    1.37 + */
    1.38 +public final class HttpConnectionParams implements CoreConnectionPNames {
    1.39 +
    1.40 +    private HttpConnectionParams() {
    1.41 +        super();
    1.42 +    }
    1.43 +
    1.44 +    /**
    1.45 +     * Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
    1.46 +     * If not set, defaults to <code>0</code>.
    1.47 +     *
    1.48 +     * @param params HTTP parameters.
    1.49 +     * @return SO_TIMEOUT.
    1.50 +     */
    1.51 +    public static int getSoTimeout(final HttpParams params) {
    1.52 +        if (params == null) {
    1.53 +            throw new IllegalArgumentException("HTTP parameters may not be null");
    1.54 +        }
    1.55 +        return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
    1.56 +    }
    1.57 +
    1.58 +    /**
    1.59 +     * Sets value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
    1.60 +     *
    1.61 +     * @param params HTTP parameters.
    1.62 +     * @param timeout SO_TIMEOUT.
    1.63 +     */
    1.64 +    public static void setSoTimeout(final HttpParams params, int timeout) {
    1.65 +        if (params == null) {
    1.66 +            throw new IllegalArgumentException("HTTP parameters may not be null");
    1.67 +        }
    1.68 +        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
    1.69 +
    1.70 +    }
    1.71 +
    1.72 +    /**
    1.73 +     * Obtains value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter.
    1.74 +     * If not set, defaults to <code>false</code>.
    1.75 +     *
    1.76 +     * @param params HTTP parameters.
    1.77 +     * @return SO_REUSEADDR.
    1.78 +     *
    1.79 +     * @since 4.1
    1.80 +     */
    1.81 +    public static boolean getSoReuseaddr(final HttpParams params) {
    1.82 +        if (params == null) {
    1.83 +            throw new IllegalArgumentException("HTTP parameters may not be null");
    1.84 +        }
    1.85 +        return params.getBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, false);
    1.86 +    }
    1.87 +
    1.88 +    /**
    1.89 +     * Sets value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter.
    1.90 +     *
    1.91 +     * @param params HTTP parameters.
    1.92 +     * @param reuseaddr SO_REUSEADDR.
    1.93 +     *
    1.94 +     * @since 4.1
    1.95 +     */
    1.96 +    public static void setSoReuseaddr(final HttpParams params, boolean reuseaddr) {
    1.97 +        if (params == null) {
    1.98 +            throw new IllegalArgumentException("HTTP parameters may not be null");
    1.99 +        }
   1.100 +        params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, reuseaddr);
   1.101 +    }
   1.102 +
   1.103 +    /**
   1.104 +     * Obtains value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
   1.105 +     * If not set, defaults to <code>true</code>.
   1.106 +     *
   1.107 +     * @param params HTTP parameters.
   1.108 +     * @return Nagle's algorithm flag
   1.109 +     */
   1.110 +    public static boolean getTcpNoDelay(final HttpParams params) {
   1.111 +        if (params == null) {
   1.112 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.113 +        }
   1.114 +        return params.getBooleanParameter
   1.115 +            (CoreConnectionPNames.TCP_NODELAY, true);
   1.116 +    }
   1.117 +
   1.118 +    /**
   1.119 +     * Sets value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
   1.120 +     *
   1.121 +     * @param params HTTP parameters.
   1.122 +     * @param value Nagle's algorithm flag
   1.123 +     */
   1.124 +    public static void setTcpNoDelay(final HttpParams params, boolean value) {
   1.125 +        if (params == null) {
   1.126 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.127 +        }
   1.128 +        params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, value);
   1.129 +    }
   1.130 +
   1.131 +    /**
   1.132 +     * Obtains value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
   1.133 +     * parameter. If not set, defaults to <code>-1</code>.
   1.134 +     *
   1.135 +     * @param params HTTP parameters.
   1.136 +     * @return socket buffer size
   1.137 +     */
   1.138 +    public static int getSocketBufferSize(final HttpParams params) {
   1.139 +        if (params == null) {
   1.140 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.141 +        }
   1.142 +        return params.getIntParameter
   1.143 +            (CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1);
   1.144 +    }
   1.145 +
   1.146 +    /**
   1.147 +     * Sets value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
   1.148 +     * parameter.
   1.149 +     *
   1.150 +     * @param params HTTP parameters.
   1.151 +     * @param size socket buffer size
   1.152 +     */
   1.153 +    public static void setSocketBufferSize(final HttpParams params, int size) {
   1.154 +        if (params == null) {
   1.155 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.156 +        }
   1.157 +        params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, size);
   1.158 +    }
   1.159 +
   1.160 +    /**
   1.161 +     * Obtains value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
   1.162 +     * If not set, defaults to <code>-1</code>.
   1.163 +     *
   1.164 +     * @param params HTTP parameters.
   1.165 +     * @return SO_LINGER.
   1.166 +     */
   1.167 +    public static int getLinger(final HttpParams params) {
   1.168 +        if (params == null) {
   1.169 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.170 +        }
   1.171 +        return params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1);
   1.172 +    }
   1.173 +
   1.174 +    /**
   1.175 +     * Sets value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
   1.176 +     *
   1.177 +     * @param params HTTP parameters.
   1.178 +     * @param value SO_LINGER.
   1.179 +     */
   1.180 +    public static void setLinger(final HttpParams params, int value) {
   1.181 +        if (params == null) {
   1.182 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.183 +        }
   1.184 +        params.setIntParameter(CoreConnectionPNames.SO_LINGER, value);
   1.185 +    }
   1.186 +
   1.187 +    /**
   1.188 +     * Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
   1.189 +     * parameter. If not set, defaults to <code>0</code>.
   1.190 +     *
   1.191 +     * @param params HTTP parameters.
   1.192 +     * @return connect timeout.
   1.193 +     */
   1.194 +    public static int getConnectionTimeout(final HttpParams params) {
   1.195 +        if (params == null) {
   1.196 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.197 +        }
   1.198 +        return params.getIntParameter
   1.199 +            (CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
   1.200 +    }
   1.201 +
   1.202 +    /**
   1.203 +     * Sets value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
   1.204 +     * parameter.
   1.205 +     *
   1.206 +     * @param params HTTP parameters.
   1.207 +     * @param timeout connect timeout.
   1.208 +     */
   1.209 +    public static void setConnectionTimeout(final HttpParams params, int timeout) {
   1.210 +        if (params == null) {
   1.211 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.212 +        }
   1.213 +        params.setIntParameter
   1.214 +            (CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
   1.215 +    }
   1.216 +
   1.217 +    /**
   1.218 +     * Obtains value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
   1.219 +     * parameter. If not set, defaults to <code>true</code>.
   1.220 +     *
   1.221 +     * @param params HTTP parameters.
   1.222 +     * @return stale connection check flag.
   1.223 +     */
   1.224 +    public static boolean isStaleCheckingEnabled(final HttpParams params) {
   1.225 +        if (params == null) {
   1.226 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.227 +        }
   1.228 +        return params.getBooleanParameter
   1.229 +            (CoreConnectionPNames.STALE_CONNECTION_CHECK, true);
   1.230 +    }
   1.231 +
   1.232 +    /**
   1.233 +     * Sets value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
   1.234 +     * parameter.
   1.235 +     *
   1.236 +     * @param params HTTP parameters.
   1.237 +     * @param value stale connection check flag.
   1.238 +     */
   1.239 +    public static void setStaleCheckingEnabled(final HttpParams params, boolean value) {
   1.240 +        if (params == null) {
   1.241 +            throw new IllegalArgumentException("HTTP parameters may not be null");
   1.242 +        }
   1.243 +        params.setBooleanParameter
   1.244 +            (CoreConnectionPNames.STALE_CONNECTION_CHECK, value);
   1.245 +    }
   1.246 +
   1.247 +}

mercurial