public Uri(String scheme, String userInfo, String host, int port, String path, String query, String fragment) { this.scheme = assertNotEmpty(scheme, "scheme"); this.userInfo = userInfo; this.host = assertNotEmpty(host, "host"); this.port = port; this.path = path; this.query = query; this.fragment = fragment; this.secured = HTTPS.equals(scheme) || WSS.equals(scheme); this.webSocket = WS.equals(scheme) || WSS.equalsIgnoreCase(scheme); }
public FileBodyGenerator(File file, long regionSeek, long regionLength) { this.file = assertNotNull(file, "file"); this.regionLength = regionLength; this.regionSeek = regionSeek; }
public ByteArrayPart(String name, byte[] bytes, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) { super(name, contentType, charset, fileName, contentId, transferEncoding); this.bytes = assertNotNull(bytes, "bytes"); }
public InputStreamPart(String name, InputStream inputStream, String fileName, long contentLength, String contentType, Charset charset, String contentId, String transferEncoding) { super(name, contentType, charset, fileName, contentId, transferEncoding); this.inputStream = assertNotNull(inputStream, "inputStream"); this.contentLength = contentLength; }
IdleChannel(Channel channel, long start) { this.channel = assertNotNull(channel, "channel"); this.start = start; }
BodyFileRegion(RandomAccessBody body) { this.body = assertNotNull(body, "body"); }
public static String assertNotEmpty(String value, String name) { assertNotNull(value, name); if (value.length() == 0) throw new IllegalArgumentException("empty " + name); return value; } }
@Override public int compareTo(CookieKey o) { Assertions.assertNotNull(o, "Parameter can't be null"); int result; if ((result = this.name.compareTo(o.name)) == 0) if ((result = this.domain.compareTo(o.domain)) == 0) result = this.path.compareTo(o.path); return result; }
public FilePart(String name, File file, String contentType, Charset charset, String fileName, String contentId, String transferEncoding) { super(name, contentType, charset, fileName != null ? fileName : file.getName(), contentId, transferEncoding); if (!assertNotNull(file, "file").isFile()) throw new IllegalArgumentException("File is not a normal file " + file.getAbsolutePath()); if (!file.canRead()) throw new IllegalArgumentException("File is not readable " + file.getAbsolutePath()); this.file = file; }
@Override public void onSubscribe(Subscription s) { assertNotNull(s, "subscription"); // If someone has made a mistake and added this Subscriber multiple times, let's handle it gracefully if (this.subscription != null) { s.cancel(); // Cancel the additional subscription } else { subscription = s; subscription.request(Long.MAX_VALUE); } }
public StringPart(String name, String value, String contentType, Charset charset, String contentId, String transferEncoding) { super(name, contentType, charsetOrDefault(charset), contentId, transferEncoding); assertNotNull(value, "value"); if (value.indexOf(0) != -1) // See RFC 2048, 2.8. "8bit Data" throw new IllegalArgumentException("NULs may not be present in string parts"); this.value = value; }
public MultipartBody(List<MultipartPart<? extends Part>> parts, String contentType, byte[] boundary) { this.boundary = boundary; this.contentType = contentType; this.parts = assertNotNull(parts, "parts"); this.contentLength = computeContentLength(); }
@Override public void onError(Throwable t) { assertNotNull(t, "throwable"); LOGGER.debug("Error occurred while consuming body stream.", t); FeedListener listener = feedListener; if (listener != null) { listener.onError(t); } }
BodyChunkedInput(Body body) { this.body = assertNotNull(body, "body"); this.contentLength = body.getContentLength(); if (contentLength <= 0) chunkSize = DEFAULT_CHUNK_SIZE; else chunkSize = (int) Math.min(contentLength, (long) DEFAULT_CHUNK_SIZE); }
@Override public void onNext(ByteBuf b) { assertNotNull(b, "bytebuf"); try { feeder.feed(b, false); } catch (Exception e) { LOGGER.error("Exception occurred while processing element in stream.", e); subscription.cancel(); } }
String loginContextName) { this.scheme = assertNotNull(scheme, "scheme"); this.principal = principal; this.password = password;
@Override protected void error(Throwable error) { assertNotNull(error, "error"); removeFromPipeline(); future.abort(error); }
/** * Checks whether proxy should be used according to nonProxyHosts settings of * it, or we want to go directly to target host. If <code>null</code> proxy is * passed in, this method returns true -- since there is NO proxy, we should * avoid to use it. Simple hostname pattern matching using "*" are supported, * but only as prefixes. * * @param hostname the hostname * @return true if we have to ignore proxy use (obeying non-proxy hosts * settings), false otherwise. * @see <a href= * "https://docs.oracle.com/javase/8/docs/api/java/net/doc-files/net-properties.html">Networking * Properties</a> */ public boolean isIgnoredForHost(String hostname) { assertNotNull(hostname, "hostname"); if (isNonEmpty(nonProxyHosts)) { for (String nonProxyHost : nonProxyHosts) { if (matchNonProxyHost(hostname, nonProxyHost)) return true; } } return false; }
/** * Creates a new multipart entity containing the given parts. * * @param parts the parts to include. * @param requestHeaders the request headers * @return a MultipartBody */ public static MultipartBody newMultipartBody(List<Part> parts, HttpHeaders requestHeaders) { assertNotNull(parts, "parts"); byte[] boundary; String contentType; String contentTypeHeader = requestHeaders.get(CONTENT_TYPE); if (isNonEmpty(contentTypeHeader)) { int boundaryLocation = contentTypeHeader.indexOf("boundary="); if (boundaryLocation != -1) { // boundary defined in existing Content-Type contentType = contentTypeHeader; boundary = (contentTypeHeader.substring(boundaryLocation + "boundary=".length()).trim()).getBytes(US_ASCII); } else { // generate boundary and append it to existing Content-Type boundary = computeMultipartBoundary(); contentType = patchContentTypeWithBoundaryAttribute(contentTypeHeader, boundary); } } else { boundary = computeMultipartBoundary(); contentType = patchContentTypeWithBoundaryAttribute(HttpHeaderValues.MULTIPART_FORM_DATA, boundary); } List<MultipartPart<? extends Part>> multipartParts = generateMultipartParts(parts, boundary); return new MultipartBody(multipartParts, contentType, boundary); }
public void parse(Uri context, final String originalUrl) { assertNotNull(originalUrl, "originalUrl"); this.originalUrl = originalUrl; this.end = originalUrl.length(); trimLeft(); trimRight(); currentIndex = start; if (!isFragmentOnly()) { computeInitialScheme(); } boolean isRelative = overrideWithContext(context); trimFragment(); inheritContextQuery(context, isRelative); boolean queryOnly = computeQuery(); parseAuthority(); computePath(queryOnly); } }