Java 类org.apache.http.util.Args 实例源码

项目:Elasticsearch    文件:LocalRestRequest.java   
public void setContent(final String source, final ContentType contentType) throws UnsupportedCharsetException {
    Args.notNull(source, "Source string");
    Charset charset = contentType != null?contentType.getCharset():null;
    if(charset == null) {
        charset = HTTP.DEF_CONTENT_CHARSET;
    }

    try {
        this.content = new BytesArray(source.getBytes(charset.name()));
    } catch (UnsupportedEncodingException var) {
        throw new UnsupportedCharsetException(charset.name());
    }

    if(contentType != null) {
        addHeader("Content-Type", contentType.toString());
    }
}
项目:purecloud-iot    文件:DefaultClientConnectionOperator.java   
@Override
public void updateSecureConnection(
        final OperatedClientConnection conn,
        final HttpHost target,
        final HttpContext context,
        final HttpParams params) throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(target, "Target host");
    Args.notNull(params, "Parameters");
    Asserts.check(conn.isOpen(), "Connection must be open");

    final SchemeRegistry registry = getSchemeRegistry(context);
    final Scheme schm = registry.getScheme(target.getSchemeName());
    Asserts.check(schm.getSchemeSocketFactory() instanceof SchemeLayeredSocketFactory,
        "Socket factory must implement SchemeLayeredSocketFactory");
    final SchemeLayeredSocketFactory lsf = (SchemeLayeredSocketFactory) schm.getSchemeSocketFactory();
    final Socket sock = lsf.createLayeredSocket(
            conn.getSocket(), target.getHostName(), schm.resolvePort(target.getPort()), params);
    prepareSocket(sock, context, params);
    conn.update(sock, target, lsf.isSecure(sock), params);
}
项目:axon-eventstore    文件:DefaultConnectionKeepAliveStrategy.java   
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
   Args.notNull(response, "HTTP response");
   final HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
   while (it.hasNext()) {
      final HeaderElement he = it.nextElement();
      final String param = he.getName();
      final String value = he.getValue();
      if (value != null && param.equalsIgnoreCase("timeout")) {
         try {
            return Long.parseLong(value) * 1000;
         } catch (final NumberFormatException ignore) {
            LOGGER.warn("keep alive timeout could not be parsed: param=" + param + " value:" + value, ignore);
         }
      }
   }
   return DEFAULT_KEEP_ALIVE;
}
项目:purecloud-iot    文件:BasicRouteDirector.java   
/**
 * Provides the next step.
 *
 * @param plan      the planned route
 * @param fact      the currently established route, or
 *                  {@code null} if nothing is established
 *
 * @return  one of the constants defined in this class, indicating
 *          either the next step to perform, or success, or failure.
 *          0 is for success, a negative value for failure.
 */
@Override
public int nextStep(final RouteInfo plan, final RouteInfo fact) {
    Args.notNull(plan, "Planned route");

    int step = UNREACHABLE;

    if ((fact == null) || (fact.getHopCount() < 1)) {
        step = firstStep(plan);
    } else if (plan.getHopCount() > 1) {
        step = proxiedStep(plan, fact);
    } else {
        step = directStep(plan, fact);
    }

    return step;

}
项目:purecloud-iot    文件:Scheme.java   
/**
 * Creates a new scheme.
 * Whether the created scheme allows for layered connections
 * depends on the class of {@code factory}.
 *
 * @param name      the scheme name, for example "http".
 *                  The name will be converted to lowercase.
 * @param factory   the factory for creating sockets for communication
 *                  with this scheme
 * @param port      the default port for this scheme
 *
 * @deprecated (4.1)  Use {@link #Scheme(String, int, SchemeSocketFactory)}
 */
