Skip to content

chore: fix various OverloadMethodsDeclarationOrder warnings #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ protected long computeLength() throws IOException {
return computeLength(this);
}

/** Default implementation returns {@code true}, but subclasses may override. */
public boolean retrySupported() {
return true;
}

/**
* Returns the computed content length based using {@link IOUtils#computeLength(StreamingContent)}
* or instead {@code -1} if {@link HttpContent#retrySupported()} is {@code false} because the
Expand All @@ -131,4 +126,9 @@ public static long computeLength(HttpContent content) throws IOException {
}
return IOUtils.computeLength(content);
}

/** Default implementation returns {@code true}, but subclasses may override. */
public boolean retrySupported() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,22 @@ public final URI toURI() {
return toURI(build());
}

/**
* Returns the URI for the given encoded URL.
*
* <p>Any {@link URISyntaxException} is wrapped in an {@link IllegalArgumentException}.
*
* @param encodedUrl encoded URL
* @return URI
*/
private static URI toURI(String encodedUrl) {
try {
return new URI(encodedUrl);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}

/**
* Constructs the URL based on the string representation of the URL from {@link #build()}.
*
Expand Down Expand Up @@ -648,22 +664,6 @@ private static boolean appendParam(
return first;
}

/**
* Returns the URI for the given encoded URL.
*
* <p>Any {@link URISyntaxException} is wrapped in an {@link IllegalArgumentException}.
*
* @param encodedUrl encoded URL
* @return URI
*/
private static URI toURI(String encodedUrl) {
try {
return new URI(encodedUrl);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}

/**
* Returns the URI for the given encoded URL.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,20 @@ public <T> T parseAs(Class<T> dataClass) throws IOException {
return request.getParser().parseAndClose(getContent(), getContentCharset(), dataClass);
}

/**
* Parses the content of the HTTP response from {@link #getContent()} and reads it into a data
* type of key/value pairs using the parser returned by {@link HttpRequest#getParser()}.
*
* @return parsed data type instance or {@code null} for no content
* @since 1.10
*/
public Object parseAs(Type dataType) throws IOException {
if (!hasMessageBody()) {
return null;
}
return request.getParser().parseAndClose(getContent(), getContentCharset(), dataType);
}

/**
* Returns whether this response contains a message body as specified in {@href
* http://tools.ietf.org/html/rfc2616#section-4.3}, calling {@link #ignore()} if {@code false}.
Expand All @@ -477,20 +491,6 @@ private boolean hasMessageBody() throws IOException {
return true;
}

/**
* Parses the content of the HTTP response from {@link #getContent()} and reads it into a data
* type of key/value pairs using the parser returned by {@link HttpRequest#getParser()}.
*
* @return parsed data type instance or {@code null} for no content
* @since 1.10
*/
public Object parseAs(Type dataType) throws IOException {
if (!hasMessageBody()) {
return null;
}
return request.getParser().parseAndClose(getContent(), getContentCharset(), dataType);
}

/**
* Parses the content of the HTTP response from {@link #getContent()} and reads it into a string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ HttpRequest buildRequest() {
return new HttpRequest(this, null);
}

/**
* Builds a low level HTTP request for the given HTTP method.
*
* @param method HTTP method
* @param url URL
* @return new low level HTTP request
* @throws IllegalArgumentException if HTTP method is not supported
* @since 1.12
*/
protected abstract LowLevelHttpRequest buildRequest(String method, String url) throws IOException;

/**
* Returns whether a specified HTTP method is supported by this transport.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public String getHeaderValue(String name) {
return response.getLastHeader(name).getValue();
}

@Override
public String getHeaderValue(int index) {
return allHeaders[index].getValue();
}

@Override
public int getHeaderCount() {
return allHeaders.length;
Expand All @@ -103,11 +108,6 @@ public String getHeaderName(int index) {
return allHeaders[index].getName();
}

@Override
public String getHeaderValue(int index) {
return allHeaders[index].getValue();
}

/**
* Aborts execution of the request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ public static DefaultHttpClient newDefaultHttpClient() {
SSLSocketFactory.getSocketFactory(), newDefaultHttpParams(), ProxySelector.getDefault());
}

/** Returns a new instance of the default HTTP parameters we use. */
static HttpParams newDefaultHttpParams() {
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ConnManagerParams.setMaxTotalConnections(params, 200);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20));
return params;
}

/**
* Creates a new instance of the Apache HTTP client that is used by the {@link
* #ApacheHttpTransport()} constructor.
Expand All @@ -188,6 +176,18 @@ static DefaultHttpClient newDefaultHttpClient(
return defaultHttpClient;
}

/** Returns a new instance of the default HTTP parameters we use. */
static HttpParams newDefaultHttpParams() {
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ConnManagerParams.setMaxTotalConnections(params, 200);
ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20));
return params;
}

@Override
public boolean supportsMethod(String method) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public final String toString(Object item) throws IOException {
return toString(item, false);
}

