/** * 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 ); }
/** * * @param prefix - file name * @param suffix - file extension * @param directory - directory where file will be created * @return FileObject * @throws KettleFileException */ public static FileObject createTempFile( String prefix, Suffix suffix, String directory ) throws KettleFileException { return createTempFile( prefix, suffix, directory, null ); }
/** * Creates a file using "java.io.tmpdir" directory * * @param prefix - file name * @param suffix - file extension * @param variableSpace is used to get system variables * @return FileObject * @throws KettleFileException */ public static FileObject createTempFile( String prefix, Suffix suffix, VariableSpace variableSpace ) throws KettleFileException { return createTempFile( prefix, suffix, TEMP_DIR, variableSpace ); }
public static FileObject createTempFile( String prefix, String suffix, String directory ) throws KettleFileException { return createTempFile( prefix, suffix, directory, null ); }
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 ); } }
KettleVFS.createTempFile( meta.getPrefix(), ".tmp", environmentSubstitute( meta.getDirectory() ), getTransMeta() );
private URL[] prepareJarFiles( FileObject zipFile ) throws Exception { // zip:file:///tmp/foo.zip FileInputList fileList = FileInputList.createFileList( this, new String[] { "zip:" + zipFile.toString(), }, new String[] { ".*\\.jar$", }, // Include mask: only jar files new String[] { ".*classpath\\.jar$", }, // Exclude mask: only jar files new String[] { "Y", }, // File required new boolean[] { true, } ); // Search sub-directories List<URL> files = new ArrayList<URL>(); // Copy the jar files in the temp folder... // for ( FileObject file : fileList.getFiles() ) { FileObject jarfilecopy = KettleVFS.createTempFile( file.getName().getBaseName(), ".jar", environmentSubstitute( "${java.io.tmpdir}" ) ); jarfilecopy.copyFrom( file, new AllFileSelector() ); files.add( jarfilecopy.getURL() ); } return files.toArray( new URL[files.size()] ); }
KettleVFS.createTempFile( meta.getPrefix(), ".tmp", environmentSubstitute( meta.getDirectory() ), getTransMeta() );
@Override WebResult generateBody( HttpServletRequest request, HttpServletResponse response, boolean useXML ) throws KettleException, IOException { FileObject tempFile = KettleVFS.createTempFile( "export", ".zip", System.getProperty( "java.io.tmpdir" ) ); OutputStream out = KettleVFS.getOutputStream( tempFile, false ); IOUtils.copy( request.getInputStream(), out );
@Test public void testPDI12424ParametersFromMetaAreCopiedToTrans() throws KettleException, URISyntaxException, IOException { String testParam = "testParam"; String testParamValue = "testParamValue"; TransMeta mockTransMeta = mock( TransMeta.class ); when( mockTransMeta.listVariables() ).thenReturn( new String[] {} ); when( mockTransMeta.listParameters() ).thenReturn( new String[] { testParam } ); when( mockTransMeta.getParameterValue( testParam ) ).thenReturn( testParamValue ); FileObject ktr = KettleVFS.createTempFile( "parameters", ".ktr", "ram://" ); try ( OutputStream outputStream = ktr.getContent().getOutputStream( true ) ) { InputStream inputStream = new ByteArrayInputStream( "<transformation></transformation>".getBytes() ); IOUtils.copy( inputStream, outputStream ); } Trans trans = new Trans( mockTransMeta, null, null, null, ktr.getURL().toURI().toString() ); assertEquals( testParamValue, trans.getParameterValue( testParam ) ); }
/** * 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 ); } }
/** * 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" * @param append * @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, boolean append ) 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, append ); 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 ); } }
if ( insertScript ) { tempFile = KettleVFS.createTempFile( "kettle", "shell.bat", System.getProperty( "java.io.tmpdir" ), this ); fileObject = createTemporaryShellFile( tempFile, realScript ); if ( insertScript ) { tempFile = KettleVFS.createTempFile( "kettle", "shell.bat", System.getProperty( "java.io.tmpdir" ), this ); fileObject = createTemporaryShellFile( tempFile, realScript ); tempFile = KettleVFS.createTempFile( "kettle", "shell", System.getProperty( "java.io.tmpdir" ), this ); fileObject = createTemporaryShellFile( tempFile, realScript );
@Test public void testEnforceProtPOnPut() throws Exception { FileObject file = KettleVFS.createTempFile( "FTPSConnectionTest_testEnforceProtPOnPut", KettleVFS.Suffix.TMP); file.createFile(); try { FTPSTestConnection connection = spy( new FTPSTestConnection( FTPSConnection.CONNECTION_TYPE_FTP_IMPLICIT_TLS_WITH_CRYPTED, "the.perfect.host", 2010, "warwickw", "julia", null ) ); connection.replies.put( "PWD", new Reply( Arrays.asList( "257 \"/la\" is current directory" ) ) ); connection.connect(); connection.uploadFile( file.getPublicURIString(), "uploaded-file" ); assertEquals( "buffer not set", "PBSZ 0\r\n", connection.commands.get( 0 ).toString() ); assertEquals( "data privacy not set", "PROT P\r\n", connection.commands.get( 1 ).toString() ); } finally { file.delete(); } }
FileObject tempFile = KettleVFS.createTempFile( "export", ".zip", System.getProperty( "java.io.tmpdir" ) ); outputStream = KettleVFS.getOutputStream( tempFile, false );
FileObject tempFile = KettleVFS.createTempFile( "transExport", KettleVFS.Suffix.ZIP, transMeta );
KettleVFS.createTempFile( "jobExport", ".zip", System.getProperty( "java.io.tmpdir" ), jobMeta );
/** * Extract a zip archive to a temp directory. * * @param archive Zip archive to extract * @return Directory the zip was extracted into * @throws IOException * @throws KettleFileException * @see DistributedCacheUtilImpl#extract(org.apache.commons.vfs.FileObject, org.apache.commons.vfs.FileObject) */ public FileObject extractToTemp( FileObject archive ) throws IOException, KettleFileException { if ( archive == null ) { throw new NullPointerException( "archive is required" ); } // Ask KettleVFS for a temporary file name without extension and use that as our temporary folder to extract into FileObject dest = KettleVFS.createTempFile( "", "", System.getProperty( "java.io.tmpdir" ) ); return extract( archive, dest ); }