@Deprecated
public Scheme(final String name,
              final SocketFactory factory,
              final int port) {

    Args.notNull(name, "Scheme name");
    Args.notNull(factory, "Socket factory");
    Args.check(port > 0 && port <= 0xffff, "Port is invalid");

    this.name = name.toLowerCase(Locale.ENGLISH);
    if (factory instanceof LayeredSocketFactory) {
        this.socketFactory = new SchemeLayeredSocketFactoryAdaptor(
                (LayeredSocketFactory) factory);
        this.layered = true;
    } else {
        this.socketFactory = new SchemeSocketFactoryAdaptor(factory);
        this.layered = false;
    }
    this.defaultPort = port;
}
项目:remote-files-sync    文件:DefaultConnectionKeepAliveStrategyHC4.java   
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
    Args.notNull(response, "HTTP response");
    final HeaderElementIterator it = new BasicHeaderElementIterator(
            response.headerIterator(HTTP.CONN_KEEP_ALIVE));
    while (it.hasNext()) {
        final HeaderElement he = it.nextElement();
        final String param = he.getName();
        final String value = he.getValue();
        if (value != null && param.equalsIgnoreCase("timeout")) {
            try {
                return Long.parseLong(value) * 1000;
            } catch(final NumberFormatException ignore) {
            }
        }
    }
    return -1;
}
项目:purecloud-iot    文件:CacheConfig.java   
public static Builder copy(final CacheConfig config) {
    Args.notNull(config, "Cache config");
    return new Builder()
        .setMaxObjectSize(config.getMaxObjectSize())
        .setMaxCacheEntries(config.getMaxCacheEntries())
        .setMaxUpdateRetries(config.getMaxUpdateRetries())
        .setHeuristicCachingEnabled(config.isHeuristicCachingEnabled())
        .setHeuristicCoefficient(config.getHeuristicCoefficient())
        .setHeuristicDefaultLifetime(config.getHeuristicDefaultLifetime())
        .setSharedCache(config.isSharedCache())
        .setAsynchronousWorkersMax(config.getAsynchronousWorkersMax())
        .setAsynchronousWorkersCore(config.getAsynchronousWorkersCore())
        .setAsynchronousWorkerIdleLifetimeSecs(config.getAsynchronousWorkerIdleLifetimeSecs())
        .setRevalidationQueueSize(config.getRevalidationQueueSize())
        .setNeverCacheHTTP10ResponsesWithQueryString(config.isNeverCacheHTTP10ResponsesWithQuery());
}
项目:remote-files-sync    文件:RFC2965DomainAttributeHandlerHC4.java   
/**
 * Match cookie domain attribute.
 */
public boolean match(final Cookie cookie, final CookieOrigin origin) {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    final String host = origin.getHost().toLowerCase(Locale.ENGLISH);
    final String cookieDomain = cookie.getDomain();

    // The effective host name MUST domain-match the Domain
    // attribute of the cookie.
    if (!domainMatch(host, cookieDomain)) {
        return false;
    }
    // effective host name minus domain must not contain any dots
    final String effectiveHostWithoutDomain = host.substring(
            0, host.length() - cookieDomain.length());
    return effectiveHostWithoutDomain.indexOf('.') == -1;
}
项目:remote-files-sync    文件:AbstractConnPool.java   
/**
 * Closes connections that have been idle longer than the given period
 * of time and evicts them from the pool.
 *
 * @param idletime maximum idle time.
 * @param tunit time unit.
 */
