diff --git a/datavec/datavec-api/src/main/java/org/datavec/api/records/reader/impl/LineRecordReader.java b/datavec/datavec-api/src/main/java/org/datavec/api/records/reader/impl/LineRecordReader.java index f951c89a3..407a71fea 100644 --- a/datavec/datavec-api/src/main/java/org/datavec/api/records/reader/impl/LineRecordReader.java +++ b/datavec/datavec-api/src/main/java/org/datavec/api/records/reader/impl/LineRecordReader.java @@ -60,6 +60,13 @@ public class LineRecordReader extends BaseRecordReader { @Override public void initialize(InputSplit split) throws IOException, InterruptedException { super.initialize(split); + if(!(inputSplit instanceof StringSplit || inputSplit instanceof InputStreamInputSplit)){ + final ArrayList uris = new ArrayList<>(); + final Iterator uriIterator = inputSplit.locationsIterator(); + while(uriIterator.hasNext()) uris.add(uriIterator.next()); + + this.locations = uris.toArray(new URI[0]); + } this.iter = getIterator(0); this.initialized = true; } @@ -68,7 +75,6 @@ public class LineRecordReader extends BaseRecordReader { public void initialize(Configuration conf, InputSplit split) throws IOException, InterruptedException { this.conf = conf; initialize(split); - this.initialized = true; } @Override @@ -207,11 +213,6 @@ public class LineRecordReader extends BaseRecordReader { } } } else { - final ArrayList uris = new ArrayList<>(); - final Iterator uriIterator = inputSplit.locationsIterator(); - while(uriIterator.hasNext()) uris.add(uriIterator.next()); - - this.locations = uris.toArray(new URI[uris.size()]); if (locations.length > 0) { InputStream inputStream = streamCreatorFn.apply(locations[location]); try { diff --git a/datavec/datavec-api/src/main/java/org/datavec/api/util/files/UriFromPathIterator.java b/datavec/datavec-api/src/main/java/org/datavec/api/util/files/UriFromPathIterator.java index ffbd36fe5..4b910410d 100644 --- a/datavec/datavec-api/src/main/java/org/datavec/api/util/files/UriFromPathIterator.java +++ b/datavec/datavec-api/src/main/java/org/datavec/api/util/files/UriFromPathIterator.java @@ -23,6 +23,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.regex.Pattern; /** * A simple utility method to convert a {@code Iterator} to an {@code Iterator}, where each @@ -32,6 +33,7 @@ import java.util.NoSuchElementException; */ @AllArgsConstructor public class UriFromPathIterator implements Iterator { + final Pattern schemaPattern = Pattern.compile("^.*?:/.*"); private final Iterator paths; @@ -42,16 +44,17 @@ public class UriFromPathIterator implements Iterator { @Override public URI next() { + if (!hasNext()) { throw new NoSuchElementException("No next element"); } try { String s = paths.next(); - if(!s.matches(".*:/.*")){ + if(schemaPattern.matcher(s).matches()){ + return new URI(s); + } else { //No scheme - assume file for backward compatibility return new File(s).toURI(); - } else { - return new URI(s); } } catch (URISyntaxException e) {