@Test public void testByteArray() throws Exception { RowMetaInterface mockedRowMetaInterface = mock( RowMetaInterface.class ); stepLoadFileInput.data.outputRowMeta = mockedRowMetaInterface; stepLoadFileInput.data.convertRowMeta = mockedRowMetaInterface; Mockito.doReturn( new ValueMetaString() ).when( mockedRowMetaInterface ).getValueMeta( anyInt() ); Mockito.doReturn( new ValueMetaBinary() ).when( mockedRowMetaInterface ).getValueMeta( anyInt() ); ( (LoadFileInputMeta) runtimeSMI ).setEncoding( "UTF-8" ); stepInputFiles.addFile( getFile( "pentaho_splash.png" ) ); inputField = new LoadFileInputField(); inputField.setType( ValueMetaInterface.TYPE_BINARY ); ( (LoadFileInputMeta) runtimeSMI ).setInputFields( new LoadFileInputField[]{ inputField } ); assertNotNull( stepLoadFileInput.getOneRow() ); assertArrayEquals( IOUtils.toByteArray( getFile( "pentaho_splash.png" ).getContent().getInputStream() ), stepLoadFileInput.data.filecontent ); }
Object[] getOneRow() throws KettleException { if ( !openNextFile() ) { return null; } Object[] outputRowData = buildEmptyRow(); try { if ( meta.getIsInFields() ) { outputRowData = data.readrow.clone(); } for ( int i = 0; i < data.nrInputFields; i++ ) { LoadFileInputField loadFileInputField = meta.getInputFields()[i]; Object o = null; int indexField = data.totalpreviousfields + i; ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( indexField ); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( indexField ); switch ( loadFileInputField.getElementType() ) { case LoadFileInputField.ELEMENT_TYPE_FILECONTENT: switch ( loadFileInputField.getTrimType() ) { case LoadFileInputField.TYPE_TRIM_LEFT: if ( meta.getEncoding() != null ) { data.filecontent = Const.ltrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.ltrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_RIGHT: if ( meta.getEncoding() != null ) { data.filecontent = Const.rtrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.rtrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_BOTH: if ( meta.getEncoding() != null ) { data.filecontent = Const.trim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.trim( new String( data.filecontent ) ).getBytes(); } break; default: break; } if ( targetValueMeta.getType() != ValueMetaInterface.TYPE_BINARY ) { if ( meta.getEncoding() != null ) { o = new String( data.filecontent, meta.getEncoding() ); } else { o = new String( data.filecontent ); } } else { o = data.filecontent; } break; case LoadFileInputField.ELEMENT_TYPE_FILESIZE: o = String.valueOf( data.fileSize ); break; default: break; } if ( targetValueMeta.getType() == ValueMetaInterface.TYPE_BINARY ) { outputRowData[indexField] = o; } else { outputRowData[indexField] = targetValueMeta.convertData( sourceValueMeta, o ); } if ( loadFileInputField.isRepeated() ) { if ( data.previousRow != null && o == null ) { outputRowData[indexField] = data.previousRow[indexField]; } } } int rowIndex = data.totalpreviousfields + data.nrInputFields; if ( meta.includeFilename() && meta.getFilenameField() != null && meta.getFilenameField().length() > 0 ) { outputRowData[rowIndex++] = data.filename; } if ( meta.includeRowNumber() && meta.getRowNumberField() != null && meta.getRowNumberField().length() > 0 ) { outputRowData[rowIndex++] = new Long( data.rownr ); } if ( meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0 ) { outputRowData[rowIndex++] = data.shortFilename; } if ( meta.getExtensionField() != null && meta.getExtensionField().length() > 0 ) { outputRowData[rowIndex++] = data.extension; } if ( meta.getPathField() != null && meta.getPathField().length() > 0 ) { outputRowData[rowIndex++] = data.path; } if ( meta.isHiddenField() != null && meta.isHiddenField().length() > 0 ) { outputRowData[rowIndex++] = new Boolean( data.hidden ); } if ( meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0 ) { outputRowData[rowIndex++] = data.lastModificationDateTime; } if ( meta.getUriField() != null && meta.getUriField().length() > 0 ) { outputRowData[rowIndex++] = data.uriName; } if ( meta.getRootUriField() != null && meta.getRootUriField().length() > 0 ) { outputRowData[rowIndex++] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : irow.cloneRow( outputRowData ); incrementLinesInput(); data.rownr++; } catch ( Exception e ) { throw new KettleException( "Error during processing a row", e ); } return outputRowData; }
LoadFileInput extends BaseStep implements StepInterface { Object[] getOneRow() throws KettleException { if ( !openNextFile() ) { return null; } Object[] outputRowData = buildEmptyRow(); try { if ( meta.getIsInFields() ) { outputRowData = data.readrow.clone(); } for ( int i = 0; i < data.nrInputFields; i++ ) { LoadFileInputField loadFileInputField = meta.getInputFields()[i]; Object o = null; int indexField = data.totalpreviousfields + i; ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( indexField ); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( indexField ); switch ( loadFileInputField.getElementType() ) { case LoadFileInputField.ELEMENT_TYPE_FILECONTENT: switch ( loadFileInputField.getTrimType() ) { case LoadFileInputField.TYPE_TRIM_LEFT: if ( meta.getEncoding() != null ) { data.filecontent = Const.ltrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.ltrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_RIGHT: if ( meta.getEncoding() != null ) { data.filecontent = Const.rtrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.rtrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_BOTH: if ( meta.getEncoding() != null ) { data.filecontent = Const.trim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.trim( new String( data.filecontent ) ).getBytes(); } break; default: break; } if ( targetValueMeta.getType() != ValueMetaInterface.TYPE_BINARY ) { if ( meta.getEncoding() != null ) { o = new String( data.filecontent, meta.getEncoding() ); } else { o = new String( data.filecontent ); } } else { o = data.filecontent; } break; case LoadFileInputField.ELEMENT_TYPE_FILESIZE: o = String.valueOf( data.fileSize ); break; default: break; } if ( targetValueMeta.getType() == ValueMetaInterface.TYPE_BINARY ) { outputRowData[indexField] = o; } else { outputRowData[indexField] = targetValueMeta.convertData( sourceValueMeta, o ); } if ( loadFileInputField.isRepeated() ) { if ( data.previousRow != null && o == null ) { outputRowData[indexField] = data.previousRow[indexField]; } } } int rowIndex = data.totalpreviousfields + data.nrInputFields; if ( meta.includeFilename() && meta.getFilenameField() != null && meta.getFilenameField().length() > 0 ) { outputRowData[rowIndex++] = data.filename; } if ( meta.includeRowNumber() && meta.getRowNumberField() != null && meta.getRowNumberField().length() > 0 ) { outputRowData[rowIndex++] = new Long( data.rownr ); } if ( meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0 ) { outputRowData[rowIndex++] = data.shortFilename; } if ( meta.getExtensionField() != null && meta.getExtensionField().length() > 0 ) { outputRowData[rowIndex++] = data.extension; } if ( meta.getPathField() != null && meta.getPathField().length() > 0 ) { outputRowData[rowIndex++] = data.path; } if ( meta.isHiddenField() != null && meta.isHiddenField().length() > 0 ) { outputRowData[rowIndex++] = new Boolean( data.hidden ); } if ( meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0 ) { outputRowData[rowIndex++] = data.lastModificationDateTime; } if ( meta.getUriField() != null && meta.getUriField().length() > 0 ) { outputRowData[rowIndex++] = data.uriName; } if ( meta.getRootUriField() != null && meta.getRootUriField().length() > 0 ) { outputRowData[rowIndex++] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : irow.cloneRow( outputRowData ); incrementLinesInput(); data.rownr++; } catch ( Exception e ) { throw new KettleException( "Error during processing a row", e ); } return outputRowData; } }
LoadFileInput extends BaseStep implements StepInterface { Object[] getOneRow() throws KettleException { if ( !openNextFile() ) { return null; } Object[] outputRowData = buildEmptyRow(); try { if ( meta.getIsInFields() ) { outputRowData = data.readrow.clone(); } for ( int i = 0; i < data.nrInputFields; i++ ) { LoadFileInputField loadFileInputField = meta.getInputFields()[i]; Object o = null; int indexField = data.totalpreviousfields + i; ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( indexField ); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( indexField ); switch ( loadFileInputField.getElementType() ) { case LoadFileInputField.ELEMENT_TYPE_FILECONTENT: switch ( loadFileInputField.getTrimType() ) { case LoadFileInputField.TYPE_TRIM_LEFT: if ( meta.getEncoding() != null ) { data.filecontent = Const.ltrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.ltrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_RIGHT: if ( meta.getEncoding() != null ) { data.filecontent = Const.rtrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.rtrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_BOTH: if ( meta.getEncoding() != null ) { data.filecontent = Const.trim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.trim( new String( data.filecontent ) ).getBytes(); } break; default: break; } if ( targetValueMeta.getType() != ValueMetaInterface.TYPE_BINARY ) { if ( meta.getEncoding() != null ) { o = new String( data.filecontent, meta.getEncoding() ); } else { o = new String( data.filecontent ); } } else { o = data.filecontent; } break; case LoadFileInputField.ELEMENT_TYPE_FILESIZE: o = String.valueOf( data.fileSize ); break; default: break; } if ( targetValueMeta.getType() == ValueMetaInterface.TYPE_BINARY ) { outputRowData[indexField] = o; } else { outputRowData[indexField] = targetValueMeta.convertData( sourceValueMeta, o ); } if ( loadFileInputField.isRepeated() ) { if ( data.previousRow != null && o == null ) { outputRowData[indexField] = data.previousRow[indexField]; } } } int rowIndex = data.totalpreviousfields + data.nrInputFields; if ( meta.includeFilename() && meta.getFilenameField() != null && meta.getFilenameField().length() > 0 ) { outputRowData[rowIndex++] = data.filename; } if ( meta.includeRowNumber() && meta.getRowNumberField() != null && meta.getRowNumberField().length() > 0 ) { outputRowData[rowIndex++] = new Long( data.rownr ); } if ( meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0 ) { outputRowData[rowIndex++] = data.shortFilename; } if ( meta.getExtensionField() != null && meta.getExtensionField().length() > 0 ) { outputRowData[rowIndex++] = data.extension; } if ( meta.getPathField() != null && meta.getPathField().length() > 0 ) { outputRowData[rowIndex++] = data.path; } if ( meta.isHiddenField() != null && meta.isHiddenField().length() > 0 ) { outputRowData[rowIndex++] = new Boolean( data.hidden ); } if ( meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0 ) { outputRowData[rowIndex++] = data.lastModificationDateTime; } if ( meta.getUriField() != null && meta.getUriField().length() > 0 ) { outputRowData[rowIndex++] = data.uriName; } if ( meta.getRootUriField() != null && meta.getRootUriField().length() > 0 ) { outputRowData[rowIndex++] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : irow.cloneRow( outputRowData ); incrementLinesInput(); data.rownr++; } catch ( Exception e ) { throw new KettleException( "Error during processing a row", e ); } return outputRowData; } LoadFileInput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); }
LoadFileInput extends BaseStep implements StepInterface { Object[] getOneRow() throws KettleException { if ( !openNextFile() ) { return null; } Object[] outputRowData = buildEmptyRow(); try { if ( meta.getIsInFields() ) { outputRowData = data.readrow.clone(); } for ( int i = 0; i < data.nrInputFields; i++ ) { LoadFileInputField loadFileInputField = meta.getInputFields()[i]; Object o = null; int indexField = data.totalpreviousfields + i; ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( indexField ); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( indexField ); switch ( loadFileInputField.getElementType() ) { case LoadFileInputField.ELEMENT_TYPE_FILECONTENT: switch ( loadFileInputField.getTrimType() ) { case LoadFileInputField.TYPE_TRIM_LEFT: if ( meta.getEncoding() != null ) { data.filecontent = Const.ltrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.ltrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_RIGHT: if ( meta.getEncoding() != null ) { data.filecontent = Const.rtrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.rtrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_BOTH: if ( meta.getEncoding() != null ) { data.filecontent = Const.trim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.trim( new String( data.filecontent ) ).getBytes(); } break; default: break; } if ( targetValueMeta.getType() != ValueMetaInterface.TYPE_BINARY ) { if ( meta.getEncoding() != null ) { o = new String( data.filecontent, meta.getEncoding() ); } else { o = new String( data.filecontent ); } } else { o = data.filecontent; } break; case LoadFileInputField.ELEMENT_TYPE_FILESIZE: o = String.valueOf( data.fileSize ); break; default: break; } if ( targetValueMeta.getType() == ValueMetaInterface.TYPE_BINARY ) { outputRowData[indexField] = o; } else { outputRowData[indexField] = targetValueMeta.convertData( sourceValueMeta, o ); } if ( loadFileInputField.isRepeated() ) { if ( data.previousRow != null && o == null ) { outputRowData[indexField] = data.previousRow[indexField]; } } } int rowIndex = data.totalpreviousfields + data.nrInputFields; if ( meta.includeFilename() && meta.getFilenameField() != null && meta.getFilenameField().length() > 0 ) { outputRowData[rowIndex++] = data.filename; } if ( meta.includeRowNumber() && meta.getRowNumberField() != null && meta.getRowNumberField().length() > 0 ) { outputRowData[rowIndex++] = new Long( data.rownr ); } if ( meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0 ) { outputRowData[rowIndex++] = data.shortFilename; } if ( meta.getExtensionField() != null && meta.getExtensionField().length() > 0 ) { outputRowData[rowIndex++] = data.extension; } if ( meta.getPathField() != null && meta.getPathField().length() > 0 ) { outputRowData[rowIndex++] = data.path; } if ( meta.isHiddenField() != null && meta.isHiddenField().length() > 0 ) { outputRowData[rowIndex++] = new Boolean( data.hidden ); } if ( meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0 ) { outputRowData[rowIndex++] = data.lastModificationDateTime; } if ( meta.getUriField() != null && meta.getUriField().length() > 0 ) { outputRowData[rowIndex++] = data.uriName; } if ( meta.getRootUriField() != null && meta.getRootUriField().length() > 0 ) { outputRowData[rowIndex++] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : irow.cloneRow( outputRowData ); incrementLinesInput(); data.rownr++; } catch ( Exception e ) { throw new KettleException( "Error during processing a row", e ); } return outputRowData; } LoadFileInput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); static byte[] getFileBinaryContent( String vfsFilename ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }
LoadFileInput extends BaseStep implements StepInterface { Object[] getOneRow() throws KettleException { if ( !openNextFile() ) { return null; } Object[] outputRowData = buildEmptyRow(); try { if ( meta.getIsInFields() ) { outputRowData = data.readrow.clone(); } for ( int i = 0; i < data.nrInputFields; i++ ) { LoadFileInputField loadFileInputField = meta.getInputFields()[i]; Object o = null; int indexField = data.totalpreviousfields + i; ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( indexField ); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( indexField ); switch ( loadFileInputField.getElementType() ) { case LoadFileInputField.ELEMENT_TYPE_FILECONTENT: switch ( loadFileInputField.getTrimType() ) { case LoadFileInputField.TYPE_TRIM_LEFT: if ( meta.getEncoding() != null ) { data.filecontent = Const.ltrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.ltrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_RIGHT: if ( meta.getEncoding() != null ) { data.filecontent = Const.rtrim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.rtrim( new String( data.filecontent ) ).getBytes(); } break; case LoadFileInputField.TYPE_TRIM_BOTH: if ( meta.getEncoding() != null ) { data.filecontent = Const.trim( new String( data.filecontent, meta.getEncoding() ) ).getBytes(); } else { data.filecontent = Const.trim( new String( data.filecontent ) ).getBytes(); } break; default: break; } if ( targetValueMeta.getType() != ValueMetaInterface.TYPE_BINARY ) { if ( meta.getEncoding() != null ) { o = new String( data.filecontent, meta.getEncoding() ); } else { o = new String( data.filecontent ); } } else { o = data.filecontent; } break; case LoadFileInputField.ELEMENT_TYPE_FILESIZE: o = String.valueOf( data.fileSize ); break; default: break; } if ( targetValueMeta.getType() == ValueMetaInterface.TYPE_BINARY ) { outputRowData[indexField] = o; } else { outputRowData[indexField] = targetValueMeta.convertData( sourceValueMeta, o ); } if ( loadFileInputField.isRepeated() ) { if ( data.previousRow != null && o == null ) { outputRowData[indexField] = data.previousRow[indexField]; } } } int rowIndex = data.totalpreviousfields + data.nrInputFields; if ( meta.includeFilename() && meta.getFilenameField() != null && meta.getFilenameField().length() > 0 ) { outputRowData[rowIndex++] = data.filename; } if ( meta.includeRowNumber() && meta.getRowNumberField() != null && meta.getRowNumberField().length() > 0 ) { outputRowData[rowIndex++] = new Long( data.rownr ); } if ( meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0 ) { outputRowData[rowIndex++] = data.shortFilename; } if ( meta.getExtensionField() != null && meta.getExtensionField().length() > 0 ) { outputRowData[rowIndex++] = data.extension; } if ( meta.getPathField() != null && meta.getPathField().length() > 0 ) { outputRowData[rowIndex++] = data.path; } if ( meta.isHiddenField() != null && meta.isHiddenField().length() > 0 ) { outputRowData[rowIndex++] = new Boolean( data.hidden ); } if ( meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0 ) { outputRowData[rowIndex++] = data.lastModificationDateTime; } if ( meta.getUriField() != null && meta.getUriField().length() > 0 ) { outputRowData[rowIndex++] = data.uriName; } if ( meta.getRootUriField() != null && meta.getRootUriField().length() > 0 ) { outputRowData[rowIndex++] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : irow.cloneRow( outputRowData ); incrementLinesInput(); data.rownr++; } catch ( Exception e ) { throw new KettleException( "Error during processing a row", e ); } return outputRowData; } LoadFileInput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); static byte[] getFileBinaryContent( String vfsFilename ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi );  }