public void closeIdle(final long idletime, final TimeUnit tunit) {
    Args.notNull(tunit, "Time unit");
    long time = tunit.toMillis(idletime);
    if (time < 0) {
        time = 0;
    }
    final long deadline = System.currentTimeMillis() - time;
    enumAvailable(new PoolEntryCallback<T, C>() {

        public void process(final PoolEntry<T, C> entry) {
            if (entry.getUpdated() <= deadline) {
                entry.close();
            }
        }

    });
}
项目:purecloud-iot    文件:AuthenticationStrategyImpl.java   
@Override
public void authSucceeded(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    Args.notNull(authhost, "Host");
    Args.notNull(authScheme, "Auth scheme");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    if (isCachable(authScheme)) {
        AuthCache authCache = clientContext.getAuthCache();
        if (authCache == null) {
            authCache = new BasicAuthCache();
            clientContext.setAuthCache(authCache);
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Caching '" + authScheme.getSchemeName() +
                    "' auth scheme for " + authhost);
        }
        authCache.put(authhost, authScheme);
    }
}
项目:purecloud-iot    文件:AbstractPoolEntry.java   
/**
 * Layers a protocol on top of an established tunnel.
 *
 * @param context   the context for layering
 * @param params    the parameters for layering
 *
 * @throws IOException  in case of a problem
 */
public void layerProtocol(final HttpContext context, final HttpParams params)
    throws IOException {

    //@@@ is context allowed to be null? depends on operator?
    Args.notNull(params, "HTTP parameters");
    Asserts.notNull(this.tracker, "Route tracker");
    Asserts.check(this.tracker.isConnected(), "Connection not open");
    Asserts.check(this.tracker.isTunnelled(), "Protocol layering without a tunnel not supported");
    Asserts.check(!this.tracker.isLayered(), "Multiple protocol layering not supported");
    // - collect the arguments
    // - call the operator
    // - update the tracking data
    // In this order, we can be sure that only a successful
    // layering on top of the connection will be tracked.

    final HttpHost target = tracker.getTargetHost();

    connOperator.updateSecureConnection(this.connection, target,
                                         context, params);

    this.tracker.layerProtocol(this.connection.isSecure());

}
项目:remote-files-sync    文件:BasicHttpClientConnectionManager.java   
public synchronized void closeIdleConnections(final long idletime, final TimeUnit tunit) {
    Args.notNull(tunit, "Time unit");
    if (this.isShutdown.get()) {
        return;
    }
    if (!this.leased) {
        long time = tunit.toMillis(idletime);
        if (time < 0) {
            time = 0;
        }
        final long deadline = System.currentTimeMillis() - time;
        if (this.updated <= deadline) {
            closeConnection();
        }
    }
}
项目:purecloud-iot    文件:PublicSuffixMatcher.java   
/**
 * @since 4.5
 */
public PublicSuffixMatcher(final Collection<PublicSuffixList> lists) {
    Args.notNull(lists,  "Domain suffix lists");
    this.rules = new ConcurrentHashMap<String, DomainType>();
    this.exceptions = new ConcurrentHashMap<String, DomainType>();
    for (final PublicSuffixList list: lists) {
        final DomainType domainType = list.getType();
        final List<String> rules = list.getRules();
        for (final String rule: rules) {
            this.rules.put(rule, domainType);
        }
        final List<String> exceptions = list.getExceptions();
        if (exceptions != null) {
            for (final String exception: exceptions) {
                this.exceptions.put(exception, domainType);
            }
        }
    }
}
项目:ibm-bpm-rest-client    文件:TaskClientImpl.java   
/**
 * {@inheritDoc}
 *
 * @throws IllegalArgumentException {@inheritDoc}
 */
@Override
public RestRootEntity<ServiceData> setTaskData(@Nonnull String tkiid, @Nonnull Map<String, Object> parameters) {
    tkiid = Args.notNull(tkiid, "Task id (tkiid)");
    parameters = Args.notNull(parameters, "Variables (parameters)");
    Args.notEmpty(parameters.keySet(), "Parameters names");
    Args.notEmpty(parameters.values(), "Parameters values");

    Gson gson = new GsonBuilder().setDateFormat(DATE_TIME_FORMAT).create();
    String params = gson.toJson(parameters);

    URI uri = new SafeUriBuilder(rootUri).addPath(tkiid).addParameter(ACTION, ACTION_SET_DATA)
            .addParameter(PARAMS, params).build();

    return makePost(httpClient, httpContext, uri, new TypeToken<RestRootEntity<ServiceData>>() {});
}
项目:purecloud-iot    文件:RFC2965DomainAttributeHandler.java   
/**
 * Parse cookie domain attribute.
 */
