@Override public FileObject resolveFile( String vfsUrl, FileSystemOptions fsOptions ) { try { return KettleVFS.getFileObject( vfsUrl, fsOptions ); } catch ( KettleFileException e ) { throw new RuntimeException( 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 ); } }
/** * @param fileName * the filename to resolve. may contain Kettle Environment variables. * @return the data file name. * @throws IOException * ... */ private String resolveFileName( final String fileName ) throws KettleException { final FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( fileName ) ); return KettleVFS.getFilename( fileObject ); } }
public static void closeEmbeddedFileSystem( String embeddedMetastoreKey ) { if ( getInstance().getFileSystemManager() instanceof ConcurrentFileSystemManager ) { ( (ConcurrentFileSystemManager) getInstance().getFileSystemManager() ) .closeEmbeddedFileSystem( embeddedMetastoreKey ); } }
public static OutputStream getOutputStream( String vfsFilename, VariableSpace space, boolean append ) throws KettleFileException { try { FileObject fileObject = getFileObject( vfsFilename, space ); return getOutputStream( fileObject, append ); } catch ( IOException e ) { throw new KettleFileException( e ); } }
public static FileObject createTempFile( String prefix, String suffix, String directory, VariableSpace space ) throws KettleFileException { try { FileObject fileObject; do { // Build temporary file name using UUID to ensure uniqueness. Old mechanism would fail using Sort Rows (for // example) // when there multiple nodes with multiple JVMs on each node. In this case, the temp file names would end up // being // duplicated which would cause the sort to fail. String filename = new StringBuilder( 50 ).append( directory ).append( '/' ).append( prefix ).append( '_' ).append( UUIDUtil.getUUIDAsString() ).append( suffix ).toString(); fileObject = getFileObject( filename, space ); } while ( fileObject.exists() ); return fileObject; } catch ( IOException e ) { throw new KettleFileException( e ); } }
/** * 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; } }
@Override public int compare( FileObject o1, FileObject o2 ) { String filename1 = getFilename( o1 ); String filename2 = getFilename( o2 ); return filename1.compareTo( filename2 ); } };
public static InputStream getInputStream( String vfsFilename ) throws KettleFileException { return getInputStream( vfsFilename, defaultVariableSpace ); }
private void doTest( String content, boolean toUnix, String expected ) throws Exception { try ( OutputStream os = new FileOutputStream( tmpFile ) ) { IOUtils.write( content.getBytes(), os ); } entry.convert( KettleVFS.getFileObject( tmpFilePath ), toUnix ); String converted = KettleVFS.getTextFileContent( tmpFilePath, "UTF-8" ); assertEquals( expected, converted ); } }
public Log4jFileAppender( FileObject file ) throws IOException { this.file = file; fileOutputStream = KettleVFS.getOutputStream( file, false ); }
/** * 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 FileObject getFileObject( String vfsFilename, VariableSpace space, FileSystemOptions fsOptions ) throws KettleFileException { try { FileSystemManager fsManager = getInstance().getFileSystemManager(); relativeFilename = false; fsOptions = buildFsOptions( space, fsOptions, vfsFilename, schemes[i] ); + cleanseFilename( vfsFilename ) + "' : " + e.getMessage(), e );
KettleVFS.createTempFile( meta.getPrefix(), ".tmp", environmentSubstitute( meta.getDirectory() ), getTransMeta() ); OutputStream outputStream = KettleVFS.getOutputStream( fileObject, false ); if ( meta.getCompress() ) { gzos = new GZIPOutputStream( new BufferedOutputStream( outputStream ) );
/** * Creates a file using "java.io.tmpdir" directory * * @param prefix - file name * @param prefix - file extension * @return FileObject * @throws KettleFileException */ public static FileObject createTempFile( String prefix, Suffix suffix ) throws KettleFileException { return createTempFile( prefix, suffix, TEMP_DIR ); }
void defaultInit() throws Throwable { // make sure static class initializers are correctly initialized // re-init cleanUp(); KettleClientEnvironment.init(); // initialize some classes, this will fail if some tests init this classes before any PDI init() // the best thing to do is to invoke this ClassRule in every test Class.forName( Database.class.getName() ); Class.forName( Timestamp.class.getName() ); Class.forName( ValueMetaBase.class.getName() ); Class.forName( SimpleTimestampFormat.class.getName() ); Class.forName( SimpleDateFormat.class.getName() ); Class.forName( XMLHandler.class.getName() ); Class.forName( LogChannel.class.getName() ); DatabaseMeta.init(); ExtensionPointMap.getInstance().reInitialize(); KettleVFS.getInstance().reset(); // reinit }
public static OutputStream getOutputStream( String vfsFilename, VariableSpace space, FileSystemOptions fsOptions, boolean append ) throws KettleFileException { try { FileObject fileObject = getFileObject( vfsFilename, space, fsOptions ); return getOutputStream( fileObject, append ); } catch ( IOException e ) { throw new KettleFileException( e ); } }
/** * Create a file appender * @param filename The (VFS) filename (URL) to write to. * @param exact is this an exact filename of a filename to be stored in "java.io.tmp" * @return A new file appender * @throws KettleFileException In case there is a problem opening the file. */ public static final Log4jFileAppender createFileAppender( String filename, boolean exact ) throws KettleFileException { try { FileObject file; if ( !exact ) { file = KettleVFS.createTempFile( filename, ".log", System.getProperty( "java.io.tmpdir" ) ); } else { file = KettleVFS.getFileObject( filename ); } Log4jFileAppender appender = new Log4jFileAppender( file ); appender.setLayout( new Log4jKettleLayout( true ) ); appender.setName( LogWriter.createFileAppenderName( filename, exact ) ); return appender; } catch ( IOException e ) { throw new KettleFileException( "Unable to add Kettle file appender to Log4J", e ); } }
/** * @see StandardFileSystemManager#freeUnusedResources() */ public static void freeUnusedResources() { ( (StandardFileSystemManager) getInstance().getFileSystemManager() ).freeUnusedResources(); }
/** * 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; } }