com.landawn.abacus.http.HttpResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-android Show documentation
Show all versions of abacus-android Show documentation
A general and simple library for Android
/*
* Copyright (C) 2019 HaiYang Li
*
* 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.landawn.abacus.http;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import com.landawn.abacus.type.Type;
import com.landawn.abacus.util.N;
/**
*
* @since 1.3
*
* @author Haiyang Li
*/
public class HttpResponse {
private final long sentRequestAtMillis;
private final long receivedResponseAtMillis;
private final int code;
private final String message;
private final Map> headers;
private final byte[] body;
private final ContentFormat bodyFormat;
HttpResponse(long sentRequestAtMillis, long receivedResponseAtMillis, int code, String message, Map> headers, byte[] body,
ContentFormat bodyFormat) {
this.sentRequestAtMillis = sentRequestAtMillis;
this.receivedResponseAtMillis = receivedResponseAtMillis;
this.code = code;
this.message = message;
this.headers = headers;
this.body = body;
this.bodyFormat = bodyFormat;
}
/**
* Returns true if the code is in [200..300), which means the request was successfully received,
* understood, and accepted.
*/
public boolean isSuccessful() {
return code >= 200 && code < 300;
}
public long sentRequestAtMillis() {
return sentRequestAtMillis;
}
public long receivedResponseAtMillis() {
return receivedResponseAtMillis;
}
public int code() {
return code;
}
public String message() {
return message;
}
public Map> headers() {
return headers;
}
public byte[] body() {
return body;
}
public T body(Class resultClass) {
N.checkArgNotNull(resultClass, "resultClass");
if (byte[].class.equals(resultClass)) {
return (T) body;
}
final Type