Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit abdb48e

Browse files
committed
Merge pull request #86 from daboxu/dev
nit
2 parents be3cca3 + 7503a42 commit abdb48e

File tree

6 files changed

+51
-29
lines changed

6 files changed

+51
-29
lines changed

onedrivesdk/src/main/java/com/onedrive/sdk/authentication/ADALAuthenticator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,10 @@ public void onError(final Exception e) {
422422
}
423423
};
424424

425-
mAdalContext.acquireTokenSilent(mOneDriveServiceInfo.get().serviceResourceId, getClientId(), mUserId.get(), callback);
425+
mAdalContext.acquireTokenSilent(mOneDriveServiceInfo.get().serviceResourceId,
426+
getClientId(),
427+
mUserId.get(),
428+
callback);
426429

427430
loginSilentWaiter.waitForSignal();
428431
//noinspection ThrowableResultOfMethodCallIgnored

onedrivesdk/src/main/java/com/onedrive/sdk/http/BaseRequest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public BaseRequest(final String requestUrl,
106106
if (options != null) {
107107
for (final Option option : options) {
108108
if (option instanceof HeaderOption) {
109-
mHeadersOptions.add((HeaderOption)option);
109+
mHeadersOptions.add((HeaderOption) option);
110110
}
111111
if (option instanceof QueryOption) {
112-
mQueryOptions.add((QueryOption)option);
112+
mQueryOptions.add((QueryOption) option);
113113
}
114114
}
115115
}
@@ -120,12 +120,15 @@ public BaseRequest(final String requestUrl,
120120

121121
/**
122122
* Gets the request url.
123+
*
123124
* @return The request url.
124125
*/
125126
@Override
126127
public URL getRequestUrl() {
127128
Uri baseUrl = Uri.parse(mRequestUrl);
128-
final Uri.Builder uriBuilder = new Uri.Builder().scheme(baseUrl.getScheme()).encodedAuthority(baseUrl.getEncodedAuthority());
129+
final Uri.Builder uriBuilder = new Uri.Builder()
130+
.scheme(baseUrl.getScheme())
131+
.encodedAuthority(baseUrl.getEncodedAuthority());
129132

130133
for (final String segment : baseUrl.getPathSegments()) {
131134
uriBuilder.appendPath(segment);
@@ -145,6 +148,7 @@ public URL getRequestUrl() {
145148

146149
/**
147150
* Gets the http method.
151+
*
148152
* @return The http method.
149153
*/
150154
@Override
@@ -154,6 +158,7 @@ public HttpMethod getHttpMethod() {
154158

155159
/**
156160
* Gets the headers.
161+
*
157162
* @return The headers.
158163
*/
159164
@Override
@@ -205,6 +210,7 @@ protected <T1, T2> T1 send(final HttpMethod method,
205210

206211
/**
207212
* Gets the query options for this request.
213+
*
208214
* @return The query options for this request.
209215
*/
210216
public List<QueryOption> getQueryOptions() {
@@ -213,6 +219,7 @@ public List<QueryOption> getQueryOptions() {
213219

214220
/**
215221
* Gets the full list of options for this request.
222+
*
216223
* @return The full list of options for this request.
217224
*/
218225
public List<Option> getOptions() {
@@ -224,6 +231,7 @@ public List<Option> getOptions() {
224231

225232
/**
226233
* Sets the http method.
234+
*
227235
* @param httpMethod The http method.
228236
*/
229237
public void setHttpMethod(final HttpMethod httpMethod) {
@@ -232,6 +240,7 @@ public void setHttpMethod(final HttpMethod httpMethod) {
232240

233241
/**
234242
* Gets the client.
243+
*
235244
* @return The client.
236245
*/
237246
public IOneDriveClient getClient() {
@@ -240,6 +249,7 @@ public IOneDriveClient getClient() {
240249

241250
/**
242251
* Gets the response type.
252+
*
243253
* @return The response type.
244254
*/
245255
public Class getResponseType() {

onedrivesdk/src/main/java/com/onedrive/sdk/http/DefaultHttpProvider.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public class DefaultHttpProvider implements IHttpProvider {
5050
/**
5151
* The content type header
5252
*/
53-
static final String ContentTypeHeaderName = "Content-Type";
53+
static final String CONTENT_TYPE_HEADER_NAME = "Content-Type";
5454

5555
/**
5656
* The content type for json responses
5757
*/
58-
static final String JsonContentType = "application/json";
58+
static final String JSON_CONTENT_TYPE = "application/json";
5959

6060
/**
6161
* The serializer.
@@ -102,6 +102,7 @@ public DefaultHttpProvider(final ISerializer serializer,
102102

103103
/**
104104
* Gets the serializer for this http provider.
105+
*
105106
* @return The serializer for this provider.
106107
*/
107108
@Override
@@ -125,7 +126,7 @@ public <Result, Body> void send(final IHttpRequest request,
125126
final Body serializable) {
126127
final IProgressCallback<Result> progressCallback;
127128
if (callback instanceof IProgressCallback) {
128-
progressCallback = (IProgressCallback<Result>)callback;
129+
progressCallback = (IProgressCallback<Result>) callback;
129130
} else {
130131
progressCallback = null;
131132
}
@@ -135,10 +136,10 @@ public <Result, Body> void send(final IHttpRequest request,
135136
public void run() {
136137
try {
137138
mExecutors.performOnForeground(sendRequestInternal(request,
138-
resultClass,
139-
serializable,
140-
progressCallback),
141-
callback);
139+
resultClass,
140+
serializable,
141+
progressCallback),
142+
callback);
142143
} catch (final ClientException e) {
143144
mExecutors.performOnForeground(e, callback);
144145
}
@@ -211,13 +212,13 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
211212
} else if (serializable instanceof byte[]) {
212213
mLogger.logDebug("Sending byte[] as request body");
213214
bytesToWrite = (byte[]) serializable;
214-
connection.addRequestHeader(ContentTypeHeaderName, binaryContentType);
215+
connection.addRequestHeader(CONTENT_TYPE_HEADER_NAME, binaryContentType);
215216
connection.setContentLength(bytesToWrite.length);
216217
} else {
217218
mLogger.logDebug("Sending " + serializable.getClass().getName() + " as request body");
218219
final String serializeObject = mSerializer.serializeObject(serializable);
219220
bytesToWrite = serializeObject.getBytes();
220-
connection.addRequestHeader(ContentTypeHeaderName, JsonContentType);
221+
connection.addRequestHeader(CONTENT_TYPE_HEADER_NAME, JSON_CONTENT_TYPE);
221222
connection.setContentLength(bytesToWrite.length);
222223
}
223224

@@ -235,24 +236,24 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
235236
writtenSoFar = writtenSoFar + toWrite;
236237
if (progress != null) {
237238
mExecutors.performOnForeground(writtenSoFar, bytesToWrite.length,
238-
progress);
239+
progress);
239240
}
240-
} while (toWrite > 0);
241+
} while (toWrite > 0);
241242
bos.close();
242243
}
243244

244245
mLogger.logDebug(String.format("Response code %d, %s",
245-
connection.getResponseCode(),
246-
connection.getResponseMessage()));
246+
connection.getResponseCode(),
247+
connection.getResponseMessage()));
247248
if (connection.getResponseCode() >= httpClientErrorResponseCode
248-
&& !isAsyncOperation(resultClass)) {
249+
&& !isAsyncOperation(resultClass)) {
249250
mLogger.logDebug("Handling error response");
250251
in = connection.getInputStream();
251252
handleErrorResponse(request, serializable, connection);
252253
}
253254

254255
if (connection.getResponseCode() == httpNoBodyResponseCode
255-
|| connection.getResponseCode() == httpNotModified) {
256+
|| connection.getResponseCode() == httpNotModified) {
256257
mLogger.logDebug("Handling response with no body");
257258
return null;
258259
}
@@ -273,16 +274,16 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
273274
}
274275
in = new BufferedInputStream(connection.getInputStream());
275276
final Result result = handleJsonResponse(in, resultClass);
276-
((AsyncOperationStatus)result).seeOther = connection.getHeaders().get("Location");
277+
((AsyncOperationStatus) result).seeOther = connection.getHeaders().get("Location");
277278
return result;
278279
}
279280

280281
in = new BufferedInputStream(connection.getInputStream());
281282

282283
final Map<String, String> headers = connection.getHeaders();
283284

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)) {
286287
mLogger.logDebug("Response json");
287288
return handleJsonResponse(in, resultClass);
288289
} else {
@@ -306,15 +307,16 @@ private <Result, Body> Result sendRequestInternal(final IHttpRequest request,
306307
throw ex;
307308
} catch (final Exception ex) {
308309
final ClientException clientException = new ClientException("Error during http request",
309-
ex,
310-
OneDriveErrorCodes.GeneralException);
310+
ex,
311+
OneDriveErrorCodes.GeneralException);
311312
mLogger.logError("Error during http request", clientException);
312313
throw clientException;
313314
}
314315
}
315316

316317
/**
317318
* Checks if the given class is an async operation.
319+
*
318320
* @param resultClass The class to check.
319321
* @return true if the class is an async operation.
320322
*/
@@ -335,11 +337,12 @@ private <Body> void handleErrorResponse(final IHttpRequest request,
335337
final IConnection connection)
336338
throws IOException {
337339
throw OneDriveServiceException.createFromConnection(request, serializable, mSerializer,
338-
connection);
340+
connection);
339341
}
340342

341343
/**
342344
* Handles the cause where the response is a binary stream.
345+
*
343346
* @param in The input stream from the response.
344347
* @return The input stream to return to the caller.
345348
*/
@@ -365,6 +368,7 @@ private <Result> Result handleJsonResponse(final InputStream in, final Class<Res
365368

366369
/**
367370
* Sets the connection factory for this provider.
371+
*
368372
* @param factory The new factory.
369373
*/
370374
void setConnectionFactory(final IConnectionFactory factory) {
@@ -373,6 +377,7 @@ void setConnectionFactory(final IConnectionFactory factory) {
373377

374378
/**
375379
* Reads in a stream and converts it into a string.
380+
*
376381
* @param input The response body stream.
377382
* @return The string result.
378383
*/

onedrivesdk/src/main/java/com/onedrive/sdk/http/IConnection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,9 @@ public interface IConnection {
9090
*/
9191
String getRequestMethod();
9292

93-
void setContentLength(int length);
93+
/**
94+
* Set the Content-Length header
95+
* @param length the length of content
96+
*/
97+
void setContentLength(final int length);
9498
}

onedrivesdk/src/main/java/com/onedrive/sdk/http/OneDriveServiceException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public static <T> OneDriveServiceException createFromConnection(final IHttpReque
300300
OneDriveErrorResponse error = null;
301301
Exception parsingException = null;
302302

303-
final String contentType = headers.get(DefaultHttpProvider.ContentTypeHeaderName);
304-
if (contentType != null && contentType.contains(DefaultHttpProvider.JsonContentType)) {
303+
final String contentType = headers.get(DefaultHttpProvider.CONTENT_TYPE_HEADER_NAME);
304+
if (contentType != null && contentType.contains(DefaultHttpProvider.JSON_CONTENT_TYPE)) {
305305
try {
306306
error = serializer.deserializeObject(rawOutput, OneDriveErrorResponse.class);
307307
} catch (final Exception ex) {

onedrivesdk/src/main/java/com/onedrive/sdk/http/UrlConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public String getRequestMethod() {
124124
}
125125

126126
@Override
127-
public void setContentLength(int length) {
127+
public void setContentLength(final int length) {
128128
mConnection.setFixedLengthStreamingMode(length);
129129
}
130130

0 commit comments

Comments
 (0)