private boolean getBackupFileFromFileSystem( String backupFileName ) throws KettleException { FileObject fileObject = getFileObjectFromKettleVFS( backupFileName ); try { return fileObject.exists(); } catch ( FileSystemException e ) { return false; } }
public boolean isProcessingNeeded( FileObject file, long lineNr, String filePart ) throws KettleException { try { return errorFile.exists(); } catch ( IOException e ) { throw new KettleException( e ); } }
private boolean checkContainsFile( String realSourceDirectoryOrFile, FileObject[] filelist, boolean isDirectory ) throws FileSystemException { boolean retval = false; for ( int i = 0; i < filelist.length; i++ ) { FileObject file = filelist[i]; if ( ( file.exists() && file.getType().equals( FileType.FILE ) ) ) { retval = true; } } return retval; }
/** * Creates a new root-location for the given repository and directory. * * @param repository the repository for which a location should be created. * @param backend the backend. * @throws ContentIOException if an error occured or the file did not point to a directory. */ public FileObjectContentLocation( final Repository repository, final FileObject backend ) throws ContentIOException { super( repository, backend ); boolean error; try { error = backend.exists() == false || backend.isFolder() == false; } catch ( FileSystemException e ) { throw new RuntimeException( e ); } if ( error ) { throw new ContentIOException( "The given backend-file is not a directory." ); } }
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 ); } }
/** * Creates a new location for the given parent and directory. * * @param parent the parent location. * @param backend the backend. * @throws ContentIOException if an error occured or the file did not point to a directory. */ public FileObjectContentLocation( final ContentLocation parent, final FileObject backend ) throws ContentIOException { super( parent, backend ); boolean error; try { error = backend.exists() == false || backend.isFolder() == false; } catch ( FileSystemException e ) { throw new RuntimeException( e ); } if ( error ) { throw new ContentIOException( "The given backend-file is not a directory." ); } }
public boolean isFileExists( String filename ) throws KettleException { try { return getFileObject( filename, getTransMeta() ).exists(); } catch ( Exception e ) { throw new KettleException( "Error opening new file : " + e.toString() ); } }
/** * Call {@link #copyFile(String, String)} method to create file backup * * @param fileObject * @throws IOException */ private String createOrGetFileBackup( FileObject fileObject ) throws IOException, KettleException { String backupFileName = filename + ".backup"; boolean isBackupFileExist = false; if ( fileObject.exists() ) { isBackupFileExist = createFileBackup( backupFileName ); } else { isBackupFileExist = getBackupFileFromFileSystem( backupFileName ); } return isBackupFileExist ? backupFileName : null; }
private static void throwsErrorOnFileNotFound( FileObject file ) throws KettleFileNotFoundException, FileSystemException { if ( file == null || !file.exists() ) { throw new KettleFileNotFoundException( "File not found", file.getName().getPath() ); } }
/** * Checks, whether an content entity with the given name exists in this content location. This method will report * invalid filenames as non-existent. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists( final String name ) { if ( RepositoryUtilities.isInvalidPathName( name ) ) { return false; } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); return child.exists(); } catch ( FileSystemException e ) { throw new RuntimeException( e ); } } }
public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { if ( ( data.dis != null ) && ( data.dis.size() > 0 ) ) { for ( DataInputStream is : data.dis ) { BaseStep.closeQuietly( is ); } } // remove temp files for ( int f = 0; f < data.files.size(); f++ ) { FileObject fileToDelete = data.files.get( f ); try { if ( fileToDelete != null && fileToDelete.exists() ) { fileToDelete.delete(); } } catch ( FileSystemException e ) { logError( e.getLocalizedMessage(), e ); } } super.dispose( smi, sdi ); }
public static boolean fileExists( String vfsFilename, VariableSpace space ) throws KettleFileException { FileObject fileObject = null; try { fileObject = getFileObject( vfsFilename, space ); return fileObject.exists(); } catch ( IOException e ) { throw new KettleFileException( e ); } finally { if ( fileObject != null ) { try { fileObject.close(); } catch ( Exception e ) { /* Ignore */ } } } }
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 ); } }
@Override public boolean exists( final String name, final RepositoryDirectoryInterface repositoryDirectory, final RepositoryObjectType objectType ) throws KettleException { try { FileObject fileObject = KettleVFS.getFileObject( calcFilename( repositoryDirectory, name, objectType.getExtension() ) ); return fileObject.exists(); } catch ( Exception e ) { throw new KettleException( e ); } }
@Test public void testOpenConnectionUseKey_2() throws Exception { when( fileObject.exists() ).thenReturn( true ); when( fileObject.getContent() ).thenReturn( fileContent ); when( fileContent.getSize() ).thenReturn( 1000L ); when( fileContent.getInputStream() ).thenReturn( new ByteArrayInputStream( new byte[] { 1, 2, 3, 4, 5 } ) ); when( variableSpace.environmentSubstitute( passPhrase ) ).thenReturn( passPhrase ); when( connection.authenticateWithPublicKey( eq( username ), Matchers.<char[]>any(), eq( passPhrase ) ) ).thenReturn( true ); SSHData.OpenConnection( server, port, username, null, true, keyFilePath, passPhrase, 0, variableSpace, null, 0, null, null ); verify( connection ).connect(); verify( connection ).authenticateWithPublicKey( eq( username ), Matchers.<char[]>any(), eq( passPhrase ) ); }
private ObjectId getObjectId( RepositoryDirectoryInterface repositoryDirectory, String name, String extension ) throws KettleException { try { String filename = calcFilename( repositoryDirectory, name, extension ); if ( !KettleVFS.getFileObject( filename ).exists() ) { return null; } // The ID is the filename relative to the base directory, including the file extension // return new StringObjectId( calcObjectId( repositoryDirectory, name, extension ) ); } catch ( Exception e ) { throw new KettleException( "Error finding ID for directory [" + repositoryDirectory + "] and name [" + name + "]", e ); } }
/** * Test that we can have some feedback on rule violations * * @throws KettleException */ @Test public void testExportAllRulesViolation() throws Exception { RepositoryExporter exporter = new RepositoryExporter( repository ); exporter.setImportRulesToValidate( getImportRules() ); List<ExportFeedback> feedback = exporter.exportAllObjectsWithFeedback( null, xmlFileName, root, RepositoryExporter.ExportType.ALL.toString() ); Assert.assertEquals( "Feedback contains all items recorded", 3, feedback.size() ); for ( ExportFeedback feed : feedback ) { if ( feed.isSimpleString() ) { continue; } Assert.assertEquals( "all items rejected: " + feed.toString(), ExportFeedback.Status.REJECTED, feed.getStatus() ); } Assert.assertTrue( "Export file is deleted", !fileObject.exists() ); }
public void setSecretKeyFromFile( String filename ) throws CryptoKeyException { FileObject file = null; try { file = KettleVFS.getFileObject( filename ); if ( !file.exists() ) { throw new CryptoException( BaseMessages.getString( PKG, "SymmetricCrypto.CanNotFindFile", file.getName() ) ); } byte[] KeyBytes = new byte[(int) file.getContent().getSize()]; setSecretKey( KeyBytes ); } catch ( Exception e ) { throw new CryptoKeyException( e ); } finally { if ( file != null ) { try { file.close(); } catch ( Exception e ) { /* Ignore */ } } } }
@Test public void getDatabaseId_ReturnsExactMatch_PriorToCaseInsensitiveMatch() throws Exception { final String exact = "databaseExactMatch"; final String similar = exact.toLowerCase(); assertNotSame( similar, exact ); DatabaseMeta db = saveDatabase( exact ); // simulate legacy repository - store a DB with a name different only in case DatabaseMeta another = new DatabaseMeta(); another.setName( similar ); FileObject fileObject = repository.getFileObject( another ); assertFalse( fileObject.exists() ); // just create it - enough for this case fileObject.createFile(); assertTrue( fileObject.exists() ); ObjectId id = this.repository.getDatabaseID( exact ); assertEquals( db.getObjectId(), id ); }