Skip to content

Commit e1c6970

Browse files
authored
Merge branch 'main' into sdk-4293-fix-creation-ongoing-legal-hold-policy-with-start-date
2 parents a25018e + 8cf8696 commit e1c6970

File tree

9 files changed

+100
-35
lines changed

9 files changed

+100
-35
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [4.13.1](https://github.com/box/box-java-sdk/compare/v4.13.0...v4.13.1) (2024-11-29)
6+
7+
8+
### Bug Fixes:
9+
10+
* Correctly calculate `Content-Length` when reading from a stream ([#1277](https://github.com/box/box-java-sdk/issues/1277)) ([b1d5371](https://github.com/box/box-java-sdk/commit/b1d5371491abe1729a95eb9dc39d375135c8681d))
11+
512
## [4.13.0](https://github.com/box/box-java-sdk/compare/v4.12.0...v4.13.0) (2024-11-21)
613

714

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The Box Java SDK for interacting with the
1414
[Box Content API](https://developers.box.com/docs/).
1515

1616
## Latest Release
17-
Latest release can be found [here](https://github.com/box/box-java-sdk/tree/v4.13.0).
17+
Latest release can be found [here](https://github.com/box/box-java-sdk/tree/v4.13.1).
1818

1919
## Upgrades
2020
You can read about how to migrate to the 4 version [here](doc/upgrades/3.x.x%20to%204.x.x.md).
@@ -233,31 +233,31 @@ You can find guides and tutorials in the `doc` directory.
233233

234234
* [BUILD ON BOX PLATFORM](https://developer.box.com/guides/getting-started/)
235235
* [Javadocs](http://box.github.io/box-java-sdk/javadoc/com/box/sdk/package-summary.html)
236-
* [Overview](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/overview.md)
237-
* [Configuration](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/configuration.md)
238-
* [Logging](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/logging.md)
239-
* [Authentication](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/authentication.md)
240-
* [Files](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/files.md)
241-
* [Folders](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/folders.md)
242-
* [Comments](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/comments.md)
243-
* [Collaborations](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/collaborations.md)
244-
* [Collaboration Allowlists](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/collaboration_allowlists.md)
245-
* [Events](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/events.md)
246-
* [Search](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/search.md)
247-
* [Users](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/users.md)
248-
* [Groups](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/groups.md)
249-
* [Tasks](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/tasks.md)
250-
* [Trash](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/trash.md)
251-
* [Collections](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/collections.md)
252-
* [Devices](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/devices.md)
253-
* [Retention Policies](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/retention_policies.md)
254-
* [Legal Holds Policy](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/legal_holds.md)
255-
* [Watermarking](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/watermarking.md)
256-
* [Webhooks](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/webhooks.md)
257-
* [Web Links](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/weblinks.md)
258-
* [Metadata Templates](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/metadata_template.md)
259-
* [Classifications](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/classifications.md)
260-
* [Recent Items](https://github.com/box/box-java-sdk/blob/v4.13.0/doc/recent_items.md)
236+
* [Overview](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/overview.md)
237+
* [Configuration](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/configuration.md)
238+
* [Logging](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/logging.md)
239+
* [Authentication](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/authentication.md)
240+
* [Files](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/files.md)
241+
* [Folders](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/folders.md)
242+
* [Comments](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/comments.md)
243+
* [Collaborations](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/collaborations.md)
244+
* [Collaboration Allowlists](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/collaboration_allowlists.md)
245+
* [Events](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/events.md)
246+
* [Search](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/search.md)
247+
* [Users](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/users.md)
248+
* [Groups](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/groups.md)
249+
* [Tasks](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/tasks.md)
250+
* [Trash](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/trash.md)
251+
* [Collections](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/collections.md)
252+
* [Devices](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/devices.md)
253+
* [Retention Policies](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/retention_policies.md)
254+
* [Legal Holds Policy](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/legal_holds.md)
255+
* [Watermarking](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/watermarking.md)
256+
* [Webhooks](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/webhooks.md)
257+
* [Web Links](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/weblinks.md)
258+
* [Metadata Templates](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/metadata_template.md)
259+
* [Classifications](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/classifications.md)
260+
* [Recent Items](https://github.com/box/box-java-sdk/blob/v4.13.1/doc/recent_items.md)
261261

262262

263263
Javadocs are generated when `gradle javadoc` is run and can be found in

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sourceCompatibility = 1.8
1313

1414
group = "com.box"
1515
archivesBaseName = "box-java-sdk"
16-
version = "4.13.0"
16+
version = "4.13.1"
1717

1818
java {
1919
withJavadocJar()

src/intTest/java/com/box/sdk/BoxAIIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void aiExtractStructuredWithMetadataTemplate() throws InterruptedExceptio
317317
JsonObject sourceJson = response.getSourceJson();
318318
assertThat(sourceJson.get("firstName").asString(), is(equalTo("John")));
319319
assertThat(sourceJson.get("lastName").asString(), is(equalTo("Doe")));
320-
assertThat(sourceJson.get("dateOfBirth").asString(), is(equalTo("1990-07-04")));
320+
assertThat(sourceJson.get("dateOfBirth").asString(), is(equalTo("1990-07-04T00:00:00Z")));
321321
assertThat(sourceJson.get("age").asInt(), is(equalTo(34)));
322322
assertThat(sourceJson.get("hobby").asArray().get(0).asString(), is(equalTo("guitar")));
323323
assertThat(sourceJson.get("hobby").asArray().get(1).asString(), is(equalTo("books")));

src/intTest/java/com/box/sdk/BoxFileIT.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,27 @@ public void getRepresentationContentSucceeds() throws InterruptedException {
146146
}
147147
}
148148

149+
@Test
150+
public void getRepresentationContentWithExtractedTextSucceeds() throws InterruptedException {
151+
BoxAPIConnection api = jwtApiForServiceAccount();
152+
String fileName = "text.pdf";
153+
BoxFile file = null;
154+
try {
155+
file = uploadSampleFileToUniqueFolder(api, fileName);
156+
final String fileId = file.getID();
157+
String representationHint = "[extracted_text]";
158+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
159+
Retry.retry(() -> {
160+
new BoxFile(api, fileId).getRepresentationContent(representationHint, outputStream);
161+
byte[] downloadedRepresentationContent = outputStream.toByteArray();
162+
String text = new String(downloadedRepresentationContent, StandardCharsets.UTF_8);
163+
assertTrue(text.contains("Lorem ipsum"));
164+
}, 5, 100);
165+
} finally {
166+
deleteFile(file);
167+
}
168+
}
169+
149170
@Test
150171
public void uploadFileStreamSucceeds() {
151172
BoxAPIConnection api = jwtApiForServiceAccount();
@@ -156,7 +177,7 @@ public void uploadFileStreamSucceeds() {
156177

157178
BoxFile uploadedFile = null;
158179
try {
159-
InputStream uploadStream = new ByteArrayInputStream(fileContent);
180+
InputStream uploadStream = new ByteArrayInputStream(fileContent);
160181
BoxFile.Info uploadedFileInfo = folder.uploadFile(uploadStream, BoxFileIT.generateString());
161182
uploadedFile = uploadedFileInfo.getResource();
162183

@@ -552,11 +573,11 @@ public void canPaginateOverListOfVersions() {
552573

553574
byte[] fileBytes = "Version 2".getBytes(StandardCharsets.UTF_8);
554575
uploadedFile.uploadNewVersion(
555-
new ByteArrayInputStream(fileBytes), null, fileBytes.length, mock(ProgressListener.class));
576+
new ByteArrayInputStream(fileBytes), null, fileBytes.length, mock(ProgressListener.class));
556577

557578
fileBytes = "Version 3".getBytes(StandardCharsets.UTF_8);
558579
uploadedFile.uploadNewVersion(
559-
new ByteArrayInputStream(fileBytes), null, fileBytes.length, mock(ProgressListener.class));
580+
new ByteArrayInputStream(fileBytes), null, fileBytes.length, mock(ProgressListener.class));
560581

561582
Collection<BoxFileVersion> versionsPart1 = uploadedFile.getVersionsRange(0, 1);
562583
assertThat(versionsPart1.size(), is(1));

src/main/java/com/box/sdk/BinaryBodyUtils.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.box.sdk;
22

3+
import com.box.sdk.http.HttpHeaders;
34
import java.io.IOException;
45
import java.io.InputStream;
56
import java.io.OutputStream;
@@ -73,12 +74,43 @@ static void writeStreamWithContentLength(BoxAPIResponse response, OutputStream o
7374
} else {
7475
input = response.getBody();
7576
}
76-
writeStreamTo(input, output, response.getContentLength());
77+
writeStreamTo(input, output, getContentLengthFromAPIResponse(response));
7778
} finally {
7879
response.close();
7980
}
8081
}
8182

83+
/**
84+
* Get the content length from the API response.
85+
* In some cases, the Content-Length is not provided in the response headers.
86+
* This could happen when getting the content representation for a compressed data.
87+
* In that case the API will switch to chunk mode and provide the length in the "X-Original-Content-Length" header.
88+
*
89+
* @param response API response.
90+
* @return Content length.
91+
*/
92+
private static long getContentLengthFromAPIResponse(BoxAPIResponse response) {
93+
long length = response.getContentLength();
94+
if (length == -1) {
95+
String headerValue = null;
96+
if (response.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH)) {
97+
headerValue = response.getHeaders().get(HttpHeaders.CONTENT_LENGTH).get(0);
98+
} else if (response.getHeaders().containsKey(HttpHeaders.X_ORIGINAL_CONTENT_LENGTH)) {
99+
headerValue = response.getHeaders().get(HttpHeaders.X_ORIGINAL_CONTENT_LENGTH).get(0);
100+
}
101+
102+
if (headerValue != null) {
103+
try {
104+
length = Integer.parseInt(headerValue);
105+
} catch (NumberFormatException e) {
106+
throw new RuntimeException("Invalid content length: " + headerValue);
107+
}
108+
}
109+
}
110+
111+
return length;
112+
}
113+
82114
/**
83115
* Writes content of input stream to provided output.
84116
*
@@ -126,8 +158,8 @@ static void writeStreamTo(InputStream input, OutputStream output, long expectedL
126158
totalBytesRead += n; // Track the total bytes read
127159
}
128160
if (totalBytesRead != expectedLength) {
129-
throw new IOException("Stream ended prematurely. Expected " + expectedLength
130-
+ " bytes, but read " + totalBytesRead + " bytes.");
161+
throw new IOException("Stream ended prematurely. Expected "
162+
+ expectedLength + " bytes, but read " + totalBytesRead + " bytes.");
131163
}
132164
} catch (IOException e) {
133165
throw new RuntimeException("Error during streaming: " + e.getMessage(), e);

src/main/java/com/box/sdk/BoxAPIConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class BoxAPIConnection {
8585
private static final String BOX_NOTIFICATIONS_HEADER = "Box-Notifications";
8686

8787
private static final String JAVA_VERSION = System.getProperty("java.version");
88-
private static final String SDK_VERSION = "4.13.0";
88+
private static final String SDK_VERSION = "4.13.1";
8989

9090
/**
9191
* The amount of buffer time, in milliseconds, to use when determining if an access token should be refreshed. For

src/main/java/com/box/sdk/http/HttpHeaders.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public final class HttpHeaders {
1010
*/
1111
public static final String CONTENT_LENGTH = "Content-Length";
1212

13+
/**
14+
* HTTP header key X-Original-Content-Length.
15+
*/
16+
public static final String X_ORIGINAL_CONTENT_LENGTH = "X-Original-Content-Length";
17+
1318
/**
1419
* HTTP header key Content-Type.
1520
*/
11.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)