Example usage for org.apache.commons.vfs2 FileObject canRenameTo

List of usage examples for org.apache.commons.vfs2 FileObject canRenameTo

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject canRenameTo.

Prototype

boolean canRenameTo(FileObject newfile);

Source Link

Document

Queries the file if it is possible to rename it to newfile.

Usage

From source file:org.apache.accumulo.start.classloader.vfs.providers.ReadOnlyHdfsFileProviderTest.java

@Test(expected = UnsupportedOperationException.class)
public void testCanRenameTo() throws Exception {
    FileObject fo = createTestFile(this.hdfs);
    Assert.assertNotNull(fo);//from   w w w . j  a  v a 2  s .c om
    fo.canRenameTo(fo);
}

From source file:org.pentaho.vfs.ui.VfsBrowser.java

public boolean renameItem(TreeItem ti, String newName) throws FileSystemException {
    FileObject file = (FileObject) ti.getData();
    FileObject newFileObject = file.getParent().resolveFile(newName);

    if (file.canRenameTo(newFileObject)) {
        if (!newFileObject.exists()) {
            newFileObject.createFile();// www. j  a  va 2 s. co  m
        } else {
            return false;
        }
        file.moveTo(newFileObject);
        ti.setText(newName);
        ti.setData(newFileObject);
        return true;
    } else {
        return false;
    }

}