當前位置: 首頁>>代碼示例>>Java>>正文


Java VFSClassLoader類代碼示例

本文整理匯總了Java中org.apache.commons.vfs2.impl.VFSClassLoader的典型用法代碼示例。如果您正苦於以下問題:Java VFSClassLoader類的具體用法?Java VFSClassLoader怎麽用?Java VFSClassLoader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VFSClassLoader類屬於org.apache.commons.vfs2.impl包,在下文中一共展示了VFSClassLoader類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createClassLoader

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
/**
 * Creates the classloader to use when testing.
 */
private VFSClassLoader createClassLoader() throws FileSystemException
{
    FileObject file = getBaseFolder();
    final VFSClassLoader loader =
        new VFSClassLoader(file , getManager());
    return loader;
}
 
開發者ID:wso2,項目名稱:wso2-commons-vfs,代碼行數:11,代碼來源:VfsClassLoaderTests.java

示例2: testLoadClass

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
/**
 * Tests loading a class.
 */
public void testLoadClass() throws Exception
{
    final VFSClassLoader loader = createClassLoader();

    final Class<?> testClass = loader.loadClass("code.ClassToLoad");
    final Package pack = testClass.getPackage();
    assertEquals("code", pack.getName());
    verifyPackage(pack, false);

    final Object testObject = testClass.newInstance();
    assertEquals("**PRIVATE**", testObject.toString());
}
 
開發者ID:wso2,項目名稱:wso2-commons-vfs,代碼行數:16,代碼來源:VfsClassLoaderTests.java

示例3: testLoadResource

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
/**
 * Tests loading a resource.
 */
public void testLoadResource() throws Exception
{
    final VFSClassLoader loader = createClassLoader();

    final URL resource = loader.getResource("read-tests/file1.txt");

    assertNotNull(resource);
    final URLConnection urlCon = resource.openConnection();
    assertSameURLContent(FILE1_CONTENT, urlCon);
}
 
開發者ID:wso2,項目名稱:wso2-commons-vfs,代碼行數:14,代碼來源:VfsClassLoaderTests.java

示例4: testSealing

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
/**
 * Tests package sealing.
 */
public void testSealing() throws Exception
{
    final VFSClassLoader loader = createClassLoader();
    final Class<?> testClass = loader.loadClass("code.sealed.AnotherClass");
    final Package pack = testClass.getPackage();
    assertEquals("code.sealed", pack.getName());
    verifyPackage(pack, true);
}
 
開發者ID:wso2,項目名稱:wso2-commons-vfs,代碼行數:12,代碼來源:VfsClassLoaderTests.java

示例5: initClassLoader

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
public static void initClassLoader()
		throws MalformedURLException {
	synchronized (MUTEX) {
		if (classLoaderInitialized) {
			return;
		}
		final ClassLoader classLoader = FeatureDataUtils.class.getClassLoader();
		LOGGER.info("Generating patched classloader");
		if (classLoader instanceof VFSClassLoader) {
			final VFSClassLoader cl = (VFSClassLoader) classLoader;
			final FileObject[] fileObjs = cl.getFileObjects();
			final URL[] fileUrls = new URL[fileObjs.length];
			for (int i = 0; i < fileObjs.length; i++) {
				fileUrls[i] = new URL(
						fileObjs[i].toString());
			}
			final ClassLoader urlCL = java.security.AccessController
					.doPrivileged(new java.security.PrivilegedAction<URLClassLoader>() {
						@Override
						public URLClassLoader run() {
							final URLClassLoader ucl = new URLClassLoader(
									fileUrls,
									cl);
							return ucl;
						}
					});
			GeoTools.addClassLoader(urlCL);

		}
		classLoaderInitialized = true;
	}
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:33,代碼來源:FeatureDataUtils.java

示例6: initialize

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
@Override
public void initialize(Context context) {
  super.initialize(context);
  if(context != null) {

    Optional<Object> optional = context.getCapability(STELLAR_CONFIG, false);
    if (optional.isPresent()) {
      Map<String, Object> stellarConfig = (Map<String, Object>) optional.get();
      if(LOG.isDebugEnabled()) {
        LOG.debug("Setting up classloader using the following config: {}", stellarConfig);
      }

      include(STELLAR_SEARCH_INCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
      exclude(STELLAR_SEARCH_EXCLUDES_KEY.get(stellarConfig, String.class).split(STELLAR_SEARCH_DELIMS));
      Optional<ClassLoader> vfsLoader = Optional.empty();
      try {
        vfsLoader = VFSClassloaderUtil.configureClassloader(STELLAR_VFS_PATHS.get(stellarConfig, String.class));
        if(vfsLoader.isPresent()) {
          LOG.debug("CLASSLOADER LOADED WITH: {}", STELLAR_VFS_PATHS.get(stellarConfig, String.class));
          if(LOG.isDebugEnabled()) {
            for (FileObject fo : ((VFSClassLoader) vfsLoader.get()).getFileObjects()) {
              LOG.error("{} - {}", fo.getURL(), fo.exists());
            }
          }
          classLoaders(vfsLoader.get());
        }
      } catch (FileSystemException e) {
        LOG.error("Unable to process filesystem: {}", e.getMessage(), e);
      }
    }
    else {
      LOG.info("No stellar config set; I'm reverting to the context classpath with no restrictions.");
      if(LOG.isDebugEnabled()) {
        try {
          throw new IllegalStateException("No config set, stacktrace follows.");
        } catch (IllegalStateException ise) {
          LOG.error(ise.getMessage(), ise);
        }
      }
    }
  }
  else {
    throw new IllegalStateException("CONTEXT IS NULL!");
  }
}
 
開發者ID:apache,項目名稱:metron,代碼行數:46,代碼來源:ClasspathFunctionResolver.java

示例7: getClasspath

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
private static String getClasspath(
		final Class context )
		throws IOException {

	try {
		final ArrayList<ClassLoader> classloaders = new ArrayList<ClassLoader>();

		ClassLoader cl = context.getClassLoader();

		while (cl != null) {
			classloaders.add(cl);
			cl = cl.getParent();
		}

		Collections.reverse(classloaders);

		final StringBuilder classpathBuilder = new StringBuilder();

		// assume 0 is the system classloader and skip it
		for (int i = 0; i < classloaders.size(); i++) {
			final ClassLoader classLoader = classloaders.get(i);

			if (classLoader instanceof URLClassLoader) {

				for (final URL u : ((URLClassLoader) classLoader).getURLs()) {
					append(
							classpathBuilder,
							u);
				}

			}
			else if (classLoader instanceof VFSClassLoader) {

				final VFSClassLoader vcl = (VFSClassLoader) classLoader;
				for (final FileObject f : vcl.getFileObjects()) {
					append(
							classpathBuilder,
							f.getURL());
				}
			}
			else {
				throw new IllegalArgumentException(
						"Unknown classloader type : " + classLoader.getClass().getName());
			}
		}

		classpathBuilder.deleteCharAt(0);
		return classpathBuilder.toString();

	}
	catch (final URISyntaxException e) {
		throw new IOException(
				e);
	}
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:56,代碼來源:MiniAccumuloClusterFactory.java

示例8: initClassLoader

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
private static void initClassLoader()
		throws MalformedURLException {
	synchronized (MUTEX) {
		if (classLoaderInitialized) {
			return;
		}
		final ClassLoader classLoader = AccumuloUtils.class.getClassLoader();
		LOGGER.info("Generating patched classloader");
		if (classLoader instanceof VFSClassLoader) {
			final VFSClassLoader cl = (VFSClassLoader) classLoader;
			final FileObject[] fileObjs = cl.getFileObjects();
			final ArrayList<URL> fileList = new ArrayList();

			for (int i = 0; i < fileObjs.length; i++) {
				String fileStr = fileObjs[i].toString();
				if (verifyProtocol(fileStr)) {
					fileList.add(new URL(
							fileStr));
				}
				else {
					LOGGER.error("Failed to register class loader from: " + fileStr);
				}
			}

			final URL[] fileUrls = new URL[fileList.size()];
			for (int i = 0; i < fileList.size(); i++) {
				fileUrls[i] = fileList.get(i);
			}

			final ClassLoader urlCL = java.security.AccessController
					.doPrivileged(new java.security.PrivilegedAction<URLClassLoader>() {
						@Override
						public URLClassLoader run() {
							final URLClassLoader ucl = new URLClassLoader(
									fileUrls,
									cl);
							return ucl;
						}
					});

			SPIServiceRegistry.registerClassLoader(urlCL);
		}
		classLoaderInitialized = true;
	}
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:46,代碼來源:AccumuloUtils.java

示例9: test

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
@Test
public void test()
		// HPFortify FP: unit test not subject to security vulnerability
		throws FileSystemException,
		MalformedURLException {
	DefaultFileSystemManager fsManager = new DefaultFileSystemManager();
	fsManager.setCacheStrategy(CacheStrategy.MANUAL);
	fsManager.setFilesCache(new SoftRefFilesCache());
	fsManager.addProvider(
			"file",
			new DefaultLocalFileProvider());
	fsManager.addProvider(
			"jar",
			new JarFileProvider());
	fsManager.setBaseFile(new File(
			"."));

	// fsManager.addProvider("jar", new JarFileProvider());
	fsManager.init();
	FileObject jarFile = fsManager.resolveFile("jar:src/test/test.jar");

	final VFSClassLoader cl = new VFSClassLoader(
			jarFile,
			fsManager);

	final FileObject[] fileObjs = cl.getFileObjects();
	final URL[] fileUrls = new URL[fileObjs.length];
	for (int i = 0; i < fileObjs.length; i++) {
		fileUrls[i] = new URL(
				fileObjs[i].toString());
	}
	SPIServiceRegistry registry = new SPIServiceRegistry(
			FieldSerializationProviderSpi.class);
	registry.registerLocalClassLoader(java.security.AccessController
			.doPrivileged(new java.security.PrivilegedAction<URLClassLoader>() {
				public URLClassLoader run() {
					final URLClassLoader ucl = new URLClassLoader(
							fileUrls,
							cl);
					return ucl;
				}
			}));

	// Proves that the VFS Classloader SPI loading bug exists
	Iterator<FieldSerializationProviderSpi> it1 = ServiceLoader.load(
			FieldSerializationProviderSpi.class).iterator();
	boolean found = false;
	while (it1.hasNext()) {
		found |= it1.next().getClass().equals(
				BooleanSerializationProvider.class);
	}
	assertFalse(found);

	Iterator<FieldSerializationProviderSpi> it = registry.load(FieldSerializationProviderSpi.class);
	found = false;
	try {
		while (it.hasNext()) {
			found |= it.next().getClass().equals(
					BooleanSerializationProvider.class);
		}
	}
	catch (Throwable ex) {

		assertTrue(ex instanceof NoClassDefFoundError && ex.getLocalizedMessage().contains(
				"FieldSerializationProviderSpi"));
		return;
	}
	assertTrue(
			"The class not found exception is expected since the JAR file was not registered",
			false);
}
 
開發者ID:locationtech,項目名稱:geowave,代碼行數:72,代碼來源:SPIServiceRegistryTest.java

示例10: configureClassloader

import org.apache.commons.vfs2.impl.VFSClassLoader; //導入依賴的package包/類
/**
 * Create a classloader backed by a virtual filesystem which can handle the following URI types:
 * * res - resource files
 * * jar
 * * tar
 * * bz2
 * * tgz
 * * zip
 * * HDFS
 * * FTP
 * * HTTP/S
 * * file
 * @param paths A set of comma separated paths.  The paths are URIs or URIs with a regex pattern at the end.
 * @return A classloader object if it can create it
 * @throws FileSystemException
 */
public static Optional<ClassLoader> configureClassloader(String paths) throws FileSystemException {
  if(paths.trim().isEmpty()) {
    return Optional.empty();
  }
  FileSystemManager vfs = generateVfs();
  FileObject[] objects = resolve(vfs, paths);
  if(objects == null || objects.length == 0) {
    return Optional.empty();
  }
  return Optional.of(new VFSClassLoader(objects, vfs, vfs.getClass().getClassLoader()));
}
 
開發者ID:apache,項目名稱:metron,代碼行數:28,代碼來源:VFSClassloaderUtil.java


注:本文中的org.apache.commons.vfs2.impl.VFSClassLoader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。