@@ -50,12 +50,12 @@ public class DefaultHttpProvider implements IHttpProvider {
50
50
/**
51
51
* The content type header
52
52
*/
53
- static final String ContentTypeHeaderName = "Content-Type" ;
53
+ static final String CONTENT_TYPE_HEADER_NAME = "Content-Type" ;
54
54
55
55
/**
56
56
* The content type for json responses
57
57
*/
58
- static final String JsonContentType = "application/json" ;
58
+ static final String JSON_CONTENT_TYPE = "application/json" ;
59
59
60
60
/**
61
61
* The serializer.
@@ -102,6 +102,7 @@ public DefaultHttpProvider(final ISerializer serializer,
102
102
103
103
/**
104
104
* Gets the serializer for this http provider.
105
+ *
105
106
* @return The serializer for this provider.
106
107
*/
107
108
@ Override
@@ -125,7 +126,7 @@ public <Result, Body> void send(final IHttpRequest request,
125
126
final Body serializable ) {
126
127
final IProgressCallback <Result > progressCallback ;
127
128
if (callback instanceof IProgressCallback ) {
128
- progressCallback = (IProgressCallback <Result >)callback ;
129
+ progressCallback = (IProgressCallback <Result >) callback ;
129
130
} else {
130
131
progressCallback = null ;
131
132
}
@@ -135,10 +136,10 @@ public <Result, Body> void send(final IHttpRequest request,
135
136
public void run () {
136
137
try {
137
138
mExecutors .performOnForeground (sendRequestInternal (request ,
138
- resultClass ,
139
- serializable ,
140
- progressCallback ),
141
- callback );
139
+ resultClass ,
140
+ serializable ,
141
+ progressCallback ),
142
+ callback );
142
143
} catch (final ClientException e ) {
143
144
mExecutors .performOnForeground (e , callback );
144
145
}
@@ -211,13 +212,13 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
211
212
} else if (serializable instanceof byte []) {
212
213
mLogger .logDebug ("Sending byte[] as request body" );
213
214
bytesToWrite = (byte []) serializable ;
214
- connection .addRequestHeader (ContentTypeHeaderName , binaryContentType );
215
+ connection .addRequestHeader (CONTENT_TYPE_HEADER_NAME , binaryContentType );
215
216
connection .setContentLength (bytesToWrite .length );
216
217
} else {
217
218
mLogger .logDebug ("Sending " + serializable .getClass ().getName () + " as request body" );
218
219
final String serializeObject = mSerializer .serializeObject (serializable );
219
220
bytesToWrite = serializeObject .getBytes ();
220
- connection .addRequestHeader (ContentTypeHeaderName , JsonContentType );
221
+ connection .addRequestHeader (CONTENT_TYPE_HEADER_NAME , JSON_CONTENT_TYPE );
221
222
connection .setContentLength (bytesToWrite .length );
222
223
}
223
224
@@ -235,24 +236,24 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
235
236
writtenSoFar = writtenSoFar + toWrite ;
236
237
if (progress != null ) {
237
238
mExecutors .performOnForeground (writtenSoFar , bytesToWrite .length ,
238
- progress );
239
+ progress );
239
240
}
240
- } while (toWrite > 0 );
241
+ } while (toWrite > 0 );
241
242
bos .close ();
242
243
}
243
244
244
245
mLogger .logDebug (String .format ("Response code %d, %s" ,
245
- connection .getResponseCode (),
246
- connection .getResponseMessage ()));
246
+ connection .getResponseCode (),
247
+ connection .getResponseMessage ()));
247
248
if (connection .getResponseCode () >= httpClientErrorResponseCode
248
- && !isAsyncOperation (resultClass )) {
249
+ && !isAsyncOperation (resultClass )) {
249
250
mLogger .logDebug ("Handling error response" );
250
251
in = connection .getInputStream ();
251
252
handleErrorResponse (request , serializable , connection );
252
253
}
253
254
254
255
if (connection .getResponseCode () == httpNoBodyResponseCode
255
- || connection .getResponseCode () == httpNotModified ) {
256
+ || connection .getResponseCode () == httpNotModified ) {
256
257
mLogger .logDebug ("Handling response with no body" );
257
258
return null ;
258
259
}
@@ -273,16 +274,16 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
273
274
}
274
275
in = new BufferedInputStream (connection .getInputStream ());
275
276
final Result result = handleJsonResponse (in , resultClass );
276
- ((AsyncOperationStatus )result ).seeOther = connection .getHeaders ().get ("Location" );
277
+ ((AsyncOperationStatus ) result ).seeOther = connection .getHeaders ().get ("Location" );
277
278
return result ;
278
279
}
279
280
280
281
in = new BufferedInputStream (connection .getInputStream ());
281
282
282
283
final Map <String , String > headers = connection .getHeaders ();
283
284
284
- final String contentType = headers .get (ContentTypeHeaderName );
285
- if (contentType .contains (JsonContentType )) {
285
+ final String contentType = headers .get (CONTENT_TYPE_HEADER_NAME );
286
+ if (contentType .contains (JSON_CONTENT_TYPE )) {
286
287
mLogger .logDebug ("Response json" );
287
288
return handleJsonResponse (in , resultClass );
288
289
} else {
@@ -306,15 +307,16 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
306
307
throw ex ;
307
308
} catch (final Exception ex ) {
308
309
final ClientException clientException = new ClientException ("Error during http request" ,
309
- ex ,
310
- OneDriveErrorCodes .GeneralException );
310
+ ex ,
311
+ OneDriveErrorCodes .GeneralException );
311
312
mLogger .logError ("Error during http request" , clientException );
312
313
throw clientException ;
313
314
}
314
315
}
315
316
316
317
/**
317
318
* Checks if the given class is an async operation.
319
+ *
318
320
* @param resultClass The class to check.
319
321
* @return true if the class is an async operation.
320
322
*/
@@ -335,11 +337,12 @@ private <Body> void handleErrorResponse(final IHttpRequest request,
335
337
final IConnection connection )
336
338
throws IOException {
337
339
throw OneDriveServiceException .createFromConnection (request , serializable , mSerializer ,
338
- connection );
340
+ connection );
339
341
}
340
342
341
343
/**
342
344
* Handles the cause where the response is a binary stream.
345
+ *
343
346
* @param in The input stream from the response.
344
347
* @return The input stream to return to the caller.
345
348
*/
@@ -365,6 +368,7 @@ private <Result> Result handleJsonResponse(final InputStream in, final Class<Res
365
368
366
369
/**
367
370
* Sets the connection factory for this provider.
371
+ *
368
372
* @param factory The new factory.
369
373
*/
370
374
void setConnectionFactory (final IConnectionFactory factory ) {
@@ -373,6 +377,7 @@ void setConnectionFactory(final IConnectionFactory factory) {
373
377
374
378
/**
375
379
* Reads in a stream and converts it into a string.
380
+ *
376
381
* @param input The response body stream.
377
382
* @return The string result.
378
383
*/
0 commit comments