Skip to content

Commit 1e240e7

Browse files
authored
Merge pull request #1414 from digital-preservation/develop
DROID release 6.9.4
2 parents 626a5e9 + 7c32eb7 commit 1e240e7

File tree

31 files changed

+91
-99
lines changed

31 files changed

+91
-99
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
curl -X POST "https://api.github.com/repos/digital-preservation/droid/pulls" \
4747
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
4848
-H "Accept: application/vnd.github+json" \
49-
-d '{"title": "Version bump","head": "$BRANCH_NAME","base": "main"}'
49+
-d "{\"title\": \"Version bump\",\"head\": \"$BRANCH_NAME\",\"base\": \"main\"}"
5050
github-release:
5151
runs-on: ubuntu-latest
5252
steps:

droid-api/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>droid-parent</artifactId>
66
<groupId>uk.gov.nationalarchives</groupId>
7-
<version>6.9.3-SNAPSHOT</version>
7+
<version>6.9.4-SNAPSHOT</version>
88
<relativePath>../droid-parent</relativePath>
99
</parent>
1010

@@ -181,7 +181,7 @@
181181
<dependency>
182182
<groupId>org.apache.commons</groupId>
183183
<artifactId>commons-lang3</artifactId>
184-
<version>3.17.0</version>
184+
<version>3.18.0</version>
185185
</dependency>
186186
<dependency>
187187
<groupId>org.apache.httpcomponents</groupId>

droid-binary/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>droid-parent</artifactId>
66
<groupId>uk.gov.nationalarchives</groupId>
7-
<version>6.9.3-SNAPSHOT</version>
7+
<version>6.9.4-SNAPSHOT</version>
88
<relativePath>../droid-parent</relativePath>
99
</parent>
1010

droid-build-tools/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>droid-parent</artifactId>
66
<groupId>uk.gov.nationalarchives</groupId>
7-
<version>6.9.3-SNAPSHOT</version>
7+
<version>6.9.4-SNAPSHOT</version>
88
<relativePath>../droid-parent</relativePath>
99
</parent>
1010

droid-command-line/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>droid-parent</artifactId>
66
<groupId>uk.gov.nationalarchives</groupId>
7-
<version>6.9.3-SNAPSHOT</version>
7+
<version>6.9.4-SNAPSHOT</version>
88
<relativePath>../droid-parent</relativePath>
99
</parent>
1010

droid-container/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>droid-parent</artifactId>
66
<groupId>uk.gov.nationalarchives</groupId>
7-
<version>6.9.3-SNAPSHOT</version>
7+
<version>6.9.4-SNAPSHOT</version>
88
<relativePath>../droid-parent</relativePath>
99
</parent>
1010

@@ -141,7 +141,7 @@
141141
<dependency>
142142
<groupId>org.wiremock</groupId>
143143
<artifactId>wiremock</artifactId>
144-
<version>3.13.0</version>
144+
<version>3.13.1</version>
145145
<scope>test</scope>
146146
</dependency>
147147
</dependencies>

droid-core-interfaces/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>droid-parent</artifactId>
66
<groupId>uk.gov.nationalarchives</groupId>
7-
<version>6.9.3-SNAPSHOT</version>
7+
<version>6.9.4-SNAPSHOT</version>
88
<relativePath>../droid-parent</relativePath>
99
</parent>
1010

@@ -142,7 +142,7 @@
142142
<dependency>
143143
<groupId>commons-codec</groupId>
144144
<artifactId>commons-codec</artifactId>
145-
<version>1.18.0</version>
145+
<version>1.19.0</version>
146146
</dependency>
147147
<dependency>
148148
<groupId>net.java.truevfs</groupId>

droid-core-interfaces/src/main/java/uk/gov/nationalarchives/droid/core/interfaces/resource/HttpWindowReader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public HttpWindowReader(WindowCache cache, HttpUtils.HttpMetadata httpMetadata,
5858
this.length = httpMetadata.fileSize();
5959
}
6060

