Skip to content

Commit

Permalink
Update TableMetadataParser.java
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-grepr authored Sep 27, 2024
1 parent 5739b3e commit 4e94944
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions core/src/main/java/org/apache/iceberg/TableMetadataParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,21 @@ public static void internalWrite(
boolean isGzip = Codec.fromFileName(outputFile.location()) == Codec.GZIP;
try (OutputStream os = overwrite ? outputFile.createOrOverwrite() : outputFile.create()) {
if (isGzip) {
os = new GZIPOutputStream(os);
try (OutputStream gos = new GZIPOutputStream(os);
OutputStream osw = new OutputStreamWriter(gos, StandardCharsets.UTF_8)) {
JsonGenerator generator = JsonUtil.factory().createGenerator(os);
generator.useDefaultPrettyPrinter();
toJson(metadata, generator);
generator.flush();
}
} else {
try (OutputStream osw = new OutputStreamWriter(os, StandardCharsets.UTF_8)) {
JsonGenerator generator = JsonUtil.factory().createGenerator(os);
generator.useDefaultPrettyPrinter();
toJson(metadata, generator);
generator.flush();
}
}
os = new OutputStreamWriter(os, StandardCharsets.UTF_8);
JsonGenerator generator = JsonUtil.factory().createGenerator(os);
generator.useDefaultPrettyPrinter();
toJson(metadata, generator);
generator.flush();
} catch (IOException e) {
throw new RuntimeIOException(e, "Failed to write json to file: %s", outputFile);
}
Expand Down Expand Up @@ -279,7 +287,9 @@ public static TableMetadata read(FileIO io, InputFile file) {
Codec codec = Codec.fromFileName(file.location());
try (InputStream is = file.newStream()) {
if (codec == Codec.GZIP) {
is = new GZIPInputStream(is);
try (InputStream gis = new GZIPInputStream(is)) {
return fromJson(file, JsonUtil.mapper().readValue(gis, JsonNode.class));
}
}
return fromJson(file, JsonUtil.mapper().readValue(is, JsonNode.class));
} catch (IOException e) {
Expand Down

0 comments on commit 4e94944

Please sign in to comment.