Skip to content

Commit 321a13f

Browse files
authored
OAK-11380: Remove usage of Guava Files.asByteSource - oak-upgrade (#1982)
1 parent ddcca17 commit 321a13f

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStore.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.BufferedWriter;
2222
import java.io.File;
23+
import java.io.FileInputStream;
2324
import java.io.FileNotFoundException;
2425
import java.io.FileOutputStream;
2526
import java.io.IOException;
@@ -35,7 +36,6 @@
3536

3637
import javax.jcr.RepositoryException;
3738

38-
import org.apache.jackrabbit.guava.common.io.Files;
3939
import org.apache.commons.io.FilenameUtils;
4040
import org.apache.commons.io.IOUtils;
4141
import org.apache.commons.io.LineIterator;
@@ -45,6 +45,7 @@
4545
import org.apache.jackrabbit.core.data.DataRecord;
4646
import org.apache.jackrabbit.core.data.DataStore;
4747
import org.apache.jackrabbit.core.data.DataStoreException;
48+
import org.apache.jackrabbit.guava.common.io.Files;
4849
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
4950
import org.apache.jackrabbit.oak.commons.conditions.Validate;
5051
import org.slf4j.Logger;
@@ -287,17 +288,13 @@ private void initializeDelegate(String homeDir) throws RepositoryException {
287288
File configFile = new File(delegateConfigFilePath);
288289
checkArgument(configFile.exists(), "Delegate DataStore config file %s does not exist", configFile.getAbsolutePath());
289290

290-
InputStream is = null;
291-
try {
291+
try (InputStream is = new FileInputStream(configFile)) {
292292
Properties props = new Properties();
293-
is = Files.asByteSource(configFile).openStream();
294293
props.load(is);
295294
PropertiesUtil.populate(delegate, propsToMap(props), false);
296295
log.info("Configured the delegating DataStore via {}", configFile.getAbsolutePath());
297296
} catch (IOException e) {
298297
throw new RepositoryException("Error reading from config file " + configFile.getAbsolutePath(), e);
299-
} finally {
300-
IOUtils.closeQuietly(is);
301298
}
302299
}
303300

oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/blob/LengthCachingDataStoreTest.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package org.apache.jackrabbit.oak.upgrade.blob;
2120

21+
import static org.junit.Assert.assertArrayEquals;
2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertNotNull;
24-
import static org.junit.Assert.assertTrue;
2524

2625
import java.io.ByteArrayInputStream;
2726
import java.io.File;
@@ -32,7 +31,6 @@
3231
import java.util.Properties;
3332
import java.util.Random;
3433

35-
import org.apache.jackrabbit.guava.common.io.ByteSource;
3634
import org.apache.jackrabbit.guava.common.io.Files;
3735
import org.apache.jackrabbit.core.data.DataIdentifier;
3836
import org.apache.jackrabbit.core.data.DataRecord;
@@ -105,7 +103,7 @@ public void delegateRecordTest() throws Exception{
105103
assertEquals(dr, dr2);
106104

107105
assertEquals(dr.getLength(), dr2.getLength());
108-
assertTrue(supplier(dr).contentEquals(supplier(dr2)));
106+
assertArrayEquals(streamAsByteArray(dr), streamAsByteArray(dr2));
109107
}
110108

111109
@Test
@@ -180,16 +178,9 @@ private byte[] bytes(int size) {
180178
return data;
181179
}
182180

183-
private static ByteSource supplier(final DataRecord dr) {
184-
return new ByteSource() {
185-
@Override
186-
public InputStream openStream() throws IOException {
187-
try {
188-
return dr.getStream();
189-
} catch (DataStoreException e) {
190-
throw new RuntimeException(e);
191-
}
192-
}
193-
};
181+
private static byte[] streamAsByteArray(final DataRecord dr) throws IOException, DataStoreException {
182+
try (InputStream is = dr.getStream()) {
183+
return is.readAllBytes();
184+
}
194185
}
195186
}

0 commit comments

Comments
 (0)