List of usage examples for org.apache.commons.vfs FileObject exists
public boolean exists() throws FileSystemException;
From source file:pt.webdetails.di.baserver.utils.repositoryPlugin.ui.ToolbarController.java
private boolean saveXMLFileToVfs(EngineMetaInterface meta) { Spoon spoon = this.getSpoon(); LogChannelInterface spoonLog = spoon.getLog(); Shell spoonShell = spoon.getShell(); if (spoonLog.isBasic()) { spoonLog.logBasic("Save file as..."); }//from w ww. j a va 2s .c o m VfsDialogFileInfo fileInfo = this.getLastOpenedFile(); FileObject rootFile = fileInfo.getRootFile(); FileObject initialFile = fileInfo.getInitialFile(); if (rootFile == null || initialFile == null) { return false; } String filename = null; FileObject selectedFile = spoon.getVfsFileChooserDialog(rootFile, initialFile).open(spoonShell, null, this.getConstants().getVfsScheme(), true, "Untitled", Const.STRING_TRANS_AND_JOB_FILTER_EXT, Const.getTransformationAndJobFilterNames(), VfsFileChooserDialog.VFS_DIALOG_SAVEAS); if (selectedFile != null) { filename = selectedFile.getName().getFriendlyURI(); } if (filename != null) { Collection<String> extensionMasks = new ArrayList<String>(); for (String composedExtension : meta.getFilterExtensions()) { // extension given by meta.getFilterExtensions may contain elements // with more than one extension mask separated by ';'. E.g. "*.ktr;*.kjb" String[] extensions = composedExtension.split(";"); for (String simpleExtension : extensions) { extensionMasks.add(simpleExtension); } } filename = this.addDefaultExtensionIfMissing(filename, extensionMasks, meta.getDefaultExtension()); // See if the file already exists... boolean overrideFile = true; try { FileObject f = KettleVFS.getFileObject(filename); if (f.exists()) { overrideFile = this.promptShouldOverrideFile(); } } catch (Exception e) { // TODO do we want to show an error dialog here? My first guess // is not, but we might. } if (overrideFile) { spoon.save(meta, filename, false); } } return false; }
From source file:r.base.Files.java
/** * Utility function to extract information about files on the user's file systems. * * @param context current call Context/*from w w w .j av a2 s .c o m*/ * @param paths the list of files for which to return information * @return list column-oriented table of file information * @throws FileSystemException */ @Primitive("file.info") public static ListVector fileInfo(@Current Context context, StringVector paths) throws FileSystemException { DoubleVector.Builder size = new DoubleVector.Builder(); LogicalVector.Builder isdir = new LogicalVector.Builder(); IntVector.Builder mode = (IntVector.Builder) new IntVector.Builder().setAttribute(Symbols.CLASS, new StringVector("octmode")); DoubleVector.Builder mtime = new DoubleVector.Builder(); StringVector.Builder exe = new StringVector.Builder(); for (String path : paths) { FileObject file = context.resolveFile(path); if (file.exists()) { if (file.getType() == FileType.FILE) { size.add((int) file.getContent().getSize()); } else { size.add(0); } isdir.add(file.getType() == FileType.FOLDER); mode.add(mode(file)); try { mtime.add(file.getContent().getLastModifiedTime()); } catch (Exception e) { mtime.add(0); } exe.add(file.getName().getBaseName().endsWith(".exe") ? "yes" : "no"); } else { size.add(IntVector.NA); isdir.add(IntVector.NA); mode.add(IntVector.NA); mtime.add(DoubleVector.NA); exe.add(StringVector.NA); } } return ListVector.newNamedBuilder().add("size", size).add("isdir", isdir).add("mode", mode) .add("mtime", mtime).add("ctime", mtime).add("atime", mtime).add("exe", exe).build(); }
From source file:r.base.Files.java
private static void delete(FileObject file, boolean recursive) throws FileSystemException { if (file.exists()) { if (file.getType() == FileType.FILE) { file.delete();//from ww w . j a va 2s . c o m } else if (file.getType() == FileType.FOLDER) { if (file.getChildren().length == 0) { file.delete(); } else if (recursive) { file.delete(); } } } }
From source file:r.base.Files.java
/** * Helper function to extract a zip entry to the given folder. *///w w w. j a v a2 s . co m private static void unzipExtract(ZipInputStream zin, ZipEntry entry, FileObject exdir, boolean junkpaths, boolean overwrite) throws IOException { if (junkpaths) { throw new EvalException("unzip(junpaths=false) not yet implemented"); } FileObject exfile = exdir.resolveFile(entry.getName()); if (exfile.exists() && !overwrite) { throw new EvalException("file to be extracted '%s' already exists", exfile.getName().getURI()); } OutputStream out = exfile.getContent().getOutputStream(); try { byte buffer[] = new byte[64 * 1024]; int bytesRead; while ((bytesRead = zin.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } } finally { out.close(); } }
From source file:unitTests.dataspaces.AbstractLimitingFileObjectTest.java
private void createRealFileChild() throws FileSystemException { realFile.createFolder();/*w w w . ja v a2s. c o m*/ final FileObject childFile = realFile.resolveFile(CHILD_NAME); childFile.createFile(); assertTrue(childFile.exists()); }
From source file:unitTests.dataspaces.VFSApplicationScratchSpaceImplTest.java
private void assertIsExistingEmptyDirectory(final String path) throws FileSystemException { final FileObject fPartialDS = fileSystemManager.resolveFile(path); assertTrue(fPartialDS.exists()); assertEquals(FileType.FOLDER, fPartialDS.getType()); assertEquals(0, fPartialDS.getChildren().length); }
From source file:unitTests.dataspaces.VFSFactoryTest.java
@Test public void testLocalFileProvider() throws Exception { FileObject fo = null; try {/*from w w w. j a va 2 s.c o m*/ fo = manager.resolveFile(testFile.getCanonicalPath()); assertTrue(fo.exists()); final InputStream ios = fo.getContent().getInputStream(); final BufferedReader reader = new BufferedReader(new InputStreamReader(ios)); assertEquals("test", reader.readLine()); } finally { if (fo != null) fo.close(); } }
From source file:unitTests.dataspaces.VFSMountManagerHelperTest.java
/** * Tests mounting only one valid FileSystem * @throws Exception//from w w w.ja v a2 s . co m */ @Test public void testMountOk() throws Exception { logger.info("*************** testMountOk"); String[] validUrls = server.getVFSRootURLs(); for (String validUrl : validUrls) { FileObject mounted = VFSMountManagerHelper.mount(validUrl); Assert.assertTrue(mounted.exists()); } }
From source file:unitTests.dataspaces.VFSMountManagerHelperTest.java
/** * Tests closing all FileSystems//from w w w .jav a 2 s . c o m * @throws Exception */ @Ignore("vfs close file system doesn't seem to work properly") @Test public void testCloseFileSystems() throws Exception { logger.info("*************** testCloseFileSystems"); String[] validUrls = server.getVFSRootURLs(); ArrayList<FileObject> fos = new ArrayList<FileObject>(); for (String validUrl : validUrls) { FileObject mounted = VFSMountManagerHelper.mount(validUrl); Assert.assertTrue(mounted.exists()); fos.add(mounted); } VFSMountManagerHelper.closeFileSystems(Arrays.asList(validUrls)); boolean onlyExceptions = true; for (FileObject closedFo : fos) { try { FileObject toto = closedFo.resolveFile("toto"); toto.createFile(); onlyExceptions = false; logger.error(toto.getURL() + " exists : " + toto.exists()); } catch (FileSystemException e) { // this should occur } } Assert.assertTrue("Only Exceptions received", onlyExceptions); }
From source file:unitTests.dataspaces.VFSNodeScratchSpaceImplTest.java
private void assertIsExistingEmptyDirectory(String path) throws FileSystemException { FileObject fPartialDS = fileSystemManager.resolveFile(path); assertTrue(fPartialDS.exists()); assertEquals(FileType.FOLDER, fPartialDS.getType()); assertEquals(0, fPartialDS.getChildren().length); }