From c192dd60b4dbf13bbee12e3dbba5cbc39edddd29 Mon Sep 17 00:00:00 2001 From: Danny Chen Date: Wed, 31 May 2017 17:41:27 -0700 Subject: [PATCH] Change from deprecated closeQuietly to try with resources --- .../table/timeline/HoodieActiveTimeline.java | 9 +----- .../timeline/HoodieArchivedTimeline.java | 28 ++++++++----------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieActiveTimeline.java b/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieActiveTimeline.java index 2d29ab3ca..b662fe9ab 100644 --- a/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieActiveTimeline.java +++ b/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieActiveTimeline.java @@ -18,7 +18,6 @@ package com.uber.hoodie.common.table.timeline; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; -import com.google.common.io.Closeables; import com.uber.hoodie.common.table.HoodieTableMetaClient; import com.uber.hoodie.common.table.HoodieTimeline; import com.uber.hoodie.common.util.FSUtils; @@ -303,16 +302,10 @@ public class HoodieActiveTimeline extends HoodieDefaultTimeline { } protected Optional readDataFromPath(Path detailPath) { - FSDataInputStream is = null; - try { - is = fs.open(detailPath); + try (FSDataInputStream is = fs.open(detailPath)) { return Optional.of(IOUtils.toByteArray(is)); } catch (IOException e) { throw new HoodieIOException("Could not read commit details from " + detailPath, e); - } finally { - if (is != null) { - Closeables.closeQuietly(is); - } } } diff --git a/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieArchivedTimeline.java b/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieArchivedTimeline.java index e47954b2a..2835fe0e1 100644 --- a/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieArchivedTimeline.java +++ b/hoodie-common/src/main/java/com/uber/hoodie/common/table/timeline/HoodieArchivedTimeline.java @@ -16,7 +16,6 @@ package com.uber.hoodie.common.table.timeline; -import com.google.common.io.Closeables; import com.uber.hoodie.common.table.HoodieTimeline; import com.uber.hoodie.common.util.FSUtils; import com.uber.hoodie.exception.HoodieIOException; @@ -56,23 +55,18 @@ public class HoodieArchivedTimeline extends HoodieDefaultTimeline { public HoodieArchivedTimeline(FileSystem fs, String metaPath) { // Read back the commits to make sure Path archiveLogPath = getArchiveLogPath(metaPath); - try { - SequenceFile.Reader reader = - new SequenceFile.Reader(fs.getConf(), SequenceFile.Reader.file(archiveLogPath)); - try { - Text key = new Text(); - Text val = new Text(); - while (reader.next(key, val)) { - // TODO - limit the number of commits loaded in memory. this could get very large. - // This is okay because only tooling will load the archived commit timeline today - readCommits.put(key.toString(), Arrays.copyOf(val.getBytes(), val.getLength())); - } - this.instants = readCommits.keySet().stream().map( - s -> new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION, s)).collect( - Collectors.toList()); - } finally { - Closeables.closeQuietly(reader); + try (SequenceFile.Reader reader = + new SequenceFile.Reader(fs.getConf(), SequenceFile.Reader.file(archiveLogPath))) { + Text key = new Text(); + Text val = new Text(); + while (reader.next(key, val)) { + // TODO - limit the number of commits loaded in memory. this could get very large. + // This is okay because only tooling will load the archived commit timeline today + readCommits.put(key.toString(), Arrays.copyOf(val.getBytes(), val.getLength())); } + this.instants = readCommits.keySet().stream().map( + s -> new HoodieInstant(false, HoodieTimeline.COMMIT_ACTION, s)).collect( + Collectors.toList()); } catch (IOException e) { throw new HoodieIOException( "Could not load archived commit timeline from path " + archiveLogPath, e);