static ClassLoader getSystemClassLoader() { if (System.getSecurityManager() == null) { return ClassLoader.getSystemClassLoader(); } else { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return ClassLoader.getSystemClassLoader(); } }); } }
static ClassLoader getSystemClassLoader() { if (System.getSecurityManager() == null) { return ClassLoader.getSystemClassLoader(); } else { return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return ClassLoader.getSystemClassLoader(); } }); } }
private static ImmutableList<URL> getClassLoaderUrls(ClassLoader classloader) { if (classloader instanceof URLClassLoader) { return ImmutableList.copyOf(((URLClassLoader) classloader).getURLs()); } if (classloader.equals(ClassLoader.getSystemClassLoader())) { return parseJavaClassPath(); } return ImmutableList.of(); }
private static void load(LangLocale locale) { ResourceBundle bundle; ClassLoader classLoader = ClassLoader.getSystemClassLoader(); String resName = String.format("i18n/Messages_%s.properties", locale.get()); URL bundleUrl = classLoader.getResource(resName); if (bundleUrl == null) { throw new JadxRuntimeException("Locale resource not found: " + resName); } try (Reader reader = new InputStreamReader(bundleUrl.openStream(), StandardCharsets.UTF_8)) { bundle = new PropertyResourceBundle(reader); } catch (IOException e) { throw new JadxRuntimeException("Failed to load " + resName, e); } i18nMessagesMap.put(locale, bundle); }
public static Properties loadFilterConfig() throws IOException { Properties filterProperties = new Properties(); loadFilterConfig(filterProperties, ClassLoader.getSystemClassLoader()); loadFilterConfig(filterProperties, FilterManager.class.getClassLoader()); loadFilterConfig(filterProperties, Thread.currentThread().getContextClassLoader()); loadFilterConfig(filterProperties, FilterManager.class.getClassLoader()); return filterProperties; }
private static ImmutableList<URL> getClassLoaderUrls(ClassLoader classloader) { if (classloader instanceof URLClassLoader) { return ImmutableList.copyOf(((URLClassLoader) classloader).getURLs()); } if (classloader.equals(ClassLoader.getSystemClassLoader())) { return parseJavaClassPath(); } return ImmutableList.of(); }
@Test public void testResourceToString_ExistingResourceAtSubPackage_WithClassLoader() throws Exception { final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").getFile()).length(); final String content = IOUtils.resourceToString( "org/apache/commons/io/FileUtilsTestDataCR.dat", StandardCharsets.UTF_8, ClassLoader.getSystemClassLoader() ); assertNotNull(content); assertEquals(fileSize, content.getBytes().length); }
@Test public void testResourceToString_ExistingResourceAtRootPackage_WithClassLoader() throws Exception { final long fileSize = new File(getClass().getResource("/test-file-simple-utf8.bin").getFile()).length(); final String content = IOUtils.resourceToString( "test-file-simple-utf8.bin", StandardCharsets.UTF_8, ClassLoader.getSystemClassLoader() ); assertNotNull(content); assertEquals(fileSize, content.getBytes().length); }
public void testResourceScanner() throws IOException { ResourceScanner scanner = new ResourceScanner(); scanner.scan(ClassLoader.getSystemClassLoader()); assertThat(scanner.resources).contains("com/google/common/reflect/ClassPathTest.class"); }
@Test public void testResourceToByteArray_ExistingResourceAtRootPackage_WithClassLoader() throws Exception { final long fileSize = new File(getClass().getResource("/test-file-utf8.bin").getFile()).length(); final byte[] bytes = IOUtils.resourceToByteArray("test-file-utf8.bin", ClassLoader.getSystemClassLoader()); assertNotNull(bytes); assertEquals(fileSize, bytes.length); }
@Test public void testResourceToByteArray_ExistingResourceAtSubPackage_WithClassLoader() throws Exception { final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").getFile()).length(); final byte[] bytes = IOUtils.resourceToByteArray("org/apache/commons/io/FileUtilsTestDataCR.dat", ClassLoader.getSystemClassLoader()); assertNotNull(bytes); assertEquals(fileSize, bytes.length); }
@Test public void testResourceToString_NullCharset_WithClassLoader() throws Exception { IOUtils.resourceToString("test-file-utf8.bin", null, ClassLoader.getSystemClassLoader()); }
@Test(expected = IOException.class) public void testResourceToString_NonExistingResource_WithClassLoader() throws Exception { IOUtils.resourceToString("non-existing-file.bin", StandardCharsets.UTF_8, ClassLoader.getSystemClassLoader()); }
@Test(expected = IOException.class) public void testResourceToByteArray_NonExistingResource_WithClassLoader() throws Exception { IOUtils.resourceToByteArray("non-existing-file.bin", ClassLoader.getSystemClassLoader()); }
@Test(expected = IOException.class) public void testResourceToURL_NonExistingResource_WithClassLoader() throws Exception { IOUtils.resourceToURL("non-existing-file.bin", ClassLoader.getSystemClassLoader()); }
@Test public void testResourceToURL_ExistingResourceAtRootPackage_WithClassLoader() throws Exception { final URL url = IOUtils.resourceToURL("test-file-utf8.bin", ClassLoader.getSystemClassLoader()); assertNotNull(url); assertTrue(url.getFile().endsWith("/test-file-utf8.bin")); }
@Test public void testResourceToURL_ExistingResourceAtSubPackage_WithClassLoader() throws Exception { final URL url = IOUtils.resourceToURL( "org/apache/commons/io/FileUtilsTestDataCR.dat", ClassLoader.getSystemClassLoader() ); assertNotNull(url); assertTrue(url.getFile().endsWith("/org/apache/commons/io/FileUtilsTestDataCR.dat")); }
@Test public void testResourceToURL_Null_WithClassLoader() throws Exception { boolean exceptionOccurred = false; try { IOUtils.resourceToURL(null, ClassLoader.getSystemClassLoader()); fail(); } catch (final NullPointerException npe) { exceptionOccurred = true; assertNotNull(npe); } assertTrue(exceptionOccurred); }
@Test public void testResourceToByteArray_Null_WithClassLoader() throws Exception { boolean exceptionOccurred = false; try { IOUtils.resourceToByteArray(null, ClassLoader.getSystemClassLoader()); fail(); } catch (final NullPointerException npe) { exceptionOccurred = true; assertNotNull(npe); } assertTrue(exceptionOccurred); }
@Test public void testResourceToString_NullResource_WithClassLoader() throws Exception { boolean exceptionOccurred = false; try { IOUtils.resourceToString(null, StandardCharsets.UTF_8, ClassLoader.getSystemClassLoader()); fail(); } catch (final NullPointerException npe) { exceptionOccurred = true; assertNotNull(npe); } assertTrue(exceptionOccurred); }