Commit bb55ceda by Adi Amir

support 'assumeContentBinary' flag

parent 77115c56
...@@ -7,3 +7,5 @@ ...@@ -7,3 +7,5 @@
- support Encoding type (other than utf8) in http responses - support Encoding type (other than utf8) in http responses
## 1.2.4 ## 1.2.4
- support binary content in response - support binary content in response
## 1.2.5
- support 'assumeContentBinary' flag
\ No newline at end of file
group 'com.ipgallery.common' group 'com.ipgallery.common'
version '1.2.4' version '1.2.5'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
......
...@@ -30,6 +30,7 @@ public class SimpleHttpClient { ...@@ -30,6 +30,7 @@ public class SimpleHttpClient {
private ThreadSafeClientConnManager connManager = null; private ThreadSafeClientConnManager connManager = null;
private CookieStore cookieStore = null; private CookieStore cookieStore = null;
private Map<String, Boolean> binaryMimeTypes = new HashMap<String, Boolean>(); private Map<String, Boolean> binaryMimeTypes = new HashMap<String, Boolean>();
private Boolean isAssumeBinaryContent = false;
public SimpleHttpClient() public SimpleHttpClient()
...@@ -51,6 +52,11 @@ public class SimpleHttpClient { ...@@ -51,6 +52,11 @@ public class SimpleHttpClient {
this.cookieStore = defaulthttpClient.getCookieStore(); this.cookieStore = defaulthttpClient.getCookieStore();
} }
public void assumeBinaryContent() {
isAssumeBinaryContent = true;
}
public Boolean isAssumeBinaryContent() { return isAssumeBinaryContent; }
public void shutdown() throws Throwable public void shutdown() throws Throwable
{ {
defaulthttpClient.getConnectionManager().shutdown(); defaulthttpClient.getConnectionManager().shutdown();
...@@ -108,7 +114,11 @@ public class SimpleHttpClient { ...@@ -108,7 +114,11 @@ public class SimpleHttpClient {
try { try {
HttpEntity httpEntity = response.getEntity(); HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) { if (httpEntity != null) {
if (isContentBinary(response)) { if (isAssumeBinaryContent) {
InputStream is = httpEntity.getContent();
resp.binaryContent = IOUtils.toByteArray(is);
}
else if (isContentBinary(response)) {
// content is binary // content is binary
InputStream is = httpEntity.getContent(); InputStream is = httpEntity.getContent();
byte[] baContent = IOUtils.toByteArray(is); byte[] baContent = IOUtils.toByteArray(is);
......
...@@ -9,8 +9,8 @@ public class SimpleHttpResponse { ...@@ -9,8 +9,8 @@ public class SimpleHttpResponse {
protected int statusCode = 0; protected int statusCode = 0;
protected Map<String, String> headers; protected Map<String, String> headers;
protected List<Cookie> cookies; protected List<Cookie> cookies;
protected String content = null; protected String content = null;
protected byte[] binaryContent = null;
public SimpleHttpResponse() { public SimpleHttpResponse() {
} }
...@@ -27,6 +27,8 @@ public class SimpleHttpResponse { ...@@ -27,6 +27,8 @@ public class SimpleHttpResponse {
public void setHeaders(Map<String, String> headers) { this.headers = headers; } public void setHeaders(Map<String, String> headers) { this.headers = headers; }
public String getContent() { return content; } public String getContent() { return content; }
public void setContent(String content) { this.content = content; } public void setContent(String content) { this.content = content; }
public byte[] getBinaryContent() { return binaryContent; }
public void setBinaryContent(byte[] binaryContent) { this.binaryContent = binaryContent; }
@Override @Override
public String toString() { public String toString() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment