public static InputStream getInputStream( String vfsFilename ) throws KettleFileException { return getInputStream( vfsFilename, defaultVariableSpace ); }
/** * This is not thread safe: please try to get the file appender yourself using the static constructor and work from there */ public InputStream getFileInputStream() throws IOException { return KettleVFS.getInputStream( fileAppender.getFile() ); }
/** * Sample a json file by name * * @param file - a file name * @return The sampled Node * @throws IOException */ public Node sample( String file ) throws IOException, KettleFileException { try { return sample( KettleVFS.getInputStream( file ) ); } catch ( KettleFileException kfe ) { throw kfe; } }
public static String getTextFileContent( String vfsFilename, VariableSpace space, String charSetName ) throws KettleFileException { try { InputStream inputStream = null; if ( space == null ) { inputStream = getInputStream( vfsFilename ); } else { inputStream = getInputStream( vfsFilename, space ); } InputStreamReader reader = new InputStreamReader( inputStream, charSetName ); int c; StringBuilder aBuffer = new StringBuilder(); while ( ( c = reader.read() ) != -1 ) { aBuffer.append( (char) c ); } reader.close(); inputStream.close(); return aBuffer.toString(); } catch ( IOException e ) { throw new KettleFileException( e ); } }
/** * Internal image loading from Kettle's VFS. */ private static SwingUniversalImage loadFromSimpleVFS( String location ) { try { InputStream s = KettleVFS.getInputStream( location ); if ( s == null ) { return null; } try { return loadImage( s, location ); } finally { IOUtils.closeQuietly( s ); } } catch ( KettleFileException e ) { // do nothing. try to load next } return null; }
/** * Internal image loading from Kettle's VFS. */ private static SwtUniversalImage loadFromSimpleVFS( Display display, String location ) { try { InputStream s = KettleVFS.getInputStream( location ); if ( s == null ) { return null; } try { return loadImage( display, s, location ); } finally { IOUtils.closeQuietly( s ); } } catch ( KettleFileException e ) { // do nothing. try to load next } return null; }
/** * TODO: GUI resources. */ public static Image getImage( Display display, String location ) { // TODO: find other instances of getImage (plugin, steps) and transition them to new model through an laf manager try { InputStream is = KettleVFS.getInputStream( location ); Image im = new Image( display, is ); is.close(); return im; } catch ( Exception e ) { try { return new Image( display, ImageUtil.class.getClassLoader().getResourceAsStream( location ) ); } catch ( Exception npe ) { throw new RuntimeException( "Unable to load image with name [" + location + "]", e ); } } }
/** * Copies a VFS File * * @param in the source file object * @param out the destination file object * @throws KettleException */ public static void copyFile( FileObject in, FileObject out ) throws KettleException { try ( BufferedInputStream fis = new BufferedInputStream( KettleVFS.getInputStream( in ) ); BufferedOutputStream fos = new BufferedOutputStream( KettleVFS.getOutputStream( out, false ) ) ) { byte[] buf = new byte[ 1024 * 1024 ]; // copy in chunks of 1 MB int i = 0; while ( ( i = fis.read( buf ) ) != -1 ) { fos.write( buf, 0, i ); } } catch ( Exception e ) { throw new KettleException( e ); } }
public static InputStream getInputStream( String vfsFilename, VariableSpace space ) throws KettleFileException { try { FileObject fileObject = getFileObject( vfsFilename, space ); return getInputStream( fileObject ); } catch ( IOException e ) { throw new KettleFileException( e ); } }
public OdfWorkbook( String filename, String encoding ) throws KettleException { this.filename = filename; this.encoding = encoding; try { document = OdfSpreadsheetDocument.loadDocument( KettleVFS.getInputStream( filename ) ); } catch ( Exception e ) { throw new KettleException( e ); } }
/** * Load a file into an XML document * * @param fileObject * The fileObject to load into a document * @param systemID * Provide a base for resolving relative URIs. * @param ignoreEntities * Ignores external entities and returns an empty dummy. * @param namespaceAware * support XML namespaces. * @return the Document if all went well, null if an error occured! */ public static Document loadXMLFile( FileObject fileObject, String systemID, boolean ignoreEntities, boolean namespaceAware ) throws KettleXMLException { try { return loadXMLFile( KettleVFS.getInputStream( fileObject ), systemID, ignoreEntities, namespaceAware ); } catch ( IOException e ) { throw new KettleXMLException( "Unable to read file [" + fileObject.toString() + "]", e ); } }
public void loadFile( String filename ) throws Exception { this.filename = filename; this.file = KettleVFS.getFileObject( filename ); InputStream is = null; try { is = KettleVFS.getInputStream( getFile() ); for ( Object data : getYaml().loadAll( is ) ) { documents.add( data ); this.useMap = ( data instanceof Map ); } this.documenti = documents.iterator(); } finally { if ( is != null ) { is.close(); } } }
public void put( FileObject fileObject, String remoteFile ) throws KettleJobException { int mode = ChannelSftp.OVERWRITE; InputStream inputStream = null; try { inputStream = KettleVFS.getInputStream( fileObject ); c.put( inputStream, remoteFile, null, mode ); } catch ( Exception e ) { throw new KettleJobException( e ); } finally { if ( inputStream != null ) { try { inputStream.close(); } catch ( IOException e ) { throw new KettleJobException( e ); } } } }
private void openNewFile() throws KettleException { try ( FileObject newFile = KettleVFS.getFileObject( data.filename, getTransMeta() ) ) { data.pro = new Properties(); data.KeySet.clear(); data.file = newFile; if ( meta.isAppend() && data.file.exists() ) { data.pro.load( KettleVFS.getInputStream( data.file ) ); } // Create parent folder if needed... createParentFolder(); //save processing file data.previousFileName = data.filename; } catch ( Exception e ) { throw new KettleException( "Error opening file [" + data.filename + "]!", e ); } }
private boolean copyFile( String src, String dest ) throws KettleFileException, IOException { FileObject srcFile = getFileObjectFromKettleVFS( src ); FileObject destFile = getFileObjectFromKettleVFS( dest ); try ( InputStream in = KettleVFS.getInputStream( srcFile ); OutputStream out = KettleVFS.getOutputStream( destFile, false ) ) { IOUtils.copy( in, out ); } return true; }
/** * Internal image loading from Kettle's user.dir VFS. */ private static SwtUniversalImage loadFromBasedVFS( Display display, String location ) { try { FileObject imageFileObject = KettleVFS.getInstance().getFileSystemManager().resolveFile( base, location ); InputStream s = KettleVFS.getInputStream( imageFileObject ); if ( s == null ) { return null; } try { return loadImage( display, s, location ); } finally { IOUtils.closeQuietly( s ); } } catch ( FileSystemException ex ) { return null; } }
/** * Internal image loading from Kettle's user.dir VFS. */ private static SwingUniversalImage loadFromBasedVFS( String location ) { try { FileObject imageFileObject = KettleVFS.getInstance().getFileSystemManager().resolveFile( base, location ); InputStream s = KettleVFS.getInputStream( imageFileObject ); if ( s == null ) { return null; } try { return loadImage( s, location ); } finally { IOUtils.closeQuietly( s ); } } catch ( FileSystemException ex ) { return null; } }
public XLSWorkbook( String filename, String encoding ) throws KettleException { this.filename = filename; this.encoding = encoding; WorkbookSettings ws = new WorkbookSettings(); if ( !Utils.isEmpty( encoding ) ) { ws.setEncoding( encoding ); } try { workbook = Workbook.getWorkbook( KettleVFS.getInputStream( filename ), ws ); } catch ( Exception e ) { throw new KettleException( e ); } }
@Override public InputStream getInputStream( final CsvInputAwareMeta meta ) { InputStream inputStream = null; try { FileObject fileObject = meta.getHeaderFileObject( getTransMeta() ); 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( "FileInputDialog.Log.OnlyLocalFilesAreSupported" ) ); } inputStream = KettleVFS.getInputStream( fileObject ); } catch ( final Exception e ) { logError( BaseMessages.getString( "FileInputDialog.ErrorGettingFileDesc.DialogMessage" ), e ); } return inputStream; }
@Override public InputStream getInputStream( final CsvInputAwareMeta meta ) { InputStream fileInputStream; CompressionInputStream inputStream = null; try { FileObject fileObject = meta.getHeaderFileObject( getTransMeta() ); fileInputStream = KettleVFS.getInputStream( fileObject ); CompressionProvider provider = CompressionProviderFactory.getInstance().createCompressionProviderInstance( ( (TextFileInputMeta) meta ).content.fileCompression ); inputStream = provider.createInputStream( fileInputStream ); } catch ( final Exception e ) { logError( BaseMessages.getString( "FileInputDialog.ErrorGettingFileDesc.DialogMessage" ), e ); } return inputStream; } }