List of usage examples for org.apache.commons.vfs FileObject close
public void close() throws FileSystemException;
From source file:org.openbi.kettle.plugins.avrooutput.AvroOutput.java
private void createParentFolder(String filename) throws Exception { // Check for parent folder FileObject parentfolder = null; try {/* www.jav a 2 s . com*/ // Get parent folder parentfolder = getFileObject(filename).getParent(); if (parentfolder.exists()) { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderExist", parentfolder.getName())); } } else { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderNotExist", parentfolder.getName())); } if (meta.getCreateParentFolder()) { parentfolder.createFolder(); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderCreated", parentfolder.getName())); } } else { throw new KettleException(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderNotExistCreateIt", parentfolder.getName(), filename)); } } } finally { if (parentfolder != null) { try { parentfolder.close(); } catch (Exception ex) { // Ignore } } } }
From source file:org.openbi.kettle.plugins.parquetoutput.ParquetOutput.java
private void createParentFolder(String filename) throws Exception { // Check for parent folder FileObject parentfolder = null; FileObject schemaParentFolder = null; try {/* ww w . j a v a2s . c om*/ // Get parent folder parentfolder = getFileObject(filename).getParent(); if (parentfolder.exists()) { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderExist", parentfolder.getName())); } } else { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderNotExist", parentfolder.getName())); } if (meta.isCreateParentFolder()) { parentfolder.createFolder(); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderCreated", parentfolder.getName())); } } else { throw new KettleException(BaseMessages.getString(PKG, "AvroOutput.Log.ParentFolderNotExistCreateIt", parentfolder.getName(), filename)); } } } finally { if (parentfolder != null) { try { parentfolder.close(); } catch (Exception ex) { // Ignore } } } }
From source file:org.openbi.kettle.plugins.tableauDataExtract.TDEOutput.java
private void createParentFolder(String filename) throws Exception { // Check for parent folder FileObject parentfolder = null; try {/*from w w w . j a va2s . c o m*/ // Get parent folder parentfolder = KettleVFS.getFileObject(filename).getParent(); if (parentfolder.exists()) { if (isDetailed()) logDetailed( BaseMessages.getString(PKG, "TDEOutput.Log.ParentFolderExist", parentfolder.getName())); } else { if (isDetailed()) logDetailed(BaseMessages.getString(PKG, "TDEOutput.Log.ParentFolderNotExist", parentfolder.getName())); if (meta.isCreateParentFolder()) { parentfolder.createFolder(); if (isDetailed()) logDetailed(BaseMessages.getString(PKG, "TDEOutput.Log.ParentFolderCreated", parentfolder.getName())); } else { throw new KettleException(BaseMessages.getString(PKG, "TDEOutput.Log.ParentFolderNotExistCreateIt", parentfolder.getName(), filename)); } } } finally { if (parentfolder != null) { try { parentfolder.close(); } catch (Exception ex) { } ; } } }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Long ChecksumCRC32(ValueMetaInterface metaA, Object dataA) { long checksum = 0; FileObject file = null; try {/*from w w w.j a v a 2s . c o m*/ file = OpenDESIGNERVFS.getFileObject(dataA.toString()); CheckedInputStream cis = null; // Computer CRC32 checksum cis = new CheckedInputStream((FileInputStream) ((LocalFile) file).getInputStream(), new CRC32()); byte[] buf = new byte[128]; while (cis.read(buf) >= 0) { } checksum = cis.getChecksum().getValue(); } catch (Exception e) { } finally { if (file != null) try { file.close(); } catch (Exception e) { } ; } return checksum; }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Long ChecksumAdler32(ValueMetaInterface metaA, Object dataA) { long checksum = 0; FileObject file = null; try {/* www. j a va2 s . c o m*/ file = OpenDESIGNERVFS.getFileObject(dataA.toString()); CheckedInputStream cis = null; // Computer Adler-32 checksum cis = new CheckedInputStream((FileInputStream) ((LocalFile) file).getInputStream(), new Adler32()); byte[] buf = new byte[128]; while (cis.read(buf) >= 0) { } checksum = cis.getChecksum().getValue(); } catch (Exception e) { //throw new Exception(e); } finally { if (file != null) try { file.close(); } catch (Exception e) { } ; } return checksum; }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Object loadFileContentInBinary(ValueMetaInterface metaA, Object dataA) throws OpenDESIGNERValueException { if (dataA == null) return null; FileObject file = null; FileInputStream fis = null;//from w ww .ja va 2 s .c om try { file = OpenDESIGNERVFS.getFileObject(dataA.toString()); fis = (FileInputStream) ((LocalFile) file).getInputStream(); int fileSize = (int) file.getContent().getSize(); byte[] content = Const.createByteArray(fileSize); fis.read(content, 0, fileSize); return content; } catch (Exception e) { throw new OpenDESIGNERValueException(e); } finally { try { if (file != null) file.close(); if (fis != null) fis.close(); } catch (Exception e) { } ; } }
From source file:org.ow2.proactive.scripting.helper.filetransfer.driver.SFTP_VFS_Driver.java
public void getFile(String remotePath, String destFolderPath) throws Exception { connect();//from w w w. j a va 2 s. c om debug("Getting file " + remotePath + " to local folder " + destFolderPath); String fileName = (new File(remotePath).getName()); String localPath = destFolderPath + File.separator + fileName; // we first set strict key checking off FileSystemOptions fsOptions = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fsOptions, "no"); // now we create a new filesystem manager // the url is of form sftp://user:pass@host/remotepath/ String uri = "sftp://" + _user + ":" + _pass + "@" + _host + "/" + remotePath; // get file object representing the local file FileObject fo = fsManager.resolveFile(uri, fsOptions); // open input stream from the remote file BufferedInputStream is = new BufferedInputStream(fo.getContent().getInputStream()); // open output stream to local file OutputStream os = new BufferedOutputStream(new FileOutputStream(localPath)); int c; // do copying while ((c = is.read()) != -1) { os.write(c); } os.close(); is.close(); // close the file object fo.close(); debug("File copied " + remotePath + " to local folder " + destFolderPath); // NOTE: if you close the file system manager, you won't be able to // use VFS again in the same VM. If you wish to copy multiple files, // make the fsManager static, initialize it once, and close just // before exiting the process. // fsManager.close(); //System.out.println("Finished copying the file"); disconnect(); }
From source file:org.ow2.proactive.scripting.helper.filetransfer.driver.SFTP_VFS_Driver.java
public void putFile(String localPathFile, String remoteFolder) throws Exception { if (remoteFolder == "") remoteFolder = "."; debug("Putting file " + localPathFile + " to " + remoteFolder); //--Setup the SCP connection connect();//from ww w. j a v a 2 s . c o m //--Define paths // String localFolder = FileTransfertUtils.getFolderFromPathfile(localPathFile); String fileName = new File(localPathFile).getName(); // we first set strict key checking off FileSystemOptions fsOptions = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fsOptions, "no"); // now we create a new filesystem manager // the url is of form sftp://user:pass@host/remotepath/ String uri = "sftp://" + _user + ":" + _pass + "@" + _host + "/" + remoteFolder + "/" + fileName; // get file object representing the local file FileObject fo = fsManager.resolveFile(uri, fsOptions); fo.createFile(); OutputStream os = fo.getContent().getOutputStream(); BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(localPathFile))); int c; // do copying while ((c = is.read()) != -1) { os.write(c); } os.close(); is.close(); fo.close(); debug("File copied :" + localPathFile + " to " + remoteFolder); //--Logout and disconnect disconnect(); }
From source file:org.pentaho.di.core.database.Database.java
/** * Execute an SQL statement inside a file on the database connection (has to be open) * * @param sql/*from www . j a v a 2s . c o m*/ * The file that contains SQL to execute * @sendSinglestatement send one statement * @return a Result object indicating the number of lines read, deleted, inserted, updated, ... * @throws KettleDatabaseException * in case anything goes wrong. */ public Result execStatementsFromFile(String filename, boolean sendSinglestatement) throws KettleException { FileObject sqlFile = null; InputStream is = null; InputStreamReader bis = null; try { if (Const.isEmpty(filename)) { throw new KettleException("Filename is missing!"); } sqlFile = KettleVFS.getFileObject(filename); if (!sqlFile.exists()) { throw new KettleException("We can not find file [" + filename + "]!"); } is = KettleVFS.getInputStream(sqlFile); bis = new InputStreamReader(new BufferedInputStream(is, 500)); StringBuffer lineStringBuffer = new StringBuffer(256); lineStringBuffer.setLength(0); BufferedReader buff = new BufferedReader(bis); String sLine = null; String sql = Const.CR; while ((sLine = buff.readLine()) != null) { if (Const.isEmpty(sLine)) { sql = sql + Const.CR; } else { sql = sql + Const.CR + sLine; } } if (sendSinglestatement) { return execStatement(sql); } else { return execStatements(sql); } } catch (Exception e) { throw new KettleException(e); } finally { try { if (sqlFile != null) { sqlFile.close(); } if (is != null) { is.close(); } if (bis != null) { bis.close(); } } catch (Exception e) { // Ignore } } }
From source file:org.pentaho.di.core.fileinput.FileInputList.java
public static FileInputList createFolderList(VariableSpace space, String[] folderName, String[] folderRequired) { FileInputList fileInputList = new FileInputList(); // Replace possible environment variables... final String[] realfolder = space.environmentSubstitute(folderName); for (int i = 0; i < realfolder.length; i++) { final String onefile = realfolder[i]; final boolean onerequired = YES.equalsIgnoreCase(folderRequired[i]); final boolean subdirs = true; final FileTypeFilter filter = FileTypeFilter.ONLY_FOLDERS; if (Const.isEmpty(onefile)) { continue; }// w w w . j a va 2 s. c o m FileObject directoryFileObject = null; try { // Find all folder names in this directory // directoryFileObject = KettleVFS.getFileObject(onefile, space); if (directoryFileObject != null && directoryFileObject.getType() == FileType.FOLDER) // it's a directory { FileObject[] fileObjects = directoryFileObject.findFiles(new AllFileSelector() { @Override public boolean traverseDescendents(FileSelectInfo info) { return info.getDepth() == 0 || subdirs; } @Override public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); try { if (fileObject != null && filter.isFileTypeAllowed(fileObject.getType())) { return true; } return false; } catch (IOException ex) { // Upon error don't process the file. return false; } } }); if (fileObjects != null) { for (int j = 0; j < fileObjects.length; j++) { if (fileObjects[j].exists()) { fileInputList.addFile(fileObjects[j]); } } } if (Const.isEmpty(fileObjects)) { if (onerequired) { fileInputList.addNonAccessibleFile(directoryFileObject); } } // Sort the list: quicksort, only for regular files fileInputList.sortFiles(); } else { if (onerequired && !directoryFileObject.exists()) { fileInputList.addNonExistantFile(directoryFileObject); } } } catch (Exception e) { log.logError(Const.getStackTracker(e)); } finally { try { if (directoryFileObject != null) { directoryFileObject.close(); } directoryFileObject = null; } catch (Exception e) { // Ignore } } } return fileInputList; }