jbonofre commented on code in PR #11609: URL: https://github.com/apache/iceberg/pull/11609#discussion_r1852042170
########## core/src/main/java/org/apache/iceberg/TableMetadataParser.java: ########## @@ -277,11 +287,21 @@ public static TableMetadata read(FileIO io, String path) { public static TableMetadata read(FileIO io, InputFile file) { Codec codec = Codec.fromFileName(file.location()); - try (InputStream is = file.newStream(); - InputStream gis = codec == Codec.GZIP ? new GZIPInputStream(is) : is) { + InputStream is = file.newStream(); + // if codec is GZIP, is will be closed by GZIPInputStream + // otherwise, os will be closed by try-with-resources + try (InputStream gis = codec == Codec.GZIP ? new GZIPInputStream(is) : is) { Review Comment: Why not gathering both statements in one try close ? It would be easier. Something like: ``` try (InputStream is = (codec == Codec.GZIP) ? new GzipInputStream(file.newStream()) : file.newStream()) { ``` ########## core/src/main/java/org/apache/iceberg/TableMetadataParser.java: ########## @@ -122,15 +122,25 @@ public static void write(TableMetadata metadata, OutputFile outputFile) { public static void internalWrite( TableMetadata metadata, OutputFile outputFile, boolean overwrite) { boolean isGzip = Codec.fromFileName(outputFile.location()) == Codec.GZIP; - try (OutputStream os = overwrite ? outputFile.createOrOverwrite() : outputFile.create(); - OutputStream gos = isGzip ? new GZIPOutputStream(os) : os; + OutputStream os = overwrite ? outputFile.createOrOverwrite() : outputFile.create(); + // if isGzip is true, os will be closed by GZIPOutputStream, + // otherwise, os will be closed by try-with-resources + try (OutputStream gos = isGzip ? new GZIPOutputStream(os) : os; Review Comment: Why not gathering all in the try-on-resource ? Something like: ``` try (OutputStream gos = isGzip ? new GZIPOutputStream((overwrite ? output.createOrOverwrite() : outputFile.create())) : (overwrite ? output.createOrOverwrite() : outputFile.create())) { ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org