STORM-1670 Removed DirectoryStream changes Signed-off-by: P. Taylor Goetz <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/ff33253f Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/ff33253f Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/ff33253f Branch: refs/heads/1.x-branch Commit: ff33253f1e1ab720b9e8dbd11ce7406ab2e61c2a Parents: 0bf0559 Author: Satish Duggana <[email protected]> Authored: Sat Apr 2 00:30:08 2016 +0530 Committer: P. Taylor Goetz <[email protected]> Committed: Mon Apr 4 16:53:57 2016 -0400 ---------------------------------------------------------------------- .../org/apache/storm/utils/VersionedStore.java | 53 ++++++++------------ 1 file changed, 21 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/ff33253f/storm-core/src/jvm/org/apache/storm/utils/VersionedStore.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/utils/VersionedStore.java b/storm-core/src/jvm/org/apache/storm/utils/VersionedStore.java index 49c736f..b9971df 100644 --- a/storm-core/src/jvm/org/apache/storm/utils/VersionedStore.java +++ b/storm-core/src/jvm/org/apache/storm/utils/VersionedStore.java @@ -18,13 +18,9 @@ package org.apache.storm.utils; import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.io.File; @@ -125,12 +121,10 @@ public class VersionedStore { } HashSet<Long> keepers = new HashSet<Long>(versions); - try(DirectoryStream<Path> directoryStream = Files.newDirectoryStream(new File(_root).toPath())) { - for (Path path : directoryStream) { - Long v = parseVersion(path.toAbsolutePath().toString()); - if (v != null && !keepers.contains(v)) { - deleteVersion(v); - } + for(String p: listDir(_root)) { + Long v = parseVersion(p); + if(v!=null && !keepers.contains(v)) { + deleteVersion(v); } } } @@ -139,18 +133,16 @@ public class VersionedStore { * Sorted from most recent to oldest */ public List<Long> getAllVersions() throws IOException { - List<Long> versions = new ArrayList<Long>(); - try(DirectoryStream<Path> pathDirectoryStream = listDirWithFinishedFiles(_root)) { - for (Path path : pathDirectoryStream) { - String absolutePath = path.toAbsolutePath().toString(); - if (absolutePath.endsWith(FINISHED_VERSION_SUFFIX)) { - versions.add(validateAndGetVersion(absolutePath)); - } + List<Long> ret = new ArrayList<Long>(); + for(String s: listDir(_root)) { + + if(s.endsWith(FINISHED_VERSION_SUFFIX) && new File(s.substring(0, s.length() - FINISHED_VERSION_SUFFIX.length())).exists()) { + ret.add(validateAndGetVersion(s)); } } - Collections.sort(versions); - Collections.reverse(versions); - return versions; + Collections.sort(ret); + Collections.reverse(ret); + return ret; } private String tokenPath(long version) { @@ -182,18 +174,15 @@ public class VersionedStore { private void mkdirs(String path) throws IOException { new File(path).mkdirs(); } - - /** - * Return files which have both original and finished versions. - */ - private DirectoryStream<Path> listDirWithFinishedFiles(String dir) throws IOException { - return Files.newDirectoryStream(new File(dir).toPath(), new DirectoryStream.Filter<Path>() { - @Override - public boolean accept(Path path) throws IOException { - final String filePath = path.toAbsolutePath().toString(); - return filePath.endsWith(FINISHED_VERSION_SUFFIX) && - new File(filePath.substring(0, filePath.length() - FINISHED_VERSION_SUFFIX.length())).exists(); + + private List<String> listDir(String dir) throws IOException { + List<String> ret = new ArrayList<String>(); + File[] contents = new File(dir).listFiles(); + if(contents!=null) { + for(File f: contents) { + ret.add(f.getAbsolutePath()); } - }); + } + return ret; } }