@Override
public void parse(
        final SetCookie cookie, final String domain) throws MalformedCookieException {
    Args.notNull(cookie, "Cookie");
    if (domain == null) {
        throw new MalformedCookieException(
                "Missing value for domain attribute");
    }
    if (domain.trim().isEmpty()) {
        throw new MalformedCookieException(
                "Blank value for domain attribute");
    }
    String s = domain;
    s = s.toLowerCase(Locale.ROOT);
    if (!domain.startsWith(".")) {
        // Per RFC 2965 section 3.2.2
        // "... If an explicitly specified value does not start with
        // a dot, the user agent supplies a leading dot ..."
        // That effectively implies that the domain attribute
        // MAY NOT be an IP address of a host name
        s = '.' + s;
    }
    cookie.setDomain(s);
}
项目:remote-files-sync    文件:NetscapeDraftSpecHC4.java   
public List<Header> formatCookies(final List<Cookie> cookies) {
    Args.notEmpty(cookies, "List of cookies");
    final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        final Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        final String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:purecloud-iot    文件:DefaultCookieSpec.java   
@Override
public List<Header> formatCookies(final List<Cookie> cookies) {
    Args.notNull(cookies, "List of cookies");
    int version = Integer.MAX_VALUE;
    boolean isSetCookie2 = true;
    for (final Cookie cookie: cookies) {
        if (!(cookie instanceof SetCookie2)) {
            isSetCookie2 = false;
        }
        if (cookie.getVersion() < version) {
            version = cookie.getVersion();
        }
    }
    if (version > 0) {
        if (isSetCookie2) {
            return strict.formatCookies(cookies);
        } else {
            return obsoleteStrict.formatCookies(cookies);
        }
    } else {
        return netscapeDraft.formatCookies(cookies);
    }
}
项目:purecloud-iot    文件:RequestExpectContinue.java   
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    if (!request.containsHeader(HTTP.EXPECT_DIRECTIVE)) {
        if (request instanceof HttpEntityEnclosingRequest) {
            final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
            final HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
            // Do not send the expect header if request body is known to be empty
            if (entity != null
                    && entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
                final HttpClientContext clientContext = HttpClientContext.adapt(context);
                final RequestConfig config = clientContext.getRequestConfig();
                if (config.isExpectContinueEnabled()) {
                    request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
                }
            }
        }
    }
}
项目:remote-files-sync    文件:RFC2965PortAttributeHandlerHC4.java   
/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
public boolean match(final Cookie cookie, final CookieOrigin origin) {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    final int port = origin.getPort();
    if (cookie instanceof ClientCookie
            && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
        if (cookie.getPorts() == null) {
            // Invalid cookie state: port not specified
            return false;
        }
        if (!portMatch(port, cookie.getPorts())) {
            return false;
        }
    }
    return true;
}
项目:datarouter    文件:DatarouterHttpRequest.java   
/**
 * Expects query string parameters to already be UTF-8 encoded. See AdvancedStringTool.makeUrlParameters().
 * URL fragment is stripped from URL when sent to server.
 */
