Skip to content

Commit a04a20a

Browse files
committed
OAK-11377: Remove usage of Guava ByteStreams.toByteArray()
1 parent db447dc commit a04a20a

File tree

9 files changed

+22
-37
lines changed

9 files changed

+22
-37
lines changed

oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapServerClassLoader.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
1817
package org.apache.jackrabbit.oak.security.authentication.ldap;
1918

20-
import org.apache.jackrabbit.guava.common.io.ByteStreams;
21-
2219
import ch.qos.logback.classic.Logger;
2320
import ch.qos.logback.core.Appender;
2421

@@ -47,10 +44,14 @@ public class LdapServerClassLoader extends URLClassLoader {
4744

4845
private LdapServerClassLoader(URL[] urls, Class serverClass, Class serverBaseClass) throws IOException {
4946
super(urls, ClassLoader.getSystemClassLoader().getParent());
50-
this.serverClassResource = ByteStreams.toByteArray(
51-
serverClass.getResourceAsStream("/".concat(serverClass.getCanonicalName()).replace('.', '/').concat(".class")));
52-
this.serverBaseClassResource = ByteStreams.toByteArray(
53-
serverBaseClass.getResourceAsStream("/".concat(serverBaseClass.getCanonicalName()).replace('.', '/').concat(".class")));
47+
this.serverClassResource = classAsBytes(serverClass);
48+
this.serverBaseClassResource = classAsBytes(serverBaseClass);
49+
}
50+
51+
private static byte[] classAsBytes(Class base) throws IOException {
52+
try (InputStream is = base.getResourceAsStream("/".concat(base.getCanonicalName()).replace('.', '/').concat(".class"))) {
53+
return is.readAllBytes();
54+
}
5455
}
5556

5657
public static LdapServerClassLoader createServerClassLoader() throws URISyntaxException, ClassNotFoundException, IOException {

oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/cloud/CloudBlobStore.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.NoSuchElementException;
2626
import java.util.Objects;
2727

28-
import org.apache.jackrabbit.guava.common.io.ByteStreams;
2928
import org.apache.jackrabbit.oak.commons.StringUtils;
3029
import org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore;
3130
import org.jclouds.ContextBuilder;
@@ -160,7 +159,7 @@ protected byte[] readBlockFromBackend(BlockId blockId) throws Exception {
160159

161160
Payload payload = cloudBlob.getPayload();
162161
try {
163-
data = ByteStreams.toByteArray(payload.getInput());
162+
data = payload.getInput().readAllBytes();
164163
cache.put(id, data);
165164
} finally {
166165
payload.close();

oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/directaccess/AbstractDataRecordAccessProviderIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.jackrabbit.core.data.DataStoreException;
3535
import org.junit.Test;
3636

37-
import static org.apache.jackrabbit.guava.common.io.ByteStreams.toByteArray;
3837
import static org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils.randomStream;
3938
import static org.junit.Assert.assertEquals;
4039
import static org.junit.Assert.assertNotNull;
@@ -111,7 +110,7 @@ public void testMultiPartDirectUploadIT() throws DataRecordUploadException, Data
111110
assertNotNull(retrievedRecord);
112111

113112
in.reset();
114-
assertTrue(Arrays.equals(toByteArray(in), toByteArray(retrievedRecord.getStream())));
113+
assertTrue(Arrays.equals(in.readAllBytes(), retrievedRecord.getStream().readAllBytes()));
115114
}
116115
finally {
117116
if (null != uploadedRecord) {

oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/datastore/directaccess/AbstractDataRecordAccessProviderTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848

4949
import org.apache.jackrabbit.guava.common.base.Strings;
5050

51-
import static org.apache.jackrabbit.guava.common.io.ByteStreams.toByteArray;
5251
import static org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils.randomStream;
5352
import static org.junit.Assert.assertEquals;
5453
import static org.junit.Assert.assertFalse;
@@ -165,7 +164,7 @@ record = doSynchronousAddRecord((DataStore) dataStore, testStream);
165164
assertEquals(200, conn.getResponseCode());
166165

167166
testStream.reset();
168-
assertTrue(Arrays.equals(toByteArray(testStream), toByteArray(conn.getInputStream())));
167+
assertTrue(Arrays.equals(testStream.readAllBytes(), conn.getInputStream().readAllBytes()));
169168
}
170169
finally {
171170
if (null != record) {
@@ -240,7 +239,7 @@ record = doSynchronousAddRecord((DataStore) dataStore, testStream);
240239
);
241240

242241
testStream.reset();
243-
assertTrue(Arrays.equals(toByteArray(testStream), toByteArray(conn.getInputStream())));
242+
assertTrue(Arrays.equals(testStream.readAllBytes(), conn.getInputStream().readAllBytes()));
244243
}
245244
}
246245
finally {
@@ -586,7 +585,7 @@ public void testSinglePutDirectUploadIT() throws DataRecordUploadException, Data
586585
DataRecord retrievedRecord = doGetRecord((DataStore) ds, uploadedRecord.getIdentifier());
587586
assertNotNull(retrievedRecord);
588587
uploadStream.reset();
589-
assertTrue(Arrays.equals(toByteArray(uploadStream), toByteArray(retrievedRecord.getStream())));
588+
assertTrue(Arrays.equals(uploadStream.readAllBytes(), retrievedRecord.getStream().readAllBytes()));
590589
}
591590
finally {
592591
if (null != uploadedRecord) {

oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/CompactionAndCleanupIT.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import java.util.concurrent.atomic.AtomicReference;
6262
import java.util.function.Consumer;
6363

64-
import org.apache.jackrabbit.guava.common.io.ByteStreams;
6564
import org.apache.jackrabbit.oak.api.Blob;
6665
import org.apache.jackrabbit.oak.api.CommitFailedException;
6766
import org.apache.jackrabbit.oak.api.PropertyState;
@@ -218,8 +217,8 @@ public void compactionNoBinaryClone() throws Exception {
218217
long size7 = fileStore.getStats().getApproximateSize();
219218

220219
// No data loss
221-
byte[] blob = ByteStreams.toByteArray(nodeStore.getRoot()
222-
.getProperty("blob2").getValue(Type.BINARY).getNewStream());
220+
byte[] blob = nodeStore.getRoot()
221+
.getProperty("blob2").getValue(Type.BINARY).getNewStream().readAllBytes();
223222
assertEquals(blobSize, blob.length);
224223
} finally {
225224
fileStore.close();
@@ -308,8 +307,8 @@ public void offlineCompaction() throws Exception {
308307
assertTrue("the blob should not be collected", size7 > blobSize);
309308

310309
// No data loss
311-
byte[] blob = ByteStreams.toByteArray(nodeStore.getRoot()
312-
.getProperty("blob2").getValue(Type.BINARY).getNewStream());
310+
byte[] blob = nodeStore.getRoot()
311+
.getProperty("blob2").getValue(Type.BINARY).getNewStream().readAllBytes();
313312
assertEquals(blobSize, blob.length);
314313
} finally {
315314
fileStore.close();

oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/BlobThroughPutTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.concurrent.atomic.AtomicBoolean;
2929

3030
import org.apache.commons.collections4.bidimap.DualHashBidiMap;
31-
import org.apache.jackrabbit.guava.common.io.ByteStreams;
3231
import com.mongodb.BasicDBObject;
3332
import com.mongodb.MongoClient;
3433
import com.mongodb.MongoClientURI;
@@ -201,7 +200,7 @@ private static class Benchmark {
201200

202201
static {
203202
try {
204-
DATA = ByteStreams.toByteArray(new RandomStream(BLOB_SIZE, 100));
203+
DATA = (new RandomStream(BLOB_SIZE, 100)).readAllBytes();
205204
} catch (IOException e) {
206205
throw new IllegalStateException(e);
207206
}

oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.Objects;
3636
import java.util.StringJoiner;
3737

38-
import org.apache.jackrabbit.guava.common.io.ByteStreams;
3938
import org.apache.jackrabbit.oak.api.Blob;
4039
import org.apache.jackrabbit.oak.api.PropertyState;
4140
import org.apache.jackrabbit.oak.api.Type;
@@ -538,7 +537,7 @@ public NodeBuilder removeProperty(String name) {
538537
@Override
539538
public Blob createBlob(InputStream stream) throws IOException {
540539
try {
541-
return new ArrayBasedBlob(ByteStreams.toByteArray(stream));
540+
return new ArrayBasedBlob(stream.readAllBytes());
542541
} finally {
543542
stream.close();
544543
}

oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import java.util.concurrent.atomic.AtomicInteger;
3434
import java.util.concurrent.atomic.AtomicReference;
3535

36-
import org.apache.jackrabbit.guava.common.io.ByteStreams;
37-
3836
import org.apache.jackrabbit.oak.api.Blob;
3937
import org.apache.jackrabbit.oak.api.CommitFailedException;
4038
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
@@ -182,7 +180,7 @@ public NodeState reset(@NotNull NodeBuilder builder) {
182180
@Override
183181
public ArrayBasedBlob createBlob(InputStream inputStream) throws IOException {
184182
try {
185-
return new ArrayBasedBlob(ByteStreams.toByteArray(inputStream));
183+
return new ArrayBasedBlob(inputStream.readAllBytes());
186184
}
187185
finally {
188186
inputStream.close();

oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/value/Conversions.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import java.util.Calendar;
2626
import java.util.TimeZone;
2727

28-
import org.apache.jackrabbit.guava.common.io.ByteStreams;
29-
3028
import org.apache.jackrabbit.oak.api.Blob;
3129
import org.apache.jackrabbit.oak.api.Type;
3230
import org.apache.jackrabbit.oak.plugins.memory.StringBasedBlob;
@@ -156,14 +154,8 @@ public static Converter convert(final Blob value) {
156154
return new Converter() {
157155
@Override
158156
public String toString() {
159-
try {
160-
InputStream in = value.getNewStream();
161-
try {
162-
return new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8);
163-
}
164-
finally {
165-
in.close();
166-
}
157+
try (InputStream in = value.getNewStream()) {
158+
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
167159
}
168160
catch (IOException e) {
169161
throw new IllegalArgumentException(e);

0 commit comments

Comments
 (0)