This is an automated email from the ASF dual-hosted git repository. reschke pushed a commit to branch OAK-11406 in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 52ead1f04411c756c93b3a6ca223e969e25a7203 Author: Julian Reschke <[email protected]> AuthorDate: Mon Jan 20 14:36:58 2025 +0100 OAK-11406: Remove usage of Guava io.ByteSource --- .../oak/plugins/tika/BinaryResource.java | 9 +- .../oak/plugins/tika/BlobStoreByteSource.java | 8 +- .../jackrabbit/oak/plugins/tika/TextExtractor.java | 4 +- .../oak/plugins/tika/TestDataSource.java} | 104 +++++++++------------ .../oak/plugins/tika/TextExtractorTest.java | 7 +- .../oak/plugins/tika/TextPopulatorTest.java | 19 +--- 6 files changed, 55 insertions(+), 96 deletions(-) diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BinaryResource.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BinaryResource.java index ba63795630..d1963f05e2 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BinaryResource.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BinaryResource.java @@ -16,23 +16,20 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.tika; -import org.apache.jackrabbit.guava.common.io.ByteSource; - import static java.util.Objects.requireNonNull; import org.jetbrains.annotations.Nullable; class BinaryResource { - private final ByteSource byteSource; + private final BlobStoreByteSource byteSource; private final String mimeType; private final String encoding; private final String path; private final String blobId; - public BinaryResource(ByteSource byteSource, + public BinaryResource(BlobStoreByteSource byteSource, @Nullable String mimeType, @Nullable String encoding, String path, @@ -44,7 +41,7 @@ class BinaryResource { this.blobId = requireNonNull(blobId, "BlobId must be specified"); } - public ByteSource getByteSource() { + public BlobStoreByteSource getByteSource() { return byteSource; } diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BlobStoreByteSource.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BlobStoreByteSource.java index 237c55e2cf..b1b2969957 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BlobStoreByteSource.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BlobStoreByteSource.java @@ -16,25 +16,23 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.tika; import java.io.IOException; import java.io.InputStream; -import org.apache.jackrabbit.guava.common.io.ByteSource; import org.apache.jackrabbit.oak.spi.blob.BlobStore; import org.jetbrains.annotations.Nullable; /** * Avoiding use of BlobByteSource to avoid concurrent access to NodeState */ -class BlobStoreByteSource extends ByteSource { +class BlobStoreByteSource { private final BlobStore blobStore; private final String blobId; private final Long size; - BlobStoreByteSource(BlobStore blobStore, String blobId,@Nullable Long size) { + BlobStoreByteSource(BlobStore blobStore, String blobId, @Nullable Long size) { this.blobStore = blobStore; this.blobId = blobId; this.size = size; @@ -44,12 +42,10 @@ class BlobStoreByteSource extends ByteSource { this(blobStore, blobId, null); } - @Override public InputStream openStream() throws IOException { return blobStore.getInputStream(blobId); } - @Override public long size() throws IOException { if (size != null) { return size; diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractor.java b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractor.java index 1374075278..5bb34371f8 100644 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractor.java +++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractor.java @@ -16,10 +16,8 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.tika; -import org.apache.jackrabbit.guava.common.io.ByteSource; import org.apache.jackrabbit.guava.common.io.CountingInputStream; import org.apache.jackrabbit.oak.commons.IOUtils; import org.apache.jackrabbit.oak.commons.io.LazyInputStream; @@ -243,7 +241,7 @@ class TextExtractor implements Closeable { //~--------------------------------------< Tika > - private String parseStringValue(ByteSource byteSource, Metadata metadata, String path) { + private String parseStringValue(BlobStoreByteSource byteSource, Metadata metadata, String path) { WriteOutContentHandler handler = new WriteOutContentHandler(maxExtractedLength); long start = System.currentTimeMillis(); long size = 0; diff --git a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BlobStoreByteSource.java b/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TestDataSource.java old mode 100644 new mode 100755 similarity index 55% copy from oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BlobStoreByteSource.java copy to oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TestDataSource.java index 237c55e2cf..c2cc88dcc0 --- a/oak-run/src/main/java/org/apache/jackrabbit/oak/plugins/tika/BlobStoreByteSource.java +++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TestDataSource.java @@ -1,59 +1,45 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.jackrabbit.oak.plugins.tika; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.jackrabbit.guava.common.io.ByteSource; -import org.apache.jackrabbit.oak.spi.blob.BlobStore; -import org.jetbrains.annotations.Nullable; - -/** - * Avoiding use of BlobByteSource to avoid concurrent access to NodeState - */ -class BlobStoreByteSource extends ByteSource { - private final BlobStore blobStore; - private final String blobId; - private final Long size; - - BlobStoreByteSource(BlobStore blobStore, String blobId,@Nullable Long size) { - this.blobStore = blobStore; - this.blobId = blobId; - this.size = size; - } - - BlobStoreByteSource(BlobStore blobStore, String blobId) { - this(blobStore, blobId, null); - } - - @Override - public InputStream openStream() throws IOException { - return blobStore.getInputStream(blobId); - } - - @Override - public long size() throws IOException { - if (size != null) { - return size; - } - return blobStore.getBlobLength(blobId); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.plugins.tika; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +/** + * Unit tests only + */ +class TestDataSource extends BlobStoreByteSource { + + private final byte[] bytes; + + public TestDataSource(String contents) { + super(null, ""); + this.bytes = contents.getBytes(StandardCharsets.UTF_8); + } + + public InputStream openStream() throws IOException { + return new ByteArrayInputStream(bytes); + } + + public long size() throws IOException { + return bytes.length; + } +} diff --git a/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractorTest.java b/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractorTest.java index 0dd640082b..d6c5ec75ad 100644 --- a/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractorTest.java +++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextExtractorTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.tika; import java.io.IOException; @@ -24,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.jackrabbit.guava.common.io.ByteSource; import org.apache.jackrabbit.oak.plugins.blob.datastore.TextWriter; import org.junit.Test; @@ -44,14 +42,15 @@ public class TextExtractorTest { ); extractor.extract(binaries); - extractor.close(); + assertEquals(2, writer.data.size()); assertEquals("foo", writer.data.get("b").trim()); } private static BinaryResource bin(String text, String mime, String id) { - return new BinaryResource(ByteSource.wrap(text.getBytes()), mime, null, id, id); + return new BinaryResource(new TestDataSource(text), + mime, null, id, id); } private static class MapTextWriter implements TextWriter { diff --git a/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextPopulatorTest.java b/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextPopulatorTest.java index 251f95944b..338b58e155 100644 --- a/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextPopulatorTest.java +++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/plugins/tika/TextPopulatorTest.java @@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.plugins.tika; import org.apache.jackrabbit.guava.common.collect.FluentIterable; -import org.apache.jackrabbit.guava.common.io.ByteSource; import org.apache.jackrabbit.oak.plugins.blob.datastore.TextWriter; import org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory; import org.apache.jackrabbit.oak.plugins.index.lucene.OakAnalyzer; @@ -35,11 +34,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -271,7 +267,7 @@ public class TextPopulatorTest { FakeBinaryResourceProvider(String ... paths) { for (String path : paths) { - binaries.add(new BinaryResource(new StringByteSource(""), null, null, path, getBlobId(path))); + binaries.add(new BinaryResource(new TestDataSource(""), null, null, path, getBlobId(path))); } } @@ -290,17 +286,4 @@ public class TextPopulatorTest { }; } } - - private static class StringByteSource extends ByteSource { - private final String data; - - StringByteSource(String data) { - this.data = data; - } - - @Override - public InputStream openStream() { - return new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); - } - } }