public DatarouterHttpRequest(HttpRequestMethod method, final String url, boolean retrySafe){
    Args.notBlank(url, "request url");
    Args.notNull(method, "http method");

    String fragment;
    int fragmentIndex = url.indexOf('#');
    if(fragmentIndex > 0 && fragmentIndex < url.length() - 1){
        fragment = url.substring(fragmentIndex + 1);
    }else{
        fragmentIndex = url.length();
        fragment = "";
    }
    String path = url.substring(0, fragmentIndex);

    Map<String,List<String>> queryParams;
    int queryIndex = path.indexOf("?");
    if(queryIndex > 0){
        queryParams = extractQueryParams(path.substring(queryIndex + 1));
        path = path.substring(0, queryIndex);
    }else{
        queryParams = new LinkedHashMap<>();
    }
    this.method = method;
    this.path = path;
    this.retrySafe = retrySafe;
    this.fragment = fragment;
    this.headers = new HashMap<>();
    this.queryParams = queryParams;
    this.postParams = new HashMap<>();
    this.cookies = new ArrayList<>();
}
项目:purecloud-iot    文件:MinimalHttpClient.java   
public MinimalHttpClient(
        final HttpClientConnectionManager connManager) {
    super();
    this.connManager = Args.notNull(connManager, "HTTP connection manager");
    this.requestExecutor = new MinimalClientExec(
            new HttpRequestExecutor(),
            connManager,
            DefaultConnectionReuseStrategy.INSTANCE,
            DefaultConnectionKeepAliveStrategy.INSTANCE);
    this.params = new BasicHttpParams();
}
项目:purecloud-iot    文件:ExponentialBackOffSchedulingStrategy.java   
ExponentialBackOffSchedulingStrategy(
        final ScheduledExecutorService executor,
        final long backOffRate,
        final long initialExpiryInMillis,
        final long maxExpiryInMillis) {
    this.executor = Args.notNull(executor, "Executor");
    this.backOffRate = Args.notNegative(backOffRate, "BackOffRate");
    this.initialExpiryInMillis = Args.notNegative(initialExpiryInMillis, "InitialExpiryInMillis");
    this.maxExpiryInMillis = Args.notNegative(maxExpiryInMillis, "MaxExpiryInMillis");
}
项目:purecloud-iot    文件:Proxies.java   
public static CloseableHttpResponse enhanceResponse(final HttpResponse original) {
    Args.notNull(original, "HTTP response");
    if (original instanceof CloseableHttpResponse) {
        return (CloseableHttpResponse) original;
    } else {
        return (CloseableHttpResponse) Proxy.newProxyInstance(
                ResponseProxyHandler.class.getClassLoader(),
                new Class<?>[] { CloseableHttpResponse.class },
                new ResponseProxyHandler(original));
    }
}
项目:remote-files-sync    文件:BasicHttpEntityHC4.java   
public void writeTo(final OutputStream outstream) throws IOException {
    Args.notNull(outstream, "Output stream");
    final InputStream instream = getContent();
    try {
        int l;
        final byte[] tmp = new byte[OUTPUT_BUFFER_SIZE];
        while ((l = instream.read(tmp)) != -1) {
            outstream.write(tmp, 0, l);
        }
    } finally {
        instream.close();
    }
}
项目:remote-files-sync    文件:ByteArrayEntityHC4.java   
/**
 * @since 4.2
 */
@SuppressWarnings("deprecation")
public ByteArrayEntityHC4(final byte[] b, final ContentType contentType) {
    super();
    Args.notNull(b, "Source byte array");
    this.content = b;
    this.b = b;
    this.off = 0;
    this.len = this.b.length;
    if (contentType != null) {
        setContentType(contentType.toString());
    }
}
项目:purecloud-iot    文件:ConnManagerParams.java   
/**
 * Returns lookup interface for maximum number of connections allowed per route.
 *
 * @param params HTTP parameters
 *
 * @return lookup interface for maximum number of connections allowed per route.
 */
public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
    Args.notNull(params, "HTTP parameters");
    ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE);
    if (connPerRoute == null) {
        connPerRoute = DEFAULT_CONN_PER_ROUTE;
    }
    return connPerRoute;
}
项目:remote-files-sync    文件:SerializableEntityHC4.java   
/**
 * Creates new instance of this class.
 *
 * @param ser input
 * @param bufferize tells whether the content should be
 *        stored in an internal buffer
 * @throws IOException in case of an I/O error
 */
