Args.notNull(requestDate, "Request date"); Args.notNull(responseDate, "Response date"); Args.check(status >= HttpStatus.SC_SUCCESS, "Status code"); Args.notNull(responseHeaders, "Response headers"); this.requestDate = requestDate;
/** * Update the entry with the new information from the response. Should only be used for * 304 responses. */ public HttpCacheEntry updateCacheEntry( final String requestId, final HttpCacheEntry entry, final Date requestDate, final Date responseDate, final HttpResponse response) throws ResourceIOException { Args.check(response.getCode() == HttpStatus.SC_NOT_MODIFIED, "Response must have 304 status code"); final Header[] mergedHeaders = mergeHeaders(entry, response); Resource resource = null; if (entry.getResource() != null) { resource = resourceFactory.copy(requestId, entry.getResource()); } return new HttpCacheEntry( requestDate, responseDate, entry.getStatus(), mergedHeaders, resource); }
/** * Sets the factor to use when backing off; the new * per-host limit will be roughly the current max times * this factor. {@code Math.floor} is applied in the * case of non-integer outcomes to ensure we actually * decrease the pool size. Pool sizes are never decreased * below 1, however. Defaults to 0.5. * @param d must be between 0.0 and 1.0, exclusive. */ public void setBackoffFactor(final double d) { Args.check(d > 0.0 && d < 1.0, "Backoff factor must be 0.0 < f < 1.0"); backoffFactor = d; }
@Override public final HttpHost getHopTarget(final int hop) { Args.notNegative(hop, "Hop index"); final int hopcount = getHopCount(); Args.check(hop < hopcount, "Hop index exceeds tracked route length"); if (hop < hopcount - 1) { return this.proxyChain.get(hop); } else { return this.targetHost; } }
@Override public final HttpHost getHopTarget(final int hop) { Args.notNegative(hop, "Hop index"); final int hopcount = getHopCount(); Args.check(hop < hopcount, "Hop index exceeds tracked route length"); HttpHost result = null; if (hop < hopcount-1) { result = this.proxyChain[hop]; } else { result = this.targetHost; } return result; }
public RawFrame createPingAck(final ByteBuffer opaqueData) { Args.notNull(opaqueData, "Opaque data"); Args.check(opaqueData.remaining() == 8, "Opaque data length must be equal 8"); return new RawFrame(FrameType.PING.getValue(), FrameFlag.ACK.value, 0, opaqueData); }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String normalizedMimeType = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(normalizedMimeType), "MIME type may not contain reserved characters"); return new ContentType(normalizedMimeType, charset); }
/** * Creates a new instance of {@link ContentType}. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param charset charset. * @return content type */ public static ContentType create(final String mimeType, final Charset charset) { final String normalizedMimeType = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(normalizedMimeType), "MIME type may not contain reserved characters"); return new ContentType(normalizedMimeType, charset); }
public RawFrame createPing(final ByteBuffer opaqueData) { Args.notNull(opaqueData, "Opaque data"); Args.check(opaqueData.remaining() == 8, "Opaque data length must be equal 8"); return new RawFrame(FrameType.PING.getValue(), 0, 0, opaqueData); }
private HttpRoute(final HttpHost targetHost, final InetAddress local, final List<HttpHost> proxies, final boolean secure, final TunnelType tunnelled, final LayerType layered) { Args.notNull(targetHost, "Target host"); Args.notNegative(targetHost.getPort(), "Target port"); this.targetHost = targetHost; this.localAddress = local; if (proxies != null && !proxies.isEmpty()) { this.proxyChain = new ArrayList<>(proxies); } else { this.proxyChain = null; } if (tunnelled == TunnelType.TUNNELLED) { Args.check(this.proxyChain != null, "Proxy required if tunnelled"); } this.secure = secure; this.tunnelled = tunnelled != null ? tunnelled : TunnelType.PLAIN; this.layered = layered != null ? layered : LayerType.PLAIN; }
/** * Creates a new instance of {@link ContentType} with the given parameters. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param params parameters. * @return content type * * @since 4.4 */ public static ContentType create( final String mimeType, final NameValuePair... params) throws UnsupportedCharsetException { final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(type), "MIME type may not contain reserved characters"); return create(mimeType, params, true); }
/** * Creates a new instance of {@link ContentType} with the given parameters. * * @param mimeType MIME type. It may not be {@code null} or empty. It may not contain * characters {@code <">, <;>, <,>} reserved by the HTTP specification. * @param params parameters. * @return content type * * @since 4.4 */ public static ContentType create( final String mimeType, final NameValuePair... params) throws UnsupportedCharsetException { final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.ROOT); Args.check(valid(type), "MIME type may not contain reserved characters"); return create(mimeType, params, true); }
@Test public void testArgCheckPass() { Args.check(true, "All is well"); }
@Test(expected=IllegalArgumentException.class) public void testArgCheckFail() { Args.check(false, "Oopsie"); }
Args.check(uri.isAbsolute(), "Base URI must be absolute"); final URIBuilder builder = new URIBuilder(uri); final String path = builder.getPath();
/** * Compares this protocol version with another one. * Only protocol versions with the same protocol name can be compared. * This method does <i>not</i> define a total ordering, as it would be * required for {@link java.lang.Comparable}. * * @param that the protocol version to compare with * * @return a negative integer, zero, or a positive integer * as this version is less than, equal to, or greater than * the argument version. * * @throws IllegalArgumentException * if the argument has a different protocol name than this object, * or if the argument is {@code null} */ public int compareToVersion(final ProtocolVersion that) { Args.notNull(that, "Protocol version"); Args.check(this.protocol.equals(that.protocol), "Versions for different protocols cannot be compared: %s %s", this, that); int delta = getMajor() - that.getMajor(); if (delta == 0) { delta = getMinor() - that.getMinor(); } return delta; }
/** * Compares this protocol version with another one. * Only protocol versions with the same protocol name can be compared. * This method does <i>not</i> define a total ordering, as it would be * required for {@link java.lang.Comparable}. * * @param that the protocol version to compare with * * @return a negative integer, zero, or a positive integer * as this version is less than, equal to, or greater than * the argument version. * * @throws IllegalArgumentException * if the argument has a different protocol name than this object, * or if the argument is {@code null} */ public int compareToVersion(final ProtocolVersion that) { Args.notNull(that, "Protocol version"); Args.check(this.protocol.equals(that.protocol), "Versions for different protocols cannot be compared: %s %s", this, that); int delta = getMajor() - that.getMajor(); if (delta == 0) { delta = getMinor() - that.getMinor(); } return delta; }
Args.notNull(requestDate, "Request date"); Args.notNull(responseDate, "Response date"); Args.check(status >= HttpStatus.SC_SUCCESS, "Status code"); Args.notNull(responseHeaders, "Response headers"); this.requestDate = requestDate;
/** * Update the entry with the new information from the response. Should only be used for * 304 responses. */ public HttpCacheEntry updateCacheEntry( final String requestId, final HttpCacheEntry entry, final Date requestDate, final Date responseDate, final HttpResponse response) throws ResourceIOException { Args.check(response.getCode() == HttpStatus.SC_NOT_MODIFIED, "Response must have 304 status code"); final Header[] mergedHeaders = mergeHeaders(entry, response); Resource resource = null; if (entry.getResource() != null) { resource = resourceFactory.copy(requestId, entry.getResource()); } return new HttpCacheEntry( requestDate, responseDate, entry.getStatus(), mergedHeaders, resource); }