Java Code Examples for org.pentaho.di.core.vfs.KettleVFS#createTempFile()
The following examples show how to use
org.pentaho.di.core.vfs.KettleVFS#createTempFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegisterPackageServlet.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Copy contents of <code>inputStream</code> to <code>directory</code>. Expecting zip file. * @param inputStream zip file input stream. * @param directory local destination directory. * @return copied file path. * @throws KettleException */ protected String copyRequestToDirectory( InputStream inputStream, String directory ) throws KettleException { String copiedFilePath; try { FileObject foDirectory = KettleVFS.getFileObject( directory ); if ( !foDirectory.exists() ) { foDirectory.createFolder(); } FileObject tempZipFile = KettleVFS.createTempFile( "export", ".zip", directory ); OutputStream outputStream = KettleVFS.getOutputStream( tempZipFile, false ); copyAndClose( inputStream, outputStream ); copiedFilePath = tempZipFile.getName().getPath(); } catch ( IOException ioe ) { throw new KettleException( BaseMessages.getString( PKG, "RegisterPackageServlet.Exception.CopyRequest", directory ), ioe ); } return copiedFilePath; }
Example 2
Source File: JobEntryTalendJobExec.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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()] ); }
Example 3
Source File: FTPSConnectionTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@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(); } }
Example 4
Source File: TransTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@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 ) ); }
Example 5
Source File: LogWriter.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * 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 ); } }
Example 6
Source File: LogWriter.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * 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 ); } }
Example 7
Source File: DistributedCacheUtilImpl.java From pentaho-hadoop-shims with Apache License 2.0 | 5 votes |
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 ); }
Example 8
Source File: ResultFileTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testGetRow() throws KettleFileException, FileSystemException { File tempDir = new File( new TemporaryFolder().toString() ); FileObject tempFile = KettleVFS.createTempFile( "prefix", "suffix", tempDir.toString() ); Date timeBeforeFile = Calendar.getInstance().getTime(); ResultFile resultFile = new ResultFile( ResultFile.FILE_TYPE_GENERAL, tempFile, "myOriginParent", "myOrigin" ); Date timeAfterFile = Calendar.getInstance().getTime(); assertNotNull( resultFile ); RowMetaInterface rm = resultFile.getRow().getRowMeta(); assertEquals( 7, rm.getValueMetaList().size() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 0 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 1 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 2 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 3 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 4 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 5 ).getType() ); assertEquals( ValueMetaInterface.TYPE_DATE, rm.getValueMeta( 6 ).getType() ); assertEquals( ResultFile.FILE_TYPE_GENERAL, resultFile.getType() ); assertEquals( "myOrigin", resultFile.getOrigin() ); assertEquals( "myOriginParent", resultFile.getOriginParent() ); assertTrue( "ResultFile timestamp is created in the expected window", timeBeforeFile.compareTo( resultFile.getTimestamp() ) <= 0 && timeAfterFile.compareTo( resultFile.getTimestamp() ) >= 0 ); tempFile.delete(); tempDir.delete(); }