{"record":{"id":"6e113aa6f081604c","repo":"deeplearning4j/deeplearning4j","slug":"error-reading-from-stream-for-uri-next","errorCode":null,"errorMessage":"Error reading from stream for URI: + next","messagePattern":"Error reading from stream for URI: \\+ next","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"datavec/datavec-api/src/main/java/org/datavec/api/records/reader/impl/FileRecordReader.java","lineNumber":211,"sourceCode":"        BufferedReader br = new BufferedReader(new InputStreamReader(dataInputStream));\n        StringBuilder sb = new StringBuilder();\n        String line;\n        while ((line = br.readLine()) != null) {\n            sb.append(line).append(\"\\n\");\n        }\n        return Collections.singletonList((Writable) new Text(sb.toString()));\n    }\n\n    @Override\n    public Record nextRecord() {\n        URI next = locationsIterator.next();\n        invokeListeners(next);\n\n        List<Writable> ret;\n        try(InputStream s = streamCreatorFn.apply(next)) {\n            ret = loadFromStream(next, s, Charset.forName(charset));\n        } catch (IOException e){\n            throw new RuntimeException(\"Error reading from stream for URI: \" + next);\n        }\n\n        return new org.datavec.api.records.impl.Record(ret,new RecordMetaDataURI(next, FileRecordReader.class));\n    }\n\n    @Override\n    public Record loadFromMetaData(RecordMetaData recordMetaData) throws IOException {\n        return loadFromMetaData(Collections.singletonList(recordMetaData)).get(0);\n    }\n\n    @Override\n    public List<Record> loadFromMetaData(List<RecordMetaData> recordMetaDatas) throws IOException {\n        List<Record> out = new ArrayList<>();\n\n        for (RecordMetaData meta : recordMetaDatas) {\n            URI uri = meta.getURI();\n\n            List<Writable> list;","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/datavec/datavec-api/src/main/java/org/datavec/api/records/reader/impl/FileRecordReader.java#L193-L229","documentation":"FileRecordReader.nextRecord() wraps any IOException thrown while opening or reading the stream for the current URI into an unchecked RuntimeException. This means the underlying file could not be read (missing, unreadable, deleted mid-iteration, or a failing stream creator function). The original IOException cause is discarded, so the message only tells you which URI failed.","triggerScenarios":"Calling nextRecord() (directly or via next()/r) when streamCreatorFn.apply(next) returns a stream for a URI that cannot be opened, or loadFromStream throws IOException while parsing bytes for that URI.","commonSituations":"Input split locations point to files deleted or renamed after initialization; a network/remote URI became unreachable; file permissions changed; a listener (invokeListeners) or charset produced an IO error during loadFromStream; using archives/compressed files whose streams fail mid-read.","solutions":["Verify the URI exists and is readable before initializing the reader (Files.exists / Files.isReadable) and re-initialize with valid locations.","Check filesystem/network availability for the URI; fix permissions or restore the file.","Ensure the streamCreatorFn is configured to handle the URI scheme in use (file, hdfs, archive, etc.).","Set a valid charset (default should be UTF-8) so Charset.forName inside the try block does not contribute failures."],"exampleFix":"// before\nRecordReader reader = new FileRecordReader();\nreader.initialize(split); // split points at a file deleted afterwards\nRecord rec = reader.nextRecord();\n\n// after\nFile f = new File(split.locations()[0]);\nif (!f.exists() || !f.canRead()) {\n    throw new IllegalStateException(\"Input file missing/unreadable: \" + f);\n}\nRecordReader reader = new FileRecordReader();\nreader.initialize(split);","handlingStrategy":"try-catch","validationCode":"for (URI u : split.locations()) {\n    if (!Files.isReadable(Paths.get(u)))\n        throw new IllegalStateException(\"Unreadable input: \" + u);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Record rec = reader.nextRecord();\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Error reading from stream for URI\")) {\n        log.error(\"Skipping unreadable URI\", e);\n        // skip / fail over to backup location\n    } else throw e;\n}","preventionTips":["Validate all split locations exist and are readable before initialize().","Configure streamCreatorFn for every URI scheme you use.","Avoid deleting/moving input files while a reader is active.","Wrap long-running reads with retry on transient network filesystems."],"tags":["io","file-read","runtime-exception","record-reader"],"backgroundTag":"file-read-failed","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}