import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpMessage;
import org.apache.http.HttpRequest;
public final class AndroidHttpClient implements HttpClient {
// Gzip of data shorter than this probably won't be worthwhile
- public static final long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
+ private static final long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
private static final String TAG = "AndroidHttpClient";
if (contentEncoding == null) {
return responseStream;
}
- if (contentEncoding.contains("gzip")) responseStream = new GZIPInputStream(responseStream);
+ if (contentEncoding.contains("gzip")) {
+ responseStream = new GZIPInputStream(responseStream);
+ }
return responseStream;
}
* @param data The bytes to compress
* @return Entity holding the data
*/
- public static AbstractHttpEntity getCompressedEntity(byte data[]) throws IOException {
+ public static AbstractHttpEntity getCompressedEntity(byte[] data) throws IOException {
AbstractHttpEntity entity;
if (data.length < getMinGzipSize()) {
entity = new ByteArrayEntity(data);
} else {
ByteArrayOutputStream arr = new ByteArrayOutputStream();
OutputStream zipper = new GZIPOutputStream(arr);
- zipper.write(data);
- zipper.close();
+ try {
+ zipper.write(data);
+ } finally {
+ zipper.close();
+ }
entity = new ByteArrayEntity(arr.toByteArray());
entity.setContentEncoding("gzip");
}
* Retrieves the minimum size for compressing data.
* Shorter data will not be compressed.
*/
- public static long getMinGzipSize() {
+ private static long getMinGzipSize() {
return DEFAULT_SYNC_MIN_GZIP_BYTES;
}
/**
* Logging tag and level.
*/
- private static class LoggingConfiguration {
+ private static final class LoggingConfiguration {
private final String tag;
private final int level;
/**
* Logs cURL commands equivalent to requests.
*/
- private class CurlLogger implements HttpRequestInterceptor {
+ private final class CurlLogger implements HttpRequestInterceptor {
public void process(HttpRequest request, HttpContext context)
- throws HttpException, IOException {
+ throws IOException {
LoggingConfiguration configuration = curlConfiguration;
if (configuration != null
&& configuration.isLoggable()
HttpEntity entity = entityRequest.getEntity();
if (entity != null && entity.isRepeatable()) {
if (entity.getContentLength() < 1024) {
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ OutputStream stream = new ByteArrayOutputStream();
entity.writeTo(stream);
String entityString = stream.toString();
// TODO: Check the content type, too.