1414import java .util .Map ;
1515
1616/**
17- * The base class of a http response we receive from parse server. It can be implemented by
18- * different http library such as Apache http, Android URLConnection, Square OKHttp and so on .
17+ * The http response we receive from parse server. Instances of this class are not immutable. The
18+ * response body may be consumed only once. The other fields are immutable .
1919 */
2020/** package */ class ParseHttpResponse {
2121
22+ /**
23+ * Base builder for {@code ParseHttpResponse}.
24+ */
2225 /* package */ static abstract class Init <T extends Init <T >> {
2326 private int statusCode ;
2427 private InputStream content ;
3033 /* package */ abstract T self ();
3134
3235 public Init () {
36+ this .totalSize = -1 ;
3337 this .headers = new HashMap <>();
3438 }
3539
@@ -64,7 +68,7 @@ public T addHeaders(Map<String, String> headers) {
6468 }
6569
6670 public T addHeader (String key , String value ) {
67- this . headers .put (key , value );
71+ headers .put (key , value );
6872 return self ();
6973 }
7074
@@ -74,18 +78,28 @@ public T setContentType(String contentType) {
7478 }
7579 }
7680
81+ /**
82+ * Builder of {@code ParseHttpResponse}.
83+ */
7784 public static class Builder extends Init <Builder > {
7885
7986 @ Override
8087 /* package */ Builder self () {
8188 return this ;
8289 }
8390
84- /* package */ Builder () {
91+ public Builder () {
8592 super ();
8693 }
8794
88- /* package */ Builder (ParseHttpResponse response ) {
95+ /**
96+ * Makes a new {@code ParseHttpResponse} {@code Builder} based on the input
97+ * {@code ParseHttpResponse}.
98+ *
99+ * @param response
100+ * The {@code ParseHttpResponse} where the {@code Builder}'s values come from.
101+ */
102+ public Builder (ParseHttpResponse response ) {
89103 super ();
90104 this .setStatusCode (response .getStatusCode ());
91105 this .setContent (response .getContent ());
@@ -100,12 +114,12 @@ public ParseHttpResponse build() {
100114 }
101115 }
102116
103- /* package */ final int statusCode ;
104- /* package */ final InputStream content ;
105- /* package */ final long totalSize ;
106- /* package */ final String reasonPhrase ;
107- /* package */ final Map <String , String > headers ;
108- /* package */ final String contentType ;
117+ private final int statusCode ;
118+ private final InputStream content ;
119+ private final long totalSize ;
120+ private final String reasonPhrase ;
121+ private final Map <String , String > headers ;
122+ private final String contentType ;
109123
110124 /* package */ ParseHttpResponse (Init <?> builder ) {
111125 this .statusCode = builder .statusCode ;
@@ -116,18 +130,26 @@ public ParseHttpResponse build() {
116130 this .contentType = builder .contentType ;
117131 }
118132
119- public Builder newBuilder () {
120- return new Builder (this );
121- }
122-
123133 public int getStatusCode () {
124134 return statusCode ;
125135 }
126136
137+ /**
138+ * Returns the content of the {@code ParseHttpResponse}'s body. The {@link InputStream} can only
139+ * be read once and can't be reset.
140+ *
141+ * @return The {@link InputStream} of the {@code ParseHttpResponse}'s body.
142+ */
127143 public InputStream getContent () {
128144 return content ;
129145 }
130146
147+ /**
148+ * Returns the size of the {@code ParseHttpResponse}'s body. -1 if the size of the
149+ * {@code ParseHttpResponse}'s body is unknown.
150+ *
151+ * @return The size of the {@code ParseHttpResponse}'s body.
152+ */
131153 public long getTotalSize () {
132154 return totalSize ;
133155 }
@@ -141,7 +163,7 @@ public String getContentType() {
141163 }
142164
143165 public String getHeader (String name ) {
144- return headers == null ? null : headers .get (name );
166+ return headers .get (name );
145167 }
146168
147169 public Map <String , String > getAllHeaders () {
0 commit comments