/**' * Returns the {@link InputStreamReader} corresponding to the csv file, or null if the file cannot be read. * @return the {@link InputStreamReader} corresponding to the csv file, or null if the file cannot be read */ private InputStreamReader getReader( final CsvInputMeta meta, final InputStream inputStream ) { InputStreamReader reader = null; try { String filename = transMeta.environmentSubstitute( meta.getFilename() ); FileObject fileObject = KettleVFS.getFileObject( filename ); if ( !( fileObject instanceof LocalFile ) ) { // We can only use NIO on local files at the moment, so that's what we // limit ourselves to. // throw new KettleException( BaseMessages.getString( PKG, "CsvInput.Log.OnlyLocalFilesAreSupported" ) ); } String realEncoding = transMeta.environmentSubstitute( meta.getEncoding() ); if ( Utils.isEmpty( realEncoding ) ) { reader = new InputStreamReader( inputStream ); } else { reader = new InputStreamReader( inputStream, realEncoding ); } } catch ( final Exception e ) { logError( BaseMessages.getString( PKG, "CsvInputDialog.ErrorGettingFileDesc.DialogMessage" ), e ); } return reader; }
wRowNumField.setText( Const.NVL( inputMeta.getRowNumField(), "" ) ); wAddResult.setSelection( inputMeta.isAddResultFile() ); wEncoding.setText( Const.NVL( inputMeta.getEncoding(), "" ) );
String[] readFieldNamesFromFile( String fileName, CsvInputMeta csvInputMeta ) throws KettleException { String delimiter = environmentSubstitute( csvInputMeta.getDelimiter() ); String enclosure = environmentSubstitute( csvInputMeta.getEnclosure() ); String realEncoding = environmentSubstitute( csvInputMeta.getEncoding() ); try ( FileObject fileObject = KettleVFS.getFileObject( fileName, getTransMeta() ); BOMInputStream inputStream = new BOMInputStream( KettleVFS.getInputStream( fileObject ), ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE ) ) { InputStreamReader reader = null; if ( Utils.isEmpty( realEncoding ) ) { reader = new InputStreamReader( inputStream ); } else { reader = new InputStreamReader( inputStream, realEncoding ); } EncodingType encodingType = EncodingType.guessEncodingType( reader.getEncoding() ); String line = TextFileInput.getLine( log, reader, encodingType, TextFileInputMeta.FILE_FORMAT_UNIX, new StringBuilder( 1000 ) ); String[] fieldNames = CsvInput.guessStringsFromLine( log, line, delimiter, enclosure, csvInputMeta.getEscapeCharacter() ); if ( !Utils.isEmpty( csvInputMeta.getEnclosure() ) ) { removeEnclosure( fieldNames, csvInputMeta.getEnclosure() ); } trimFieldNames( fieldNames ); return fieldNames; } catch ( IOException e ) { throw new KettleFileException( BaseMessages.getString( PKG, "CsvInput.Exception.CreateFieldMappingError" ), e ); } }
String realEncoding = environmentSubstitute( meta.getEncoding() ); data.preferredBufferSize = Integer.parseInt( environmentSubstitute( meta.getBufferSize() ) );