List of usage examples for org.apache.commons.vfs2 FileObject delete
boolean delete() throws FileSystemException;
From source file:org.pentaho.di.core.ResultFileTest.java
@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);/* w w w. ja va 2s. c o m*/ 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(); }
From source file:org.pentaho.di.job.entries.checkdbconnection.JobEntryCheckDbConnectionsIT.java
@After public void cleanup() { try {/* w w w . ja v a 2s. c o m*/ FileObject dbFile = KettleVFS.getFileObject(H2_DATABASE + ".h2.db"); if (dbFile.exists()) { System.out.println("deleting file"); dbFile.delete(); } } catch (KettleFileException | FileSystemException ignored) { // Ignore, we tried cleaning up } }
From source file:org.pentaho.di.job.entries.ftpsget.JobEntryFTPSGetIT.java
@Test public void downloadFile_WhenDestinationIsSetViaVariable() throws Exception { final String myVar = "my-var"; final String expectedDownloadedFilePath = ramDir + "/" + FtpsServer.SAMPLE_FILE; JobEntryFTPSGet job = createCommonJob(); job.setVariable(myVar, ramDir);/*from w w w . j a va2s . c o m*/ job.setTargetDirectory(String.format("${%s}", myVar)); FileObject downloaded = KettleVFS.getFileObject(expectedDownloadedFilePath); assertFalse(downloaded.exists()); try { job.execute(new Result(), 1); downloaded = KettleVFS.getFileObject(expectedDownloadedFilePath); assertTrue(downloaded.exists()); } finally { downloaded.delete(); } }
From source file:org.pentaho.di.job.entries.ftpsget.JobEntryFTPSGetIT.java
@Test public void downloadFile_WhenDestinationIsSetDirectly() throws Exception { JobEntryFTPSGet job = createCommonJob(); job.setTargetDirectory(ramDir);//w w w .j ava2s . c o m FileObject downloaded = KettleVFS.getFileObject(ramDir + "/" + FtpsServer.SAMPLE_FILE); assertFalse(downloaded.exists()); try { job.execute(new Result(), 1); downloaded = KettleVFS.getFileObject(ramDir + "/" + FtpsServer.SAMPLE_FILE); assertTrue(downloaded.exists()); } finally { downloaded.delete(); } }
From source file:org.pentaho.di.job.entries.googledrive.JobEntryGoogleDriveExport.java
protected static void exportFile(Drive driveService, File driveFile, FileObject targetFile, GoogleDriveExportFormat exportMapping) throws KettleException { Exception savedException = null; if (exportMapping != null) { FileObject tempFile = KettleVFS.createTempFile(JobEntryGoogleDriveExport.class.getSimpleName(), ".tmp", System.getProperty("java.io.tmpdir")); try {/* ww w . java2s . c o m*/ OutputStream fos = tempFile.getContent().getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(fos); try { driveService.files().export(driveFile.getId(), exportMapping.getMimeType()) .executeMediaAndDownloadTo(bos); } catch (IOException e) { // Throw this later, we want to close the output stream first savedException = new KettleException( BaseMessages.getString(PKG, "GoogleDriveExport.Error.ExportingFile"), e); } try { bos.close(); } catch (IOException ignore) { // Ignore } try { fos.close(); } catch (IOException ignore) { // Ignore } } catch (IOException e) { savedException = new KettleException( BaseMessages.getString(PKG, "GoogleDriveExport.Error.ExportingFile"), e); } if (tempFile != null) { try { targetFile.copyFrom(tempFile, Selectors.SELECT_SELF); } catch (FileSystemException e) { savedException = new KettleException( BaseMessages.getString(PKG, "GoogleDriveExport.Error.MovingFileFromTemp"), e); } } if (savedException != null) { try { if (targetFile.exists()) { targetFile.delete(); } } catch (FileSystemException ignore) { // Ignore, couldn't delete a bad output file } throw new KettleException(savedException); } } }
From source file:org.pentaho.di.job.entries.sftp.JobEntrySFTPIT.java
@Test public void getFile_WhenDestinationIsSetViaVariable() throws Exception { final String localDir = TestUtils.createTempDir(); KettleVFS.getFileObject(localDir).createFolder(); final String myVar = "my-var"; final String sftpDir = "job-entry-sftp-test"; final String fileName = "file.txt"; uploadFile(sftpDir, fileName);/*from www.j a va 2 s.co m*/ JobEntrySFTP job = new JobEntrySFTP(); job.setVariable(myVar, localDir); Job parent = mock(Job.class); when(parent.isStopped()).thenReturn(false); job.setParentJob(parent); job.setLogLevel(LogLevel.NOTHING); job.setUserName(server.getUsername()); job.setPassword(server.getPassword()); job.setServerName("localhost"); job.setServerPort(Integer.toString(server.getPort())); job.setScpDirectory(sftpDir); job.setTargetDirectory(String.format("${%s}", myVar)); job.execute(new Result(), 1); FileObject downloaded = KettleVFS.getFileObject(localDir + "/" + fileName); assertTrue(downloaded.exists()); downloaded.delete(); }
From source file:org.pentaho.di.plugins.fileopensave.providers.vfs.VFSFileProvider.java
/** * @param files//w ww . ja va 2 s . c o m * @return */ public List<VFSFile> delete(List<VFSFile> files) { List<VFSFile> deletedFiles = new ArrayList<>(); for (VFSFile file : files) { try { FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection())); if (fileObject.delete()) { deletedFiles.add(file); } } catch (KettleFileException | FileSystemException kfe) { // Ignore don't add } } return deletedFiles; }
From source file:org.pentaho.di.plugins.fileopensave.providers.vfs.VFSFileProvider.java
/** * @param file// www . j a v a2s. co m * @param newPath * @param overwrite * @return */ private VFSFile doMove(VFSFile file, String newPath, Boolean overwrite) { try { FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection())); FileObject renameObject = KettleVFS.getFileObject(newPath, new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection())); if (overwrite) { if (renameObject.exists()) { renameObject.delete(); } } fileObject.moveTo(renameObject); if (file instanceof VFSDirectory) { return VFSDirectory.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection()); } else { return VFSFile.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection()); } } catch (KettleFileException | FileSystemException e) { return null; } }
From source file:org.pentaho.di.resource.ResourceDefinitionHelper.java
public static void purge(FileObject tempFile) { if (!KEEP_EXPORTED_FILE && tempFile != null) { try {//from ww w . j a v a 2s. co m tempFile.delete(); } catch (Exception e) { // pretend nothing happened } } }
From source file:org.pentaho.di.trans.steps.textfileoutput.TextFileOutputSplittingIT.java
@After public void tearDown() throws Exception { transMeta = null;/*from w w w. j ava2s .co m*/ FileObject folder = getFolder(); for (FileObject fileObject : folder.getChildren()) { fileObject.delete(); } }