This is an automated email from the ASF dual-hosted git repository. tilman pushed a commit to branch branch_2x in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/branch_2x by this push: new 7c558a4ac TIKA-4290: replace deprecated 7c558a4ac is described below commit 7c558a4ac3a891a523e0dff6dc0f76cd9e1a6463 Author: Tilman Hausherr <til...@apache.org> AuthorDate: Sat Aug 10 14:27:24 2024 +0200 TIKA-4290: replace deprecated --- .../src/main/java/org/apache/tika/gui/TikaGUI.java | 16 +++-- .../test/java/org/apache/tika/bundle/BundleIT.java | 2 +- .../org/apache/tika/eval/app/reports/Report.java | 2 +- .../java/org/apache/tika/example/MyFirstTika.java | 11 ++-- .../org/apache/tika/example/TIAParsingExample.java | 4 +- .../tika/parser/sqlite3/SQLite3ParserTest.java | 3 +- .../tika/parser/pot/PooledTimeSeriesParser.java | 5 +- .../org/apache/tika/parser/mbox/MboxParser.java | 4 +- .../apache/tika/parser/ocr/ImagePreprocessor.java | 2 +- .../org/apache/tika/parser/pkg/ZipParserTest.java | 3 +- .../tika/pipes/emitter/azblob/AZBlobEmitter.java | 15 ++--- .../tika/pipes/fetcher/azblob/AZBlobFetcher.java | 6 +- .../org/apache/tika/server/core/CXFTestBase.java | 71 ++++++++++++---------- 13 files changed, 75 insertions(+), 69 deletions(-) diff --git a/tika-app/src/main/java/org/apache/tika/gui/TikaGUI.java b/tika-app/src/main/java/org/apache/tika/gui/TikaGUI.java index c8c69e82f..4ebbcc914 100644 --- a/tika-app/src/main/java/org/apache/tika/gui/TikaGUI.java +++ b/tika-app/src/main/java/org/apache/tika/gui/TikaGUI.java @@ -241,6 +241,7 @@ public class TikaGUI extends JFrame implements ActionListener, HyperlinkListener menu.add(item); } + @Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if ("openfile".equals(command)) { @@ -283,7 +284,7 @@ public class TikaGUI extends JFrame implements ActionListener, HyperlinkListener public void openFile(File file) { try { Metadata metadata = new Metadata(); - try (TikaInputStream stream = TikaInputStream.get(file, metadata)) { + try (TikaInputStream stream = TikaInputStream.get(file.toPath(), metadata)) { handleStream(stream, metadata); } } catch (Throwable t) { @@ -441,6 +442,7 @@ public class TikaGUI extends JFrame implements ActionListener, HyperlinkListener } } + @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == EventType.ACTIVATED) { try { @@ -619,17 +621,19 @@ public class TikaGUI extends JFrame implements ActionListener, HyperlinkListener return tmp; } + @Override public Set<MediaType> getSupportedTypes(ParseContext context) { return downstreamParser.getSupportedTypes(context); } - public void parse(InputStream stream, ContentHandler handler, Metadata metadata, - ParseContext context) throws IOException, SAXException, TikaException { + @Override + public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) + throws IOException, SAXException, TikaException { String name = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY); if (name != null && wanted.containsKey(name)) { - FileOutputStream out = new FileOutputStream(wanted.get(name)); - IOUtils.copy(stream, out); - out.close(); + try (FileOutputStream out = new FileOutputStream(wanted.get(name))) { + IOUtils.copy(stream, out); + } } else { if (downstreamParser != null) { downstreamParser.parse(stream, handler, metadata, context); diff --git a/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java b/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java index 340b1ba17..3e50fce5f 100644 --- a/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java +++ b/tika-bundles/tika-bundle-standard/src/test/java/org/apache/tika/bundle/BundleIT.java @@ -340,7 +340,7 @@ public class BundleIT { } System.out.println("about to parse " + f); Metadata metadata = new Metadata(); - try (InputStream is = TikaInputStream.get(f)) { + try (InputStream is = TikaInputStream.get(f.toPath())) { parser.parse(is, handler, metadata, context); } catch (EncryptedDocumentException e) { //swallow diff --git a/tika-eval/tika-eval-app/src/main/java/org/apache/tika/eval/app/reports/Report.java b/tika-eval/tika-eval-app/src/main/java/org/apache/tika/eval/app/reports/Report.java index 6982aaad6..75d8cd587 100644 --- a/tika-eval/tika-eval-app/src/main/java/org/apache/tika/eval/app/reports/Report.java +++ b/tika-eval/tika-eval-app/src/main/java/org/apache/tika/eval/app/reports/Report.java @@ -82,7 +82,7 @@ public class Report { try (OutputStream os = Files.newOutputStream(out)) { wb.write(os); } finally { - wb.dispose(); + wb.close(); } } } diff --git a/tika-example/src/main/java/org/apache/tika/example/MyFirstTika.java b/tika-example/src/main/java/org/apache/tika/example/MyFirstTika.java index 6a7e94d34..1e563f99e 100755 --- a/tika-example/src/main/java/org/apache/tika/example/MyFirstTika.java +++ b/tika-example/src/main/java/org/apache/tika/example/MyFirstTika.java @@ -21,6 +21,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import java.io.File; import java.io.InputStream; +import java.nio.file.Paths; import org.apache.commons.io.FileUtils; import org.xml.sax.ContentHandler; @@ -75,7 +76,7 @@ public class MyFirstTika { AutoDetectParser parser = new AutoDetectParser(tikaConfig); ContentHandler handler = new BodyContentHandler(); - TikaInputStream stream = TikaInputStream.get(new File(filename), metadata); + TikaInputStream stream = TikaInputStream.get(Paths.get(filename), metadata); parser.parse(stream, handler, metadata, new ParseContext()); return handler.toString(); } @@ -91,12 +92,10 @@ public class MyFirstTika { "The MIME type (based on filename) is: [" + mimeRegistry.detect(null, metadata) + "]"); - InputStream stream = TikaInputStream.get(new File(filename)); - System.out.println( - "The MIME type (based on MAGIC) is: [" + mimeRegistry.detect(stream, metadata) + - "]"); + InputStream stream = TikaInputStream.get(Paths.get(filename)); + System.out.println("The MIME type (based on MAGIC) is: [" + mimeRegistry.detect(stream, metadata) + "]"); - stream = TikaInputStream.get(new File(filename)); + stream = TikaInputStream.get(Paths.get(filename)); Detector detector = tikaConfig.getDetector(); System.out.println("The MIME type (based on the Detector interface) is: [" + detector.detect(stream, metadata) + "]"); diff --git a/tika-example/src/main/java/org/apache/tika/example/TIAParsingExample.java b/tika-example/src/main/java/org/apache/tika/example/TIAParsingExample.java index 5a9ee5dc5..107aeb735 100755 --- a/tika-example/src/main/java/org/apache/tika/example/TIAParsingExample.java +++ b/tika-example/src/main/java/org/apache/tika/example/TIAParsingExample.java @@ -100,13 +100,13 @@ public class TIAParsingExample { ContentHandler handler = new DefaultHandler(); Metadata metadata = new Metadata(); ParseContext context = new ParseContext(); - try (InputStream stream = TikaInputStream.get(new File(filename))) { + try (InputStream stream = TikaInputStream.get(Paths.get(filename))) { parser.parse(stream, handler, metadata, context); } } public static File tikaInputStreamGetFile(String filename) throws Exception { - try (InputStream stream = TikaInputStream.get(new File(filename))) { + try (InputStream stream = TikaInputStream.get(Paths.get(filename))) { TikaInputStream tikaInputStream = TikaInputStream.get(stream); return tikaInputStream.getFile(); } diff --git a/tika-parsers/tika-parsers-extended/tika-parsers-extended-integration-tests/src/test/java/org/apache/tika/parser/sqlite3/SQLite3ParserTest.java b/tika-parsers/tika-parsers-extended/tika-parsers-extended-integration-tests/src/test/java/org/apache/tika/parser/sqlite3/SQLite3ParserTest.java index c9be6db27..65e752bc1 100644 --- a/tika-parsers/tika-parsers-extended/tika-parsers-extended-integration-tests/src/test/java/org/apache/tika/parser/sqlite3/SQLite3ParserTest.java +++ b/tika-parsers/tika-parsers-extended/tika-parsers-extended-integration-tests/src/test/java/org/apache/tika/parser/sqlite3/SQLite3ParserTest.java @@ -68,7 +68,7 @@ public class SQLite3ParserTest extends TikaTest { } } try (TikaInputStream outer = TikaInputStream.get(getResourceAsStream(TEST_FILE1))) { - try (TikaInputStream inner = TikaInputStream.get(outer.getFile())) { + try (TikaInputStream inner = TikaInputStream.get(outer.getPath())) { _testBasic(inner); } } @@ -143,7 +143,6 @@ public class SQLite3ParserTest extends TikaTest { wrapper.parse(is, handler, metadata, new ParseContext()); } List<Metadata> metadataList = handler.getMetadataList(); - int i = 0; assertEquals(5, metadataList.size()); //make sure the \t are inserted in a body handler diff --git a/tika-parsers/tika-parsers-ml/tika-parser-advancedmedia-module/src/main/java/org/apache/tika/parser/pot/PooledTimeSeriesParser.java b/tika-parsers/tika-parsers-ml/tika-parser-advancedmedia-module/src/main/java/org/apache/tika/parser/pot/PooledTimeSeriesParser.java index b4de9dc1d..fdf859b3e 100644 --- a/tika-parsers/tika-parsers-ml/tika-parser-advancedmedia-module/src/main/java/org/apache/tika/parser/pot/PooledTimeSeriesParser.java +++ b/tika-parsers/tika-parsers-ml/tika-parser-advancedmedia-module/src/main/java/org/apache/tika/parser/pot/PooledTimeSeriesParser.java @@ -25,6 +25,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -161,9 +162,9 @@ public class PooledTimeSeriesParser extends AbstractParser { cmdLine.addArgument("-f"); cmdLine.addArgument(input.getAbsolutePath()); LOG.trace("Executing: {}", cmdLine); - DefaultExecutor exec = new DefaultExecutor(); + DefaultExecutor exec = DefaultExecutor.builder().get(); exec.setExitValue(0); - ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); + ExecuteWatchdog watchdog = ExecuteWatchdog.builder().setTimeout(Duration.ofMillis(60000)).get(); exec.setWatchdog(watchdog); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); exec.setStreamHandler(streamHandler); diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-mail-module/src/main/java/org/apache/tika/parser/mbox/MboxParser.java b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-mail-module/src/main/java/org/apache/tika/parser/mbox/MboxParser.java index d01ae191a..0a35558bd 100644 --- a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-mail-module/src/main/java/org/apache/tika/parser/mbox/MboxParser.java +++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-mail-module/src/main/java/org/apache/tika/parser/mbox/MboxParser.java @@ -73,10 +73,12 @@ public class MboxParser extends AbstractParser { private boolean tracking = false; + @Override public Set<MediaType> getSupportedTypes(ParseContext context) { return SUPPORTED_TYPES; } + @Override public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, TikaException, SAXException { @@ -108,7 +110,7 @@ public class MboxParser extends AbstractParser { if (curLine == null) { break; } - UnsynchronizedByteArrayOutputStream message = new UnsynchronizedByteArrayOutputStream(100000); + UnsynchronizedByteArrayOutputStream message = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(100000).get(); do { if (curLine.startsWith(" ") || curLine.startsWith("\t")) { String latestLine = multiline.poll(); diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-ocr-module/src/main/java/org/apache/tika/parser/ocr/ImagePreprocessor.java b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-ocr-module/src/main/java/org/apache/tika/parser/ocr/ImagePreprocessor.java index 0bf3fbc2e..0473f3bed 100644 --- a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-ocr-module/src/main/java/org/apache/tika/parser/ocr/ImagePreprocessor.java +++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-ocr-module/src/main/java/org/apache/tika/parser/ocr/ImagePreprocessor.java @@ -95,7 +95,7 @@ class ImagePreprocessor implements Serializable { } final String[] args = stream.flatMap(Collection::stream).toArray(String[]::new); commandLine.addArguments(args, true); - DefaultExecutor executor = new DefaultExecutor(); + DefaultExecutor executor = DefaultExecutor.builder().get(); try { executor.execute(commandLine); } catch (SecurityException e) { diff --git a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-pkg-module/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-pkg-module/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java index 9bc183b2c..f29d1dfb7 100644 --- a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-pkg-module/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java +++ b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-pkg-module/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java @@ -100,8 +100,7 @@ public class ZipParserTest extends AbstractPkgTest { @Test // TIKA-936 public void testCustomEncoding() throws Exception { - ArchiveStreamFactory factory = new ArchiveStreamFactory(); - factory.setEntryEncoding("SJIS"); + ArchiveStreamFactory factory = new ArchiveStreamFactory("SJIS"); trackingContext.set(ArchiveStreamFactory.class, factory); try (InputStream stream = TikaInputStream.get(Base64.decodeBase64( diff --git a/tika-pipes/tika-emitters/tika-emitter-az-blob/src/main/java/org/apache/tika/pipes/emitter/azblob/AZBlobEmitter.java b/tika-pipes/tika-emitters/tika-emitter-az-blob/src/main/java/org/apache/tika/pipes/emitter/azblob/AZBlobEmitter.java index 180bc204a..3d2af52ac 100644 --- a/tika-pipes/tika-emitters/tika-emitter-az-blob/src/main/java/org/apache/tika/pipes/emitter/azblob/AZBlobEmitter.java +++ b/tika-pipes/tika-emitters/tika-emitter-az-blob/src/main/java/org/apache/tika/pipes/emitter/azblob/AZBlobEmitter.java @@ -43,7 +43,6 @@ import org.apache.tika.config.Initializable; import org.apache.tika.config.InitializableProblemHandler; import org.apache.tika.config.Param; import org.apache.tika.exception.TikaConfigException; -import org.apache.tika.exception.TikaException; import org.apache.tika.io.TikaInputStream; import org.apache.tika.metadata.Metadata; import org.apache.tika.metadata.TikaCoreProperties; @@ -75,14 +74,15 @@ public class AZBlobEmitter extends AbstractEmitter implements Initializable, Str /** * Requires the src-bucket/path/to/my/file.txt in the {@link TikaCoreProperties#SOURCE_PATH}. * + * @param emitKey * @param metadataList * @throws IOException - * @throws TikaException + * @throws TikaEmitterException */ @Override public void emit(String emitKey, List<Metadata> metadataList) throws IOException, TikaEmitterException { - if (metadataList == null || metadataList.size() == 0) { + if (metadataList == null || metadataList.isEmpty()) { throw new TikaEmitterException("metadata list must not be null or of size 0"); } //TODO: estimate size of metadata list. Above a certain size, @@ -106,7 +106,8 @@ public class AZBlobEmitter extends AbstractEmitter implements Initializable, Str * otherwise, the client will copy the stream to a byte array and then * upload. * @param userMetadata this will be written to the az blob's properties.metadata - * @throws TikaEmitterException or IOexception if there is a Runtime client exception + * @throws IOException if there is a Runtime client exception + * @throws TikaEmitterException if there is a Runtime client exception */ @Override public void emit(String path, InputStream is, Metadata userMetadata) @@ -150,12 +151,12 @@ public class AZBlobEmitter extends AbstractEmitter implements Initializable, Str blobClient.uploadFromFile(file.toAbsolutePath().toString(), overwriteExisting); } - private void write(String path, Metadata userMetadata, byte[] bytes) { + private void write(String path, Metadata userMetadata, byte[] bytes) throws IOException { String actualPath = getActualPath(path); LOGGER.debug("about to emit to target container: ({}) path:({})", container, actualPath); BlobClient blobClient = blobContainerClient.getBlobClient(actualPath); updateMetadata(blobClient, userMetadata); - blobClient.upload(new UnsynchronizedByteArrayInputStream(bytes), bytes.length, overwriteExisting); + blobClient.upload(UnsynchronizedByteArrayInputStream.builder().setByteArray(bytes).get(), bytes.length, overwriteExisting); } private void updateMetadata(BlobClient blobClient, Metadata userMetadata) { @@ -174,7 +175,7 @@ public class AZBlobEmitter extends AbstractEmitter implements Initializable, Str } private String getActualPath(final String path) { - String ret = null; + String ret; if (!StringUtils.isBlank(prefix)) { ret = prefix + "/" + path; } else { diff --git a/tika-pipes/tika-fetchers/tika-fetcher-az-blob/src/main/java/org/apache/tika/pipes/fetcher/azblob/AZBlobFetcher.java b/tika-pipes/tika-fetchers/tika-fetcher-az-blob/src/main/java/org/apache/tika/pipes/fetcher/azblob/AZBlobFetcher.java index dee903040..f6d508dc8 100644 --- a/tika-pipes/tika-fetchers/tika-fetcher-az-blob/src/main/java/org/apache/tika/pipes/fetcher/azblob/AZBlobFetcher.java +++ b/tika-pipes/tika-fetchers/tika-fetcher-az-blob/src/main/java/org/apache/tika/pipes/fetcher/azblob/AZBlobFetcher.java @@ -20,8 +20,6 @@ import static org.apache.tika.config.TikaConfig.mustNotBeEmpty; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; @@ -91,9 +89,7 @@ public class AZBlobFetcher extends AbstractFetcher implements Initializable { long start = System.currentTimeMillis(); TemporaryResources tmpResources = new TemporaryResources(); Path tmp = tmpResources.createTempFile(); - try (OutputStream os = Files.newOutputStream(tmp)) { - blobClient.download(os); - } + blobClient.downloadToFile(tmp.toRealPath().toString()); TikaInputStream tis = TikaInputStream.get(tmp, metadata, tmpResources); long elapsed = System.currentTimeMillis() - start; LOGGER.debug("took {} ms to copy to local tmp file", elapsed); diff --git a/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/CXFTestBase.java b/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/CXFTestBase.java index 387b085a0..94476bc21 100644 --- a/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/CXFTestBase.java +++ b/tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/CXFTestBase.java @@ -168,15 +168,16 @@ public abstract class CXFTestBase { Path tempFile = null; try { tempFile = writeTemporaryArchiveFile(inputStream, "zip"); - ZipFile zip = new ZipFile(tempFile.toFile()); - Enumeration<ZipArchiveEntry> entries = zip.getEntries(); - while (entries.hasMoreElements()) { - ZipArchiveEntry entry = entries.nextElement(); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOUtils.copy(zip.getInputStream(entry), bos); - data.put(entry.getName(), DigestUtils.md5Hex(bos.toByteArray())); + try (ZipFile zip = ZipFile.builder().setPath(tempFile).get()) + { + Enumeration<ZipArchiveEntry> entries = zip.getEntries(); + while (entries.hasMoreElements()) { + ZipArchiveEntry entry = entries.nextElement(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IOUtils.copy(zip.getInputStream(entry), bos); + data.put(entry.getName(), DigestUtils.md5Hex(bos.toByteArray())); + } } - zip.close(); } finally { if (tempFile != null ) { Files.delete(tempFile); @@ -190,15 +191,16 @@ public abstract class CXFTestBase { Path tempFile = null; try { tempFile = writeTemporaryArchiveFile(inputStream, "zip"); - ZipFile zip = new ZipFile(tempFile.toFile()); - Enumeration<ZipArchiveEntry> entries = zip.getEntries(); - while (entries.hasMoreElements()) { - ZipArchiveEntry entry = entries.nextElement(); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOUtils.copy(zip.getInputStream(entry), bos); - data.put(entry.getName(), bos.toByteArray()); + try (ZipFile zip = ZipFile.builder().setPath(tempFile).get()) + { + Enumeration<ZipArchiveEntry> entries = zip.getEntries(); + while (entries.hasMoreElements()) { + ZipArchiveEntry entry = entries.nextElement(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IOUtils.copy(zip.getInputStream(entry), bos); + data.put(entry.getName(), bos.toByteArray()); + } } - zip.close(); } finally { if (tempFile != null ) { Files.delete(tempFile); @@ -209,29 +211,32 @@ public abstract class CXFTestBase { protected String readArchiveText(InputStream inputStream) throws IOException { Path tempFile = writeTemporaryArchiveFile(inputStream, "zip"); - ZipFile zip = new ZipFile(tempFile.toFile()); - zip.getEntry(UnpackerResource.TEXT_FILENAME); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.TEXT_FILENAME)), bos); - - zip.close(); + ByteArrayOutputStream bos; + try (ZipFile zip = ZipFile.builder().setPath(tempFile).get()) + { + zip.getEntry(UnpackerResource.TEXT_FILENAME); + bos = new ByteArrayOutputStream(); + IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.TEXT_FILENAME)), bos); + } Files.delete(tempFile); return bos.toString(UTF_8.name()); } protected String readArchiveMetadataAndText(InputStream inputStream) throws IOException { Path tempFile = writeTemporaryArchiveFile(inputStream, "zip"); - ZipFile zip = new ZipFile(tempFile.toFile()); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - zip.getEntry(UnpackerResource.META_FILENAME); - IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.META_FILENAME)), bos); - String metadata = new String(bos.toByteArray(), UTF_8); - - bos = new ByteArrayOutputStream(); - zip.getEntry(UnpackerResource.TEXT_FILENAME); - IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.TEXT_FILENAME)), bos); - String txt = new String(bos.toByteArray(), UTF_8); - zip.close(); + String metadata; + String txt; + try (ZipFile zip = ZipFile.builder().setPath(tempFile).get()) + { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + zip.getEntry(UnpackerResource.META_FILENAME); + IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.META_FILENAME)), bos); + metadata = new String(bos.toByteArray(), UTF_8); + bos = new ByteArrayOutputStream(); + zip.getEntry(UnpackerResource.TEXT_FILENAME); + IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.TEXT_FILENAME)), bos); + txt = new String(bos.toByteArray(), UTF_8); + } Files.delete(tempFile); return metadata + "\n\n" + txt; }