com.baidu.aip.http.AipResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-sdk Show documentation
Show all versions of java-sdk Show documentation
The AIP SDK for Java provides Java APIs for all of AI APIs.
/*
* Copyright 2017 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.baidu.aip.http;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class AipResponse {
private Map> header;
private byte[] body;
private String charset;
private int status;
public AipResponse() {
status = 0;
charset = "UTF-8";
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getBodyStr() {
if (body == null) {
return "";
}
try {
return new String(body, charset);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return new String(body);
}
}
public Map> getHeader() {
return header;
}
public void setHeader(Map> header) {
this.header = new TreeMap>(String.CASE_INSENSITIVE_ORDER);
for (Map.Entry> entry: header.entrySet()) {
if (entry.getKey() != null) {
this.header.put(entry.getKey(), entry.getValue());
}
}
}
public byte[] getBody() {
return body;
}
public void setBody(byte[] body) {
this.body = body;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
}