public SerializableEntityHC4(final Serializable ser, final boolean bufferize) throws IOException {
    super();
    Args.notNull(ser, "Source object");
    if (bufferize) {
        createBytes(ser);
    } else {
        this.objRef = ser;
    }
}
项目:purecloud-iot    文件:SSLConnectionSocketFactory.java   
@Override
public Socket connectSocket(
        final int connectTimeout,
        final Socket socket,
        final HttpHost host,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpContext context) throws IOException {
    Args.notNull(host, "HTTP host");
    Args.notNull(remoteAddress, "Remote address");
    final Socket sock = socket != null ? socket : createSocket(context);
    if (localAddress != null) {
        sock.bind(localAddress);
    }
    try {
        if (connectTimeout > 0 && sock.getSoTimeout() == 0) {
            sock.setSoTimeout(connectTimeout);
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connecting socket to " + remoteAddress + " with timeout " + connectTimeout);
        }
        sock.connect(remoteAddress, connectTimeout);
    } catch (final IOException ex) {
        try {
            sock.close();
        } catch (final IOException ignore) {
        }
        throw ex;
    }
    // Setup SSL layering if necessary
    if (sock instanceof SSLSocket) {
        final SSLSocket sslsock = (SSLSocket) sock;
        this.log.debug("Starting handshake");
        sslsock.startHandshake();
        verifyHostname(sslsock, host.getHostName());
        return sock;
    } else {
        return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
    }
}
项目:purecloud-iot    文件:BackoffStrategyExec.java   
public BackoffStrategyExec(
        final ClientExecChain requestExecutor,
        final ConnectionBackoffStrategy connectionBackoffStrategy,
        final BackoffManager backoffManager) {
    super();
    Args.notNull(requestExecutor, "HTTP client request executor");
    Args.notNull(connectionBackoffStrategy, "Connection backoff strategy");
    Args.notNull(backoffManager, "Backoff manager");
    this.requestExecutor = requestExecutor;
    this.connectionBackoffStrategy = connectionBackoffStrategy;
    this.backoffManager = backoffManager;
}
项目:remote-files-sync    文件:PoolEntry.java   
public synchronized void updateExpiry(final long time, final TimeUnit tunit) {
    Args.notNull(tunit, "Time unit");
    this.updated = System.currentTimeMillis();
    final long newExpiry;
    if (time > 0) {
        newExpiry = this.updated + tunit.toMillis(time);
    } else {
        newExpiry = Long.MAX_VALUE;
    }
    this.expiry = Math.min(newExpiry, this.validUnit);
}
项目:purecloud-iot    文件:BrowserCompatSpec.java   
@Override
public List<Header> formatCookies(final List<Cookie> cookies) {
    Args.notEmpty(cookies, "List of cookies");
    final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        final Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        final String cookieName = cookie.getName();
        final String cookieValue = cookie.getValue();
        if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) {
            BasicHeaderValueFormatter.INSTANCE.formatHeaderElement(
                    buffer,
                    new BasicHeaderElement(cookieName, cookieValue),
                    false);
        } else {
            // Netscape style cookies do not support quoted values
            buffer.append(cookieName);
            buffer.append("=");
            if (cookieValue != null) {
                buffer.append(cookieValue);
            }
        }
    }
    final List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
项目:purecloud-iot    文件:RFC6265CookieSpec.java   
@Override
public final boolean match(final Cookie cookie, final CookieOrigin origin) {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    for (final CookieAttributeHandler handler: this.attribHandlers) {
        if (!handler.match(cookie, origin)) {
            return false;
        }
    }
    return true;
}
项目:remote-files-sync    文件:AbstractConnPool.java   
public void setDefaultMaxPerRoute(final int max) {
    Args.notNegative(max, "Max per route value");
    this.lock.lock();
    try {
        this.defaultMaxPerRoute = max;
    } finally {
        this.lock.unlock();
    }
}
项目:purecloud-iot    文件:ConnPoolByRoute.java   
/**
 * Closes idle connections.
 *
 * @param idletime  the time the connections should have been idle
 *                  in order to be closed now
 * @param tunit     the unit for the {@code idletime}
 */
