List of usage examples for org.apache.commons.vfs2 FileObject isWriteable
boolean isWriteable() throws FileSystemException;
From source file:ShowProperties.java
public static void main(String[] args) throws FileSystemException { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt"); return;/*from ww w . j av a2s .co m*/ } for (int i = 0; i < args.length; i++) { try { FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing: " + args[i]); FileObject file = mgr.resolveFile(args[i]); System.out.println("URL: " + file.getURL()); System.out.println("getName(): " + file.getName()); System.out.println("BaseName: " + file.getName().getBaseName()); System.out.println("Extension: " + file.getName().getExtension()); System.out.println("Path: " + file.getName().getPath()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > 5) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (FileSystemException ex) { ex.printStackTrace(); } } }
From source file:com.googlecode.vfsjfilechooser2.utils.VFSUtils.java
/** * Tells whether a file is writable//from w w w. j a va 2s . c o m * @param fileObject * @return whether a file is writable */ public static boolean canWrite(FileObject fileObject) { try { return fileObject.isWriteable(); } catch (FileSystemException ex) { return false; } }
From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java
@Test public void testTestSuccess() throws Exception { String rootPath = System.getProperty("java.io.tmpdir", "/tmp"); DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build(); DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator; FileObject fileObject = operatorImpl.getRootFileObject(); when(fileObject.exists()).thenReturn(true); when(fileObject.isWriteable()).thenReturn(true); Assert.assertTrue(operatorImpl.test()); }
From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java
@Test public void testDirNotWriteableTest() throws Exception { String rootPath = System.getProperty("java.io.tmpdir", "/tmp"); DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build(); DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator; FileObject fileObject = operatorImpl.getRootFileObject(); when(fileObject.exists()).thenReturn(true); when(fileObject.isWriteable()).thenReturn(false); try {//from ww w . ja v a 2 s . c o m Assert.assertTrue(operatorImpl.test()); Assert.fail(); } catch (PublishException e) { Assert.assertEquals(e.getMessage(), "error.output.notwrite"); } }
From source file:com.ewcms.publication.deploy.provider.DeployOperatorBaseTest.java
@Test public void testDirNotExistTest() throws Exception { String rootPath = System.getProperty("java.io.tmpdir", "/tmp"); DeployOperatorable operator = new DeployOperatorBaseImpl.Builder().setPath(rootPath).build(); DeployOperatorBaseImpl operatorImpl = (DeployOperatorBaseImpl) operator; FileObject fileObject = operatorImpl.getRootFileObject(); when(fileObject.exists()).thenReturn(false); when(fileObject.isWriteable()).thenReturn(true); try {/* w ww .ja va 2 s. c o m*/ Assert.assertTrue(operatorImpl.test()); Assert.fail(); } catch (PublishException e) { Assert.assertEquals(e.getMessage(), "error.output.nodir"); } }
From source file:com.ewcms.publication.deploy.provider.DeployOperatorBase.java
@Override public boolean test() throws PublishException { FileObject root = null; try {/* w ww. jav a 2 s . c om*/ root = getRootFileObject(); } catch (FileSystemException e) { logger.error("Test is fail:{}", e.toString()); throw new PublishException("error.output.notconnect"); } try { if (!root.exists()) { throw new PublishException("error.output.nodir"); } if (!root.isWriteable()) { throw new PublishException("error.output.notwrite"); } root.close(); return true; } catch (FileSystemException e) { logger.error("Test is fail:{}", e.toString()); return false; } }
From source file:org.apache.accumulo.start.classloader.vfs.providers.ReadOnlyHdfsFileProviderTest.java
@Test public void testIsWritable() throws Exception { FileObject fo = manager.resolveFile(TEST_DIR1); Assert.assertNotNull(fo);/*from w w w . j av a 2s. co m*/ Assert.assertFalse(fo.exists()); // Create the test file FileObject file = createTestFile(hdfs); Assert.assertFalse(file.isWriteable()); }
From source file:org.apache.commons.vfs2.example.ShowProperties.java
public static void main(final String[] args) { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt"); return;/*from w ww .ja v a2s. c om*/ } for (final String arg : args) { try { final FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing: " + arg); final FileObject file = mgr.resolveFile(arg); System.out.println("URL: " + file.getURL()); System.out.println("getName(): " + file.getName()); System.out.println("BaseName: " + file.getName().getBaseName()); System.out.println("Extension: " + file.getName().getExtension()); System.out.println("Path: " + file.getName().getPath()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { final FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > SHOW_MAX) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (final FileSystemException ex) { ex.printStackTrace(); } } }
From source file:org.clever.Common.Storage.VirtualFileSystem.java
/** * This method lists contents of a file or folder * @param file//from www . j a va2 s. c o m * @return * @throws FileSystemException */ public String ls(FileObject file) throws FileSystemException { String str = "Contents of " + file.getName() + "\n"; if (file.exists()) { if (file.getType().equals(FileType.FILE)) { str = str + "Size: " + file.getContent().getSize() + " bytes\n" + "Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime())) + "\n" + "Readable: " + file.isReadable() + "\n" + "Writeable: " + file.isWriteable() + "\n"; return str; } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); str = str = "Directory with " + children.length + " files \n" + "Readable: " + file.isReadable() + "\n" + "Writeable: " + file.isWriteable() + "\n\n"; //str=str+"Last modified: " +DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))+"\n" ; for (int i = 0; i < children.length; i++) { str = str + children[i].getName().getBaseName() + "\n"; } } } else { str = str + "The file does not exist"; } return str; }
From source file:org.datacleaner.user.DataCleanerHome.java
private static boolean isWriteable(FileObject candidate) throws FileSystemException { if (candidate == null) { return false; }// w ww . j a va 2 s . c o m if (!candidate.isWriteable()) { return false; } // check with java.nio.Files.isWriteable() - is more detailed in it's // check final File file = VFSUtils.toFile(candidate); final Path path = file.toPath(); return Files.isWritable(path); }