/**
* Returns a serialized JSON string representation for the given item using {@link
* JsonGenerator#serialize(Object)}.
*
* @param item data key/value pairs
* @param pretty whether to return a pretty representation
* @return serialized JSON string representation
*/
private String toString(Object item, boolean pretty) throws IOException {
return toByteStream(item, pretty).toString("UTF-8");
}

/**
* Returns a pretty-printed serialized JSON string representation for the given item using {@link
* JsonGenerator#serialize(Object)} with {@link JsonGenerator#enablePrettyPrint()}.
Expand Down Expand Up @@ -137,18 +149,6 @@ public final byte[] toByteArray(Object item) throws IOException {
return toByteStream(item, false).toByteArray();
}

/**
* Returns a serialized JSON string representation for the given item using {@link
* JsonGenerator#serialize(Object)}.
*
* @param item data key/value pairs
* @param pretty whether to return a pretty representation
* @return serialized JSON string representation
*/
private String toString(Object item, boolean pretty) throws IOException {
return toByteStream(item, pretty).toString("UTF-8");
}

/**
* Returns a UTF-8 byte array output stream of the serialized JSON representation for the given
* item using {@link JsonGenerator#serialize(Object)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,41 @@ public final <T> T parseAndClose(Class<T> destinationClass, CustomizeJsonParser
}
}

/**
* Parse a JSON Object from the given JSON parser -- which is closed after parsing completes --
* into the given destination object.
*
* <p>Before this method is called, the parser must either point to the start or end of a JSON
* object or to a field name.
*
* @param destination destination object
* @since 1.15
*/
public final void parseAndClose(Object destination) throws IOException {
parseAndClose(destination, null);
}

/**
* {@link Beta} <br>
* Parse a JSON Object from the given JSON parser -- which is closed after parsing completes --
* into the given destination object, optionally using the given parser customizer.
*
* <p>Before this method is called, the parser must either point to the start or end of a JSON
* object or to a field name.
*
* @param destination destination object
* @param customizeParser optional parser customizer or {@code null} for none
*/
@Beta
public final void parseAndClose(Object destination, CustomizeJsonParser customizeParser)
throws IOException {
try {
parse(destination, customizeParser);
} finally {
close();
}
}

/**
* Skips the values of all keys in the current object until it finds the given key.
*
Expand Down Expand Up @@ -244,41 +279,6 @@ private JsonToken startParsingObjectOrArray() throws IOException {
return currentToken;
}

/**
* Parse a JSON Object from the given JSON parser -- which is closed after parsing completes --
* into the given destination object.
*
* <p>Before this method is called, the parser must either point to the start or end of a JSON
* object or to a field name.
*
* @param destination destination object
* @since 1.15
*/
public final void parseAndClose(Object destination) throws IOException {
parseAndClose(destination, null);
}

/**
* {@link Beta} <br>
* Parse a JSON Object from the given JSON parser -- which is closed after parsing completes --
* into the given destination object, optionally using the given parser customizer.
*
* <p>Before this method is called, the parser must either point to the start or end of a JSON
* object or to a field name.
*
* @param destination destination object
* @param customizeParser optional parser customizer or {@code null} for none
*/
@Beta
public final void parseAndClose(Object destination, CustomizeJsonParser customizeParser)
throws IOException {
try {
parse(destination, customizeParser);
} finally {
close();
}
}

/**
* Parse a JSON object, array, or value into a new instance of the given destination class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public MockLowLevelHttpResponse setContent(byte[] byteContent) {
return this;
}

/**
* Sets the input stream content of HTTP response or {@code null} for none.
*
* @since 1.5
*/
public MockLowLevelHttpResponse setContent(InputStream content) {
this.content = content;
return this;
}

/**
* Sets the content to {@code null} and the content length to 0. Note that the result will have a
* content length header whose value is 0.
Expand Down Expand Up @@ -216,16 +226,6 @@ public MockLowLevelHttpResponse setHeaderValues(List<String> headerValues) {
return this;
}

/**
* Sets the input stream content of HTTP response or {@code null} for none.
*
* @since 1.5
*/
public MockLowLevelHttpResponse setContent(InputStream content) {
this.content = content;
return this;
}

/**
* Sets the content type of HTTP response or {@code null} for none.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ public final V remove(int index) {
return removeFromDataIndexOfKey(index << 1);
}

/**
* Removes the key-value pair of the given key, or ignore if the key cannot be found.
*
* @return previous value or {@code null} for none
*/
@Override
public final V remove(Object key) {
return removeFromDataIndexOfKey(getDataIndexOfKey(key));
}

/** Returns whether there is a mapping for the given key. */
@Override
public final boolean containsKey(Object key) {
Expand Down Expand Up @@ -204,16 +214,6 @@ public final V put(K key, V value) {
return set(index, key, value);
}

/**
* Removes the key-value pair of the given key, or ignore if the key cannot be found.
*
* @return previous value or {@code null} for none
*/
@Override
public final V remove(Object key) {
return removeFromDataIndexOfKey(getDataIndexOfKey(key));
}

/** Trims the internal array storage to minimize memory usage. */
public final void trim() {
setDataCapacity(this.size << 1);
Expand Down
Loading