Commit bb55ceda by Adi Amir

support 'assumeContentBinary' flag

parent 77115c56
......@@ -6,4 +6,6 @@
- Handle correctly Exceptions in http requsts/responses
- support Encoding type (other than utf8) in http responses
## 1.2.4
- support binary content in response
\ No newline at end of file
- support binary content in response
## 1.2.5
- support 'assumeContentBinary' flag
\ No newline at end of file
group 'com.ipgallery.common'
version '1.2.4'
version '1.2.5'
apply plugin: 'java'
apply plugin: 'maven-publish'
......
......@@ -30,6 +30,7 @@ public class SimpleHttpClient {
private ThreadSafeClientConnManager connManager = null;
private CookieStore cookieStore = null;
private Map<String, Boolean> binaryMimeTypes = new HashMap<String, Boolean>();
private Boolean isAssumeBinaryContent = false;
public SimpleHttpClient()
......@@ -50,6 +51,11 @@ public class SimpleHttpClient {
this.defaulthttpClient = new DefaultHttpClient(connManager);
this.cookieStore = defaulthttpClient.getCookieStore();
}
public void assumeBinaryContent() {
isAssumeBinaryContent = true;
}
public Boolean isAssumeBinaryContent() { return isAssumeBinaryContent; }
public void shutdown() throws Throwable
{
......@@ -108,7 +114,11 @@ public class SimpleHttpClient {
try {
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
if (isContentBinary(response)) {
if (isAssumeBinaryContent) {
InputStream is = httpEntity.getContent();
resp.binaryContent = IOUtils.toByteArray(is);
}
else if (isContentBinary(response)) {
// content is binary
InputStream is = httpEntity.getContent();
byte[] baContent = IOUtils.toByteArray(is);
......
......@@ -9,8 +9,8 @@ public class SimpleHttpResponse {
protected int statusCode = 0;
protected Map<String, String> headers;
protected List<Cookie> cookies;
protected String content = null;
protected String content = null;
protected byte[] binaryContent = null;
public SimpleHttpResponse() {
}
......@@ -27,6 +27,8 @@ public class SimpleHttpResponse {
public void setHeaders(Map<String, String> headers) { this.headers = headers; }
public String getContent() { return content; }
public void setContent(String content) { this.content = content; }
public byte[] getBinaryContent() { return binaryContent; }
public void setBinaryContent(byte[] binaryContent) { this.binaryContent = binaryContent; }
@Override
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