List of usage examples for org.apache.commons.io FileUtils copyURLToFile
public static void copyURLToFile(URL source, File destination) throws IOException
source
to a file destination
. From source file:org.apache.accumulo.start.classloader.vfs.AccumuloReloadingVFSClassLoaderTest.java
@Test @Ignore//w ww .ja va 2 s .c o m public void testFastDeleteAndReAdd() throws Exception { FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString()); FileObject[] dirContents = testDir.getChildren(); AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folderPath, vfs, new ReloadingClassLoader() { @Override public ClassLoader getClassLoader() { return ClassLoader.getSystemClassLoader(); } }, 1000, true); FileObject[] files = ((VFSClassLoader) arvcl.getClassLoader()).getFileObjects(); Assert.assertArrayEquals(createFileSystems(dirContents), files); Class<?> clazz1 = arvcl.getClassLoader().loadClass("test.HelloWorld"); Object o1 = clazz1.newInstance(); Assert.assertEquals("Hello World!", o1.toString()); // Check that the class is the same before the update Class<?> clazz1_5 = arvcl.getClassLoader().loadClass("test.HelloWorld"); Assert.assertEquals(clazz1, clazz1_5); assertTrue(new File(folder1.getRoot(), "HelloWorld.jar").delete()); // Update the class FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar")); // Wait for the monitor to notice // VFS-487 significantly wait to avoid failure Thread.sleep(7000); Class<?> clazz2 = arvcl.getClassLoader().loadClass("test.HelloWorld"); Object o2 = clazz2.newInstance(); Assert.assertEquals("Hello World!", o2.toString()); // This is false because they are loaded by a different classloader Assert.assertFalse(clazz1.equals(clazz2)); Assert.assertFalse(o1.equals(o2)); arvcl.close(); }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloReloadingVFSClassLoaderTest.java
@Test @Ignore/*from w ww . j av a 2s. co m*/ public void testModifiedClass() throws Exception { FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString()); FileObject[] dirContents = testDir.getChildren(); AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folderPath, vfs, new ReloadingClassLoader() { @Override public ClassLoader getClassLoader() { return ClassLoader.getSystemClassLoader(); } }, 1000, true); FileObject[] files = ((VFSClassLoader) arvcl.getClassLoader()).getFileObjects(); Assert.assertArrayEquals(createFileSystems(dirContents), files); ClassLoader loader1 = arvcl.getClassLoader(); Class<?> clazz1 = loader1.loadClass("test.HelloWorld"); Object o1 = clazz1.newInstance(); Assert.assertEquals("Hello World!", o1.toString()); // Check that the class is the same before the update Class<?> clazz1_5 = arvcl.getClassLoader().loadClass("test.HelloWorld"); Assert.assertEquals(clazz1, clazz1_5); // java does aggressive caching of jar files. When using java code to read jar files that are created in the same second, it will only see the first jar // file Thread.sleep(1000); assertTrue(new File(folder1.getRoot(), "HelloWorld.jar").delete()); // Update the class FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld2.jar"), folder1.newFile("HelloWorld.jar")); // Wait for the monitor to notice // VFS-487 significantly wait to avoid failure Thread.sleep(7000); Class<?> clazz2 = arvcl.getClassLoader().loadClass("test.HelloWorld"); Object o2 = clazz2.newInstance(); Assert.assertEquals("Hallo Welt", o2.toString()); // This is false because they are loaded by a different classloader Assert.assertFalse(clazz1.equals(clazz2)); Assert.assertFalse(o1.equals(o2)); Class<?> clazz3 = loader1.loadClass("test.HelloWorld"); Object o3 = clazz3.newInstance(); Assert.assertEquals("Hello World!", o3.toString()); arvcl.close(); }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoaderTest.java
@Test public void testDefaultContextConfigured() throws Exception { Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); // Copy jar file to TEST_DIR FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar")); File conf = folder1.newFile("accumulo-site.xml"); FileWriter out = new FileWriter(conf); out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); out.append("<configuration>\n"); out.append("<property>\n"); out.append("<name>general.classpaths</name>\n"); out.append("<value></value>\n"); out.append("</property>\n"); out.append("<property>\n"); out.append("<name>general.vfs.classpaths</name>\n"); out.append("<value>" + new File(folder1.getRoot(), "HelloWorld.jar").toURI() + "</value>\n"); out.append("</property>\n"); out.append("</configuration>\n"); out.close();/*w w w. j a v a 2 s . c o m*/ Whitebox.setInternalState(AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString()); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object()); ClassLoader acl = AccumuloVFSClassLoader.getClassLoader(); Assert.assertTrue((acl instanceof VFSClassLoader)); Assert.assertTrue((acl.getParent() instanceof VFSClassLoader)); VFSClassLoader arvcl = (VFSClassLoader) acl.getParent(); Assert.assertEquals(1, arvcl.getFileObjects().length); // We can't be sure what the authority/host will be due to FQDN mappings, so just check the path Assert.assertTrue(arvcl.getFileObjects()[0].getURL().toString().contains("HelloWorld.jar")); Class<?> clazz1 = arvcl.loadClass("test.HelloWorld"); Object o1 = clazz1.newInstance(); Assert.assertEquals("Hello World!", o1.toString()); Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null); }
From source file:org.apache.accumulo.start.classloader.vfs.ContextManagerTest.java
@Before public void setup() throws Exception { vfs = getVFS();//from w w w . j a v a2s . c o m folder1.create(); folder2.create(); FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar")); FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder2.newFile("HelloWorld.jar")); uri1 = new File(folder1.getRoot(), "HelloWorld.jar").toURI().toString(); uri2 = folder2.getRoot().toURI().toString() + ".*"; }
From source file:org.apache.accumulo.test.ShellServerTest.java
@Test(timeout = 30000) public void testPertableClasspath() throws Exception { File fooFilterJar = File.createTempFile("FooFilter", ".jar"); FileUtils.copyURLToFile(this.getClass().getResource("/FooFilter.jar"), fooFilterJar); fooFilterJar.deleteOnExit();/*from w ww . ja v a2 s . c om*/ File fooConstraintJar = File.createTempFile("FooConstraint", ".jar"); FileUtils.copyURLToFile(this.getClass().getResource("/FooConstraint.jar"), fooConstraintJar); fooConstraintJar.deleteOnExit(); exec("config -s " + Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "cx1=" + fooFilterJar.toURI().toString() + "," + fooConstraintJar.toURI().toString(), true); exec("createtable ptc", true); exec("config -t ptc -s " + Property.TABLE_CLASSPATH.getKey() + "=cx1", true); UtilWaitThread.sleep(200); exec("setiter -scan -class org.apache.accumulo.test.FooFilter -p 10 -n foo", true); exec("insert foo f q v", true); UtilWaitThread.sleep(100); exec("scan -np", true, "foo", false); exec("constraint -a FooConstraint", true); exec("offline ptc"); UtilWaitThread.sleep(500); exec("online ptc"); exec("table ptc", true); exec("insert foo f q v", false); exec("insert ok foo q v", true); exec("deletetable ptc", true); exec("config -d " + Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "cx1"); }
From source file:org.apache.empire.db.eclipse.Plugin.java
private void checkConfigFile(String filename) { File configFile = new File(PluginConsts.CONFIG_DIR_PATH, filename); if (!configFile.exists()) { URL inputUrl = Plugin.class.getClassLoader().getResource(filename); try {//from w ww . j ava 2 s. c om FileUtils.copyURLToFile(inputUrl, configFile); } catch (IOException e) { Plugin.log.error("Could not copy resoucres file in configuration directory! %s", e.getMessage()); } } }
From source file:org.apache.geode.cache.query.dunit.QueryIndexUsingXMLDUnitTest.java
@Before public void before() throws Exception { addIgnoredException("Failed to create index"); URL url = getClass().getResource(CACHE_XML_FILE_NAME); assertThat(url).isNotNull(); // precondition this.cacheXmlFile = this.temporaryFolder.newFile(CACHE_XML_FILE_NAME); FileUtils.copyURLToFile(url, this.cacheXmlFile); assertThat(this.cacheXmlFile).exists(); // precondition }
From source file:org.apache.geode.cache.query.internal.index.NewDeclarativeIndexCreationJUnitTest.java
@Before public void setUp() throws Exception { this.cacheXmlFile = this.temporaryFolder.newFile(CACHE_XML_FILE_NAME); FileUtils.copyURLToFile(getClass().getResource(CACHE_XML_FILE_NAME), this.cacheXmlFile); assertThat(this.cacheXmlFile).exists(); // precondition Properties props = new Properties(); props.setProperty(CACHE_XML_FILE, this.cacheXmlFile.getAbsolutePath()); props.setProperty(MCAST_PORT, "0"); DistributedSystem ds = DistributedSystem.connect(props); this.cache = CacheFactory.create(ds); }
From source file:org.apache.geode.cache.query.internal.index.NewDeclarativeIndexCreationJUnitTest.java
/** * TODO: move this to a different test class because it requires different setup *//*from w w w . j a v a 2s.c o m*/ @Test public void testIndexCreationExceptionOnRegionWithNewDTD() throws Exception { if (this.cache != null && !this.cache.isClosed()) { this.cache.close(); } this.cacheXmlFile = this.temporaryFolder.newFile("cachequeryindexwitherror.xml"); FileUtils.copyURLToFile(getClass().getResource("cachequeryindexwitherror.xml"), this.cacheXmlFile); assertThat(this.cacheXmlFile).exists(); // precondition Properties props = new Properties(); props.setProperty(CACHE_XML_FILE, this.cacheXmlFile.getAbsolutePath()); props.setProperty(MCAST_PORT, "0"); DistributedSystem ds = DistributedSystem.connect(props); // TODO: refactoring GemFireCacheImpl.initializeDeclarativeCache requires change here assertThatThrownBy(() -> CacheFactory.create(ds)).isExactlyInstanceOf(CacheXmlException.class) .hasCauseInstanceOf(InternalGemFireException.class); }
From source file:org.apache.geode.cache30.CacheXmlTestCase.java
protected File copyResourceToDirectory(File directory, String fileName) throws IOException { URL url = getClass().getResource(fileName); File file = new File(directory, fileName); FileUtils.copyURLToFile(url, file); return file;/*from www . j a va 2 s. co m*/ }