Skip to content

Commit 1c84478

Browse files
authored
Merge pull request #162 from microsoftgraph/feature/large-file-align
feature/large file align
2 parents df86d48 + aed7d1f commit 1c84478

10 files changed

+134
-106
lines changed

spotBugsExcludeFilter.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
99
<Bug code="NP" />
1010
</Match>
1111
<Match>
12-
<Class name="com.microsoft.graph.concurrency.ChunkedUploadRequest" />
12+
<Class name="com.microsoft.graph.tasks.LargeFileUploadRequest" />
1313
<Bug code="Dm" />
1414
</Match>
1515
<Match>
16-
<Class name="com.microsoft.graph.concurrency.ChunkedUploadResponseHandler" />
16+
<Class name="com.microsoft.graph.tasks.LargeFileUploadResponseHandler" />
1717
<Method name="generateResult" />
1818
<Bug code="RCN,NP" />
1919
</Match>

src/main/java/com/microsoft/graph/http/CoreHttpProvider.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,6 @@ private <Result, Body, DeserializeType> Result processResponse(final Response re
404404

405405
// Call being executed
406406

407-
408-
if (handler != null) {
409-
handler.configConnection(response);
410-
}
411-
412407
logger.logDebug(String.format(Locale.ROOT, "Response code %d, %s",
413408
response.code(),
414409
response.message()));

src/main/java/com/microsoft/graph/http/IStatefulResponseHandler.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import javax.annotation.Nullable;
3030
import javax.annotation.Nonnull;
3131

32-
import okhttp3.Response;
33-
3432
/**
3533
* The handler interface for requests having stateful response from server.
3634
* The handler will custom the HTTP connection if needed and generate request
@@ -40,26 +38,20 @@
4038
* @param <DeserializedType> the deserialize type for serializer
4139
*/
4240
public interface IStatefulResponseHandler<ResultType, DeserializedType> {
43-
/**
44-
* Configure the response
45-
*
46-
* @param response the HTTP response
47-
*/
48-
void configConnection(@Nonnull final Response response);
49-
5041
/**
5142
* Generate result after receiving response
5243
*
5344
* @param request the HTTP request
5445
* @param response the HTTP connection
5546
* @param serializer the serializer for parsing response
5647
* @param logger the logger
48+
* @param <ResponseType> the native http client response type
5749
* @return the result generated by this handler
5850
* @throws Exception an exception occurs if the request was unable to complete for any reason
5951
*/
6052
@Nullable
61-
ResultType generateResult(@Nonnull final IHttpRequest request,
62-
@Nonnull final Response response,
53+
<ResponseType> ResultType generateResult(@Nonnull final IHttpRequest request,
54+
@Nonnull final ResponseType response,
6355
@Nonnull final ISerializer serializer,
6456
@Nonnull final ILogger logger) throws Exception;
6557
}

src/main/java/com/microsoft/graph/concurrency/IProgressCallback.java renamed to src/main/java/com/microsoft/graph/tasks/IProgressCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// THE SOFTWARE.
2121
// ------------------------------------------------------------------------------
2222

23-
package com.microsoft.graph.concurrency;
23+
package com.microsoft.graph.tasks;
2424

2525
/**
2626
* A callback that describes how to deal with success, failure, and progress

src/main/java/com/microsoft/graph/concurrency/IUploadSession.java renamed to src/main/java/com/microsoft/graph/tasks/IUploadSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// THE SOFTWARE.
2121
// ------------------------------------------------------------------------------
2222

23-
package com.microsoft.graph.concurrency;
23+
package com.microsoft.graph.tasks;
2424

2525
import java.util.List;
2626

src/main/java/com/microsoft/graph/concurrency/ChunkedUploadRequest.java renamed to src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
33
// ------------------------------------------------------------------------------
44

5-
package com.microsoft.graph.concurrency;
5+
package com.microsoft.graph.tasks;
66

77
import java.util.List;
88
import java.util.Locale;
@@ -21,7 +21,7 @@
2121
* The chunk upload request.
2222
* @param <UploadType> The upload item type.
2323
*/
24-
public class ChunkedUploadRequest<UploadType> {
24+
class LargeFileUploadRequest<UploadType> {
2525

2626
/**
2727
* Content Range header name.
@@ -41,7 +41,7 @@ public class ChunkedUploadRequest<UploadType> {
4141
/**
4242
* The base request.
4343
*/
44-
private final BaseRequest<ChunkedUploadResult<UploadType>> baseRequest;
44+
private final BaseRequest<LargeFileUploadResponse<UploadType>> baseRequest;
4545

4646
/**
4747
* Construct the ChunkedUploadRequest
@@ -55,7 +55,7 @@ public class ChunkedUploadRequest<UploadType> {
5555
* @param totalLength The total length of the input stream.
5656
*/
5757
@SuppressWarnings("unchecked")
58-
protected ChunkedUploadRequest(@Nonnull final String requestUrl,
58+
protected LargeFileUploadRequest(@Nonnull final String requestUrl,
5959
@Nonnull final IBaseClient<?> client,
6060
@Nullable final List<? extends Option> options,
6161
@Nonnull final byte[] chunk,
@@ -67,7 +67,7 @@ protected ChunkedUploadRequest(@Nonnull final String requestUrl,
6767
Objects.requireNonNull(chunk, "parameter chunk cannot be null");
6868
this.data = new byte[chunkSize];
6969
System.arraycopy(chunk, 0, this.data, 0, chunkSize);
70-
this.baseRequest = new BaseRequest<ChunkedUploadResult<UploadType>>(requestUrl, client, options, (Class<? extends ChunkedUploadResult<UploadType>>)(new ChunkedUploadResult<>((UploadType)null)).getClass()) {
70+
this.baseRequest = new BaseRequest<LargeFileUploadResponse<UploadType>>(requestUrl, client, options, (Class<? extends LargeFileUploadResponse<UploadType>>)(new LargeFileUploadResponse<>((UploadType)null)).getClass()) {
7171
};
7272
this.baseRequest.setHttpMethod(HttpMethod.PUT);
7373
this.baseRequest.addHeader(CONTENT_RANGE_HEADER_NAME,
@@ -86,24 +86,24 @@ protected ChunkedUploadRequest(@Nonnull final String requestUrl,
8686
*/
8787
@SuppressWarnings("unchecked")
8888
@Nonnull
89-
public ChunkedUploadResult<UploadType> upload(
90-
@Nonnull final ChunkedUploadResponseHandler<UploadType> responseHandler) {
89+
public LargeFileUploadResponse<UploadType> upload(
90+
@Nonnull final LargeFileUploadResponseHandler<UploadType> responseHandler) {
9191
Objects.requireNonNull(responseHandler, "parameter responseHandler cannot be null");
92-
ChunkedUploadResult<UploadType> result = null;
92+
LargeFileUploadResponse<UploadType> result = null;
9393

9494
try {
9595
result = this.baseRequest
9696
.getClient()
9797
.getHttpProvider()
98-
.send(baseRequest, (Class<ChunkedUploadResult<UploadType>>)(Class<?>) ChunkedUploadResult.class, this.data, responseHandler);
98+
.send(baseRequest, (Class<LargeFileUploadResponse<UploadType>>)(Class<?>) LargeFileUploadResponse.class, this.data, responseHandler);
9999
} catch (final ClientException e) {
100100
throw new ClientException("Request failed with error, retry if necessary.", e);
101101
}
102102

103103
if (result != null && result.chunkCompleted()) {
104104
return result;
105105
} else
106-
return new ChunkedUploadResult<UploadType>(
106+
return new LargeFileUploadResponse<UploadType>(
107107
new ClientException("Upload session failed.", result == null ? null : result.getError()));
108108
}
109109
}

src/main/java/com/microsoft/graph/concurrency/ChunkedUploadResult.java renamed to src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponse.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
33
// ------------------------------------------------------------------------------
44

5-
package com.microsoft.graph.concurrency;
5+
package com.microsoft.graph.tasks;
66

77
import com.microsoft.graph.core.ClientException;
88
import com.microsoft.graph.http.GraphServiceException;
@@ -16,7 +16,11 @@
1616
/**
1717
* Wrapper class for different upload response from server.
1818
*/
19-
public class ChunkedUploadResult<UploadType> {
19+
class LargeFileUploadResponse<UploadType> {
20+
/**
21+
* The location header from the response if provided
22+
*/
23+
private final String location;
2024
/**
2125
* The uploaded item response.
2226
*/
@@ -33,54 +37,69 @@ public class ChunkedUploadResult<UploadType> {
3337
private final ClientException error;
3438

3539
/**
36-
* Construct result with item created.
40+
* Constructs response with the location header.
41+
*
42+
* @param location The location returned by the response
43+
*/
44+
protected LargeFileUploadResponse(@Nullable final String location) {
45+
this.location = location;
46+
this.error = null;
47+
this.session = null;
48+
this.uploadedItem = null;
49+
}
50+
51+
/**
52+
* Construct response with item created.
3753
*
3854
* @param uploaded The created item.
3955
*/
40-
protected ChunkedUploadResult(@Nullable final UploadType uploaded) {
56+
protected LargeFileUploadResponse(@Nullable final UploadType uploaded) {
4157
this.uploadedItem = uploaded;
4258
this.session = null;
4359
this.error = null;
60+
this.location = null;
4461
}
4562

4663
/**
47-
* Construct result with next session.
64+
* Construct response with next session.
4865
*
4966
* @param session The next session.
5067
*/
51-
protected ChunkedUploadResult(@Nullable final IUploadSession session) {
68+
protected LargeFileUploadResponse(@Nullable final IUploadSession session) {
5269
this.session = session;
5370
this.uploadedItem = null;
5471
this.error = null;
72+
this.location = null;
5573
}
5674

5775
/**
58-
* Construct result with error.
76+
* Construct response with error.
5977
*
6078
* @param error The error occurred during uploading.
6179
*/
62-
protected ChunkedUploadResult(@Nullable final ClientException error) {
80+
protected LargeFileUploadResponse(@Nullable final ClientException error) {
6381
this.error = error;
6482
this.uploadedItem = null;
6583
this.session = null;
84+
this.location = null;
6685
}
6786

6887
/**
69-
* Construct result with server exception.
88+
* Construct response with server exception.
7089
*
7190
* @param exception The exception received from server.
7291
*/
73-
protected ChunkedUploadResult(@Nonnull final GraphServiceException exception) {
92+
protected LargeFileUploadResponse(@Nonnull final GraphServiceException exception) {
7493
this(new ClientException(Objects
7594
.requireNonNull(exception, "parameter exception cannot be null")
7695
.getMessage(/* verbose */ true),
7796
exception));
7897
}
7998

8099
/**
81-
* Checks the chunk upload is completed.
100+
* Checks the large upload range is completed.
82101
*
83-
* @return true if current chunk upload is completed.
102+
* @return true if current large upload range is completed.
84103
*/
85104
public boolean chunkCompleted() {
86105
return this.uploadedItem != null || this.session != null;
@@ -92,7 +111,7 @@ public boolean chunkCompleted() {
92111
* @return true if the response is an item.
93112
*/
94113
public boolean uploadCompleted() {
95-
return this.uploadedItem != null;
114+
return this.uploadedItem != null || this.location != null;
96115
}
97116

98117
/**
@@ -133,4 +152,12 @@ public IUploadSession getSession() {
133152
public ClientException getError() {
134153
return this.error;
135154
}
155+
/**
156+
* Get the location.
157+
* @return The location.
158+
*/
159+
@Nullable
160+
public String getLocation () {
161+
return this.location;
162+
}
136163
}

0 commit comments

Comments
 (0)