{"record":{"id":"94d945adda6dfdc5","repo":"pentaho/pentaho-kettle","slug":"exception-reading-line-using-nio-fixedinput","errorCode":null,"errorMessage":"Exception reading line using NIO: ","messagePattern":"Exception reading line using NIO: ","errorType":"exception","errorClass":"KettleFileException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/fixedinput/FixedInput.java","lineNumber":228,"sourceCode":"\n        // CR + Line feed in the worst case.\n        //\n        if ( data.byteBuffer[data.startBuffer] == '\\n' || data.byteBuffer[data.startBuffer] == '\\r' ) {\n\n          data.startBuffer++;\n\n          if ( data.byteBuffer[data.startBuffer] == '\\n' || data.byteBuffer[data.startBuffer] == '\\r' ) {\n\n            data.startBuffer++;\n          }\n        }\n        data.endBuffer = data.startBuffer;\n      }\n\n      incrementLinesInput();\n      return outputRowData;\n    } catch ( Exception e ) {\n      throw new KettleFileException( \"Exception reading line using NIO: \" + e.toString(), e );\n    }\n\n  }\n\n  private FileInputStream getFileInputStream( URL url ) throws FileNotFoundException {\n    return new FileInputStream( FileUtils.toFile( url ) );\n  }\n\n  public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {\n    meta = (FixedInputMeta) smi;\n    data = (FixedInputData) sdi;\n\n    if ( super.init( smi, sdi ) ) {\n      try {\n        data.preferredBufferSize = Integer.parseInt( environmentSubstitute( meta.getBufferSize() ) );\n        data.lineWidth = Integer.parseInt( environmentSubstitute( meta.getLineWidth() ) );\n        data.filename = environmentSubstitute( meta.getFilename() );\n","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/fixedinput/FixedInput.java#L210-L246","documentation":"FixedInput.readOneRow catches any exception while reading/parsing one fixed-width line via NIO and rethrows it as a KettleFileException with this message plus e.toString(). It indicates the NIO file read or line conversion failed mid-processing, not a field mapping issue.","triggerScenarios":"Reading a fixed-width file whose byte size is not a multiple of the line length, an I/O error on the underlying channel, or charset/decode errors during ByteBuffer-to-string conversion in processRow.","commonSituations":"Files transferred in text mode with altered line endings or trailing partial lines; wrong 'line length' setting in the Fixed file input step so the buffer math breaks; file truncated or locked by another process.","solutions":["Fix the step's line length / buffer size settings so fileSize is an exact multiple of the line size","Check the chained exception for I/O vs decode errors and repair the source file (CRLF issues, truncation)","Re-transfer the file in binary mode and verify expected file size","Open the file in the step's preview to confirm the layout matches before running the full transformation"],"exampleFix":"// before\nfileSize = file.length(); // may include trailing partial line\n// after\nlong lines = file.length() / lineLength;\nfileSize = lines * lineLength; // ignore trailing partial bytes","handlingStrategy":"validation","validationCode":"// validate file before running the transformation\nlong size = new File( filename ).length();\nif ( lineLength <= 0 || size % lineLength != 0 ) {\n  throw new IllegalStateException( \"File size \" + size + \" not a multiple of line length \" + lineLength );\n}","typeGuard":null,"tryCatchPattern":"try {\n  trans.execute( null );\n} catch ( KettleException e ) {\n  if ( e.getMessage().startsWith( \"Exception reading line using NIO\" ) ) {\n    // fix file/line-length config and retry\n  }\n}","preventionTips":["Match the step's line length exactly to the file layout","Transfer files in binary mode to avoid CRLF changes","Preview a few rows before full runs","Check file size vs expected record count"],"tags":["pdi","kettle","file-io","nio","fixed-width"],"backgroundTag":"file-read-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}