package com.ifpdos.sdk.httpd.binder.aidl;

import android.os.Parcel;
import android.os.Parcelable;
import com.ifpdos.sdk.httpd.binder.HttpStatus;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class Response implements Parcelable {
    public static final Parcelable.Creator<Response> CREATOR = new Parcelable.Creator<Response>() { // from class: com.ifpdos.sdk.httpd.binder.aidl.Response.1
        /* JADX WARN: Can't rename method to resolve collision */
        @Override // android.os.Parcelable.Creator
        public Response createFromParcel(Parcel in) {
            return new Response(in);
        }

        /* JADX WARN: Can't rename method to resolve collision */
        @Override // android.os.Parcelable.Creator
        public Response[] newArray(int size) {
            return new Response[size];
        }
    };
    private Headers headers;
    private byte[] mBody;
    private StatusLine mStatusLine;

    @Override // android.os.Parcelable
    public int describeContents() {
        return 0;
    }

    protected Response(Parcel in) {
        this.mStatusLine = (StatusLine) in.readParcelable(StatusLine.class.getClassLoader());
        this.headers = (Headers) in.readParcelable(Headers.class.getClassLoader());
        this.mBody = in.createByteArray();
    }

    private Response(StatusLine statusLine, Headers headers, byte[] body) {
        this.mStatusLine = statusLine;
        this.headers = headers;
        this.mBody = body;
    }

    public StatusLine getStatusLine() {
        return this.mStatusLine;
    }

    public String getStringBody() {
        if (this.mBody == null) {
            return null;
        }
        return new String(this.mBody);
    }

    public byte[] getBody() {
        return this.mBody;
    }

    public Map<String, String> getHeaderMap() {
        return this.headers.getHeaderMap();
    }

    public String getHeader(String key) {
        return this.headers.getHeader(key);
    }

    public int getCode() {
        return this.mStatusLine.code;
    }

    @Override // android.os.Parcelable
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.mStatusLine, flags);
        dest.writeParcelable(this.headers, flags);
        dest.writeByteArray(this.mBody);
    }

    public static final class Builder {
        private byte[] mBody;
        private final Headers mHeaders = new Headers();
        private StatusLine mStatusLine;

        public Builder setStatus(int code) {
            return setStatus(HttpStatus.getByCode(code));
        }

        public Builder setStatus(StatusLine statusLine) {
            this.mStatusLine = statusLine;
            return this;
        }

        public Builder setStatus(HttpStatus status) {
            this.mStatusLine = new StatusLine(status.code, status.message);
            return this;
        }

        public Builder setStatus(int code, String message) {
            this.mStatusLine = new StatusLine(code, message);
            return this;
        }

        public Builder addHeader(String key, String value) {
            this.mHeaders.addHeader(key, value);
            return this;
        }

        public Builder addHeaders(Map<String, String> headers) {
            this.mHeaders.addHeaders(headers);
            return this;
        }

        public Builder setBody(String body) {
            return setBody(body != null ? body.getBytes() : null);
        }

        public Builder setBody(byte[] body) {
            this.mBody = body;
            return this;
        }

        public Response build() {
            if (this.mStatusLine == null) {
                throw new RuntimeException("StatusLine must not be null");
            }
            if (!this.mHeaders.containHeader("Content-Length")) {
                Headers headers = this.mHeaders;
                byte[] bArr = this.mBody;
                headers.addHeader("Content-Length", bArr == null ? 0 : bArr.length);
            }
            return new Response(this.mStatusLine, this.mHeaders, this.mBody);
        }
    }
}
