Package org.apache.commons.vfs2

Examples of org.apache.commons.vfs2.FileObject


  }

  public void testLargeFile() throws Exception {
    File realFile = new File(largeFilePath + largeFileName + ".tar.gz");

    FileObject file = manager.resolveFile("tgz:file://" + realFile.getCanonicalPath() + "!/");

    assertNotNull(file);
    List<FileObject> files = Arrays.asList(file.getChildren());

    assertNotNull(files);
    assertEquals(1, files.size());
    FileObject f = files.get(0);

    assertTrue("Expected file not found: " + largeFileName + ".txt",
        f.getName().getBaseName().equals(largeFileName + ".txt"));
  }
View Full Code Here


    fileCheck(expectedFiles, "tar:file://c:/temp/data/data/data-small.tar");
  } */

  protected void fileCheck(String[] expectedFiles, String tarFile) throws Exception {
    assertNotNull(manager);
    FileObject file = manager.resolveFile(tarFile);

    assertNotNull(file);
    List<FileObject> files = Arrays.asList(file.getChildren());

    assertNotNull(files);
    for(int i=0; i < expectedFiles.length; ++i) {
      String expectedFile = expectedFiles[i];
      assertTrue("Expected file not found: " + expectedFile, fileExists(expectedFile, files));
View Full Code Here

   * @return
   */
  protected boolean fileExists(String expectedFile, List<FileObject> files) {
    Iterator<FileObject> iter = files.iterator();
    while (iter.hasNext()) {
      FileObject file = iter.next();
      if(file.getName().getBaseName().equals(expectedFile)) {
        return true;
      }
    }

    return false;
View Full Code Here

    public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
    {
        // Locate the base Tar file
        final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tar").getAbsolutePath();
        String uri = "tar:file:" + tarFilePath + "!/test.tar";
        final FileObject tarFile = manager.resolveFile(uri);

        // Now build the nested file system
        final FileObject nestedFS = manager.createFileSystem(tarFile);
        return nestedFS.resolveFile("/");
    }
View Full Code Here

    VFSVolume vfsVolume = (VFSVolume) last;
    boolean oldNumbering = !archive.getMainHeader().isNewNumbering()
        || archive.isOldFormat();
    String nextName = VolumeHelper.nextVolumeName(vfsVolume.getFile()
        .getName().getBaseName(), oldNumbering);
    FileObject nextVolumeFile = firstVolume.getParent().resolveFile(
        nextName);

    return new VFSVolume(archive, nextVolumeFile);
  }
View Full Code Here

        if (cmd.length < 2)
        {
            throw new Exception("USAGE: rm <path>");
        }

        final FileObject file = mgr.resolveFile(cwd, cmd[1]);
        file.delete(Selectors.SELECT_SELF);
    }
View Full Code Here

        if (cmd.length < 3)
        {
            throw new Exception("USAGE: cp <src> <dest>");
        }

        final FileObject src = mgr.resolveFile(cwd, cmd[1]);
        FileObject dest = mgr.resolveFile(cwd, cmd[2]);
        if (dest.exists() && dest.getType() == FileType.FOLDER)
        {
            dest = dest.resolveFile(src.getName().getBaseName());
        }

        dest.copyFrom(src, Selectors.SELECT_ALL);
    }
View Full Code Here

        {
            throw new Exception("USAGE: cat <path>");
        }

        // Locate the file
        final FileObject file = mgr.resolveFile(cwd, cmd[1]);

        // Dump the contents to System.out
        FileUtil.writeContent(file, System.out);
        System.out.println();
    }
View Full Code Here

        {
            path = System.getProperty("user.home");
        }

        // Locate and validate the folder
        FileObject tmp = mgr.resolveFile(cwd, path);
        if (tmp.exists())
        {
            cwd = tmp;
        }
        else
        {
            System.out.println("Folder does not exist: " + tmp.getName());
        }
        System.out.println("Current folder is " + cwd.getName());
    }
View Full Code Here

        else
        {
            recursive = false;
        }

        final FileObject file;
        if (cmd.length > pos)
        {
            file = mgr.resolveFile(cwd, cmd[pos]);
        }
        else
        {
            file = cwd;
        }

        if (file.getType() == FileType.FOLDER)
        {
            // List the contents
            System.out.println("Contents of " + file.getName());
            listChildren(file, recursive, "");
        }
        else
        {
            // Stat the file
            System.out.println(file.getName());
            final FileContent content = file.getContent();
            System.out.println("Size: " + content.getSize() + " bytes.");
            final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
            final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
            System.out.println("Last modified: " + lastMod);
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs2.FileObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.