diff --git a/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/GZipFiles.java b/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/GZipFiles.java index aa383565924da..0a31e317fea51 100644 --- a/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/GZipFiles.java +++ b/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/GZipFiles.java @@ -43,8 +43,7 @@ public class GZipFiles { /** * Returns true if the given file is a gzip file. */ - @SuppressWarnings("deprecation") - public static boolean isGzip(File f) { + public static boolean isGzip(File f) { InputStream input = null; try { diff --git a/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/ZipFiles.java b/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/ZipFiles.java index 09cd0c23daa08..367b04edd487e 100644 --- a/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/ZipFiles.java +++ b/pulsar-io/file/src/main/java/org/apache/pulsar/io/file/utils/ZipFiles.java @@ -25,7 +25,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.UncheckedIOException; import java.nio.file.Files; @@ -33,8 +32,6 @@ import java.util.stream.Stream; import java.util.zip.ZipInputStream; -import org.apache.commons.io.IOUtils; - /** * Helper class that provides helper methods for working with * zip-formatted files. @@ -44,19 +41,12 @@ public class ZipFiles { /** * Returns true if the given file is a gzip file. */ - @SuppressWarnings("deprecation") - public static boolean isZip(File f) { - - InputStream input = null; - try { - DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(f))); + public static boolean isZip(File f) { + try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(f)))){ int test = in.readInt(); - in.close(); return test == 0x504b0304; } catch (final Exception e) { return false; - } finally { - IOUtils.closeQuietly(input); } }