Package org.jboss.virtual.plugins.context.file

Examples of org.jboss.virtual.plugins.context.file.FileSystemContext


    * @throws Exception for any error
    */
   public void testNotAnArchive() throws Exception
   {
      URL url = getResource("/vfs/context/jar/");
      FileSystemContext ctx = new FileSystemContext(url);

      // we just do basic sanity checks

      // valid archive

      VirtualFileHandler handler = ctx.getRoot().getChild("archive.jar");
      //assertTrue("is vfszip", "vfszip".equals(handler.toURL().getProtocol()));
      assertFalse("is leaf", handler.isLeaf());
      assertTrue("exists", handler.exists());
      assertNotNull("pathName not null", handler.getPathName());
      assertNotNull("name not null", handler.getName());
      assertNotNull("parent not null", handler.getParent());
      assertTrue("lastModified > 0", handler.getLastModified() > 0);
      assertTrue("size > 0", handler.getSize() > 0);
      assertNotNull("VF not null", handler.getVirtualFile());
      assertFalse("hasBeenModified == false", handler.hasBeenModified());
      assertFalse("hidden == false", handler.isHidden());
      assertFalse("nested == false", handler.isNested());
      assertNotNull("toURI not null", handler.toURI());
      assertNotNull("toURL not null", handler.toURL());
      assertNotNull("toVfsUrl not null", handler.toVfsUrl());

      ByteArrayOutputStream memOut = new ByteArrayOutputStream();
      VFSUtils.copyStreamAndClose(handler.openStream(), memOut);
      assertTrue("read archive content", memOut.size() == handler.getSize());

      // invalid archive

      handler = ctx.getRoot().getChild("notanarchive.jar");
      //assertTrue("is leaf", handler.isLeaf());
      assertTrue("exists", handler.exists());
      assertTrue("lastModified > 0", handler.getLastModified() > 0);
      assertNotNull("pathName not null", handler.getPathName());
      assertNotNull("name not null", handler.getName());
View Full Code Here


   }
  
   protected VFSContext getVFSContext(String name) throws Exception
   {
      URL url = getRootResource(name);
      return new FileSystemContext(url);
   }
View Full Code Here

    * @throws Exception for any error
    */
   public void testCustomRealURL() throws Exception
   {
      URL url = getResource("/vfs/context/jar/");
      FileSystemContext ctx = new FileSystemContext(url);

      // valid archive
      VirtualFileHandler root = ctx.getRoot();
      assertEquals("Context Real URL", url.toExternalForm(), root.getRealURL().toExternalForm());
      String jarName = "archive.jar";
      VirtualFileHandler archive = root.getChild(jarName);
      assertEquals("Child Real URL", "jar:" + url.toExternalForm() + jarName + "!/", archive.getRealURL().toExternalForm());

      url = getResource("/vfs/test/");
      ctx = new FileSystemContext(url);
      root = ctx.getRoot();

      jarName = "level1.zip";
      archive = root.getChild(jarName);
      String nestedName = "level2.zip";
      VirtualFileHandler nested = archive.getChild(nestedName);
View Full Code Here

      //create guid dir
      File guidDir = createTempDirectory(getTempDirectory(), GUID.asString());
      // unpack handler
      File copy = copy(guidDir, handler);
      // create new handler
      FileSystemContext fileSystemContext = new FileSystemContext(copy);
      VirtualFileHandler newHandler = fileSystemContext.getRoot();
      VirtualFileHandler parent = handler.getParent();
      if (parent != null && replaceOldHandler(parent, handler, newHandler))
         parent.replaceChild(handler, newHandler);

      return newHandler.getVirtualFile();
View Full Code Here

      File copy = copy(guidDir, handler);

      String path = handler.getPathName();
      VFSContext oldVFSContext = handler.getVFSContext();
      // create new handler
      FileSystemContext fileSystemContext = new TempContext(copy, oldVFSContext, path);

      // merge old options
      Options newOptions = fileSystemContext.getOptions();
      if (newOptions != null) // shouldn't be null, but we check anyway
      {
         Options oldOptions = oldVFSContext.getOptions();
         if (oldOptions != null && oldOptions.size() > 0)
            newOptions.merge(oldOptions);

         newOptions.addOption(VFSUtils.IS_TEMP_FILE, Boolean.TRUE);
         // save old handler
         newOptions.addOption(VirtualFileHandler.class.getName(), handler);
      }

      VirtualFileHandler newHandler = fileSystemContext.getRoot();
      oldVFSContext.addTempInfo(new BasicTempInfo(path, copy, newHandler));

      VirtualFileHandler parent = handler.getParent();
      if (parent != null && replaceOldHandler(parent, handler, newHandler))
         parent.replaceChild(handler, newHandler);
View Full Code Here

TOP

Related Classes of org.jboss.virtual.plugins.context.file.FileSystemContext

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.