61-
private HttpResponse<byte[]> responseWithRange(long rangeStart, long rangeEnd) {
61+
private HttpResponse<byte[]> responseWithRange(long rangeStart, long rangeEnd) throws IOException {
6262
HttpRequest request = HttpRequest.newBuilder()
6363
.uri(this.uri)
6464
.header("Range", "bytes=" + rangeStart + "-" + rangeEnd)
@@ -67,7 +67,7 @@ private HttpResponse<byte[]> responseWithRange(long rangeStart, long rangeEnd) {
6767

6868
try {
6969
return httpClient.send(request, HttpResponse.BodyHandlers.ofByteArray());
70-
} catch (InterruptedException | IOException e) {
70+
} catch (InterruptedException e) {
7171
throw new RuntimeException(e);
7272
}
7373
}
@@ -92,6 +92,7 @@ public long length() throws IOException {
9292

9393
@Override
9494
public byte[] reloadWindowBytes(Window window) throws IOException {
95-
return new byte[0];
95+
long windowStart = window.getWindowPosition();
96+
return responseWithRange(windowStart, (windowStart + this.windowSize -1)).body();
9697
}
9798
}

droid-core-interfaces/src/main/java/uk/gov/nationalarchives/droid/core/interfaces/resource/S3WindowReader.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,29 @@ public S3WindowReader(WindowCache cache, S3Utils.S3ObjectMetadata s3ObjectMetada
6565
@Override
6666
protected Window createWindow(long windowStart) throws IOException {
6767
if (windowStart >= 0 && windowStart < length) {
68-
String key = this.s3ObjectMetadata.key().orElseThrow(() -> new RuntimeException(this.s3ObjectMetadata.key() + " not found"));
69-
GetObjectRequest getS3ObjectRequest = GetObjectRequest.builder()
70-
.bucket(this.s3ObjectMetadata.bucket())
71-
.key(key)
72-
.range("bytes=" + windowStart + "-" + (windowStart + this.windowSize -1))
73-
.build();
74-
75-
76-
ResponseInputStream<GetObjectResponse> response = s3Client.getObject(getS3ObjectRequest);
77-
byte[] bytes = toByteArray(response);
68+
byte[] bytes = bytesForRange(windowStart);
7869
int totalRead = bytes.length;
79-
response.close();
8070
if (totalRead > 0) {
8171
return new SoftWindow(bytes, windowStart, totalRead, this);
8272
}
8373
}
8474
return null;
8575
}
8676

87-
private static byte[] toByteArray(ResponseInputStream<GetObjectResponse> inputStream) throws IOException {
77+
private byte[] bytesForRange(long windowStart) throws IOException {
78+
String key = this.s3ObjectMetadata.key().orElseThrow(() -> new RuntimeException(this.s3ObjectMetadata.key() + " not found"));
79+
GetObjectRequest getS3ObjectRequest = GetObjectRequest.builder()
80+
.bucket(this.s3ObjectMetadata.bucket())
81+
.key(key)
82+
.range("bytes=" + windowStart + "-" + (windowStart + this.windowSize -1))
83+
.build();
84+
85+
try (ResponseInputStream<GetObjectResponse> response = s3Client.getObject(getS3ObjectRequest)) {
86+
return toByteArray(response);
87+
}
88+
}
89+
90+
private byte[] toByteArray(ResponseInputStream<GetObjectResponse> inputStream) throws IOException {
8891
try (InputStream in = inputStream; ByteArrayOutputStream out = new ByteArrayOutputStream()) {
8992
byte[] buffer = new byte[BUFFER_LENGTH];
9093
int bytesRead;
@@ -102,6 +105,7 @@ public long length() throws IOException {
102105

103106
@Override
104107
public byte[] reloadWindowBytes(Window window) throws IOException {
105-
return new byte[0];
108+
long windowStart = window.getWindowPosition();
109+
return bytesForRange(windowStart);
106110
}
107111
}

droid-core-interfaces/src/test/java/uk/gov/nationalarchives/droid/core/interfaces/resource/HttpWindowReaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ public void testWindowReaderReturnsErrorOnHttpFailure() throws Exception {
8383
HttpClient httpClient = mock(HttpClient.class);
8484
HttpUtils.HttpMetadata httpMetadata = new HttpUtils.HttpMetadata(4L, 0L, URI.create("https://example.com"));
8585
when(httpClient.send(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenThrow(new IOException("Error contacting server"));
86-
assertThrows(RuntimeException.class, () -> new HttpWindowReader(windowCache, httpMetadata, httpClient).getWindow(0));
86+
assertThrows(IOException.class, () -> new HttpWindowReader(windowCache, httpMetadata, httpClient).getWindow(0));
8787
}
8888
}

0 commit comments

Comments
 (0)