@Override
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
    Args.notNull(tunit, "Time unit");
    final long t = idletime > 0 ? idletime : 0;
    if (log.isDebugEnabled()) {
        log.debug("Closing connections idle longer than "  + t + " " + tunit);
    }
    // the latest time for which connections will be closed
    final long deadline = System.currentTimeMillis() - tunit.toMillis(t);
    poolLock.lock();
    try {
        final Iterator<BasicPoolEntry>  iter = freeConnections.iterator();
        while (iter.hasNext()) {
            final BasicPoolEntry entry = iter.next();
            if (entry.getUpdated() <= deadline) {
                if (log.isDebugEnabled()) {
                    log.debug("Closing connection last used @ " + new Date(entry.getUpdated()));
                }
                iter.remove();
                deleteEntry(entry);
            }
        }
    } finally {
        poolLock.unlock();
    }
}
项目:purecloud-iot    文件:RequestBuilder.java   
public RequestBuilder addParameter(final NameValuePair nvp) {
    Args.notNull(nvp, "Name value pair");
    if (parameters == null) {
        parameters = new LinkedList<NameValuePair>();
    }
    parameters.add(nvp);
    return this;
}
项目:remote-files-sync    文件:BasicLineParserHC4.java   
public static
    ProtocolVersion parseProtocolVersion(final String value,
                                         final LineParser parser) throws ParseException {
    Args.notNull(value, "Value");

    final CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    final ParserCursor cursor = new ParserCursor(0, value.length());
    return (parser != null ? parser : BasicLineParserHC4.INSTANCE)
            .parseProtocolVersion(buffer, cursor);
}
项目:remote-files-sync    文件:BasicLineParserHC4.java   
public static
    RequestLine parseRequestLine(final String value,
                                 final LineParser parser) throws ParseException {
    Args.notNull(value, "Value");

    final CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    final ParserCursor cursor = new ParserCursor(0, value.length());
    return (parser != null ? parser : BasicLineParserHC4.INSTANCE)
        .parseRequestLine(buffer, cursor);
}
项目:remote-files-sync    文件:AbstractMessageParserHC4.java   
/**
 * Creates new instance of AbstractMessageParserHC4.
 *
 * @param buffer the session input buffer.
 * @param lineParser the line parser. If <code>null</code> {@link BasicLineParserHC4#INSTANCE}
 *   will be used.
 * @param constraints the message constraints. If <code>null</code>
 *   {@link MessageConstraints#DEFAULT} will be used.
 *
 * @since 4.3
 */
public AbstractMessageParserHC4(
        final SessionInputBuffer buffer,
        final LineParser lineParser,
        final MessageConstraints constraints) {
    super();
    this.sessionBuffer = Args.notNull(buffer, "Session input buffer");
    this.lineParser = lineParser != null ? lineParser : BasicLineParserHC4.INSTANCE;
    this.messageConstraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
    this.headerLines = new ArrayList<CharArrayBuffer>();
    this.state = HEAD_LINE;
}
项目:remote-files-sync    文件:NetscapeDraftHeaderParserHC4.java   
public HeaderElement parseHeader(
        final CharArrayBuffer buffer,
        final ParserCursor cursor) throws ParseException {
    Args.notNull(buffer, "Char array buffer");
    Args.notNull(cursor, "Parser cursor");
    final NameValuePair nvp = parseNameValuePair(buffer, cursor);
    final List<NameValuePair> params = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        final NameValuePair param = parseNameValuePair(buffer, cursor);
        params.add(param);
    }
    return new BasicHeaderElement(
            nvp.getName(),
            nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
项目:remote-files-sync    文件:CookieSpecBaseHC4.java   
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    for (final CookieAttributeHandler handler: getAttribHandlers()) {
        handler.validate(cookie, origin);
    }
}