Tabnine Logo
Class.getResource
Code IndexAdd Tabnine to your IDE (free)

How to use
getResource
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.getResource (Showing top 20 results out of 55,341)

origin: google/guava

 /**
  * Given a {@code resourceName} that is relative to {@code contextClass}, returns a {@code URL}
  * pointing to the named resource.
  *
  * @throws IllegalArgumentException if the resource is not found
  */
 public static URL getResource(Class<?> contextClass, String resourceName) {
  URL url = contextClass.getResource(resourceName);
  checkArgument(
    url != null, "resource %s relative to %s not found.", resourceName, contextClass.getName());
  return url;
 }
}
origin: skylot/jadx

public static ImageIcon openIcon(String name) {
  String iconPath = "/icons-16/" + name + ".png";
  URL resource = Utils.class.getResource(iconPath);
  if (resource == null) {
    throw new JadxRuntimeException("Icon not found: " + iconPath);
  }
  return new ImageIcon(resource);
}
origin: google/guava

 private static URL classfile(Class<?> c) {
  return c.getResource(c.getSimpleName() + ".class");
 }
}
origin: spring-projects/spring-framework

public JAXBElement<DataHandler> standardClassDataHandler() {
  DataSource dataSource = new URLDataSource(getClass().getResource("spring-ws.png"));
  DataHandler dataHandler = new DataHandler(dataSource);
  return new JAXBElement<>(NAME, DataHandler.class, dataHandler);
}
origin: google/guava

public void testToString() throws IOException {
 URL resource = getClass().getResource("testdata/i18n.txt");
 assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
 assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
}
origin: google/guava

public void testCopyToOutputStream() throws IOException {
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 URL resource = getClass().getResource("testdata/i18n.txt");
 Resources.copy(resource, out);
 assertEquals(I18N, out.toString("UTF-8"));
}
origin: spring-projects/spring-framework

@Test(expected = FileNotFoundException.class)
public void testInputStreamNotFoundOnFileSystemResource() throws IOException {
  new FileSystemResource(getClass().getResource("Resource.class").getFile()).createRelative("X").getInputStream();
}
origin: google/guava

/** Returns the file with the given name under the testdata directory. */
protected final File getTestFile(String name) throws IOException {
 File file = new File(getTestDir(), name);
 if (!file.exists()) {
  URL resourceUrl = IoTestCase.class.getResource("testdata/" + name);
  if (resourceUrl == null) {
   return null;
  }
  copy(resourceUrl, file);
 }
 return file;
}
origin: google/guava

public void testReadLines() throws IOException {
 // TODO(chrisn): Check in a better resource
 URL resource = getClass().getResource("testdata/i18n.txt");
 assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
}
origin: spring-projects/spring-framework

@Test
public void testFileSystemResourceWithFilePath() throws Exception {
  Path filePath = Paths.get(getClass().getResource("Resource.class").toURI());
  Resource resource = new FileSystemResource(filePath);
  doTestResource(resource);
  assertEquals(new FileSystemResource(filePath), resource);
}
origin: spring-projects/spring-framework

public CallbacksSecurityTests() {
  // setup security
  if (System.getSecurityManager() == null) {
    Policy policy = Policy.getPolicy();
    URL policyURL = getClass()
        .getResource(
            "/org/springframework/beans/factory/support/security/policy.all");
    System.setProperty("java.security.policy", policyURL.toString());
    System.setProperty("policy.allowSystemProperty", "true");
    policy.refresh();
    System.setSecurityManager(new SecurityManager());
  }
}
origin: spring-projects/spring-framework

@Test
public void testFileSystemResource() throws IOException {
  String file = getClass().getResource("Resource.class").getFile();
  Resource resource = new FileSystemResource(file);
  doTestResource(resource);
  assertEquals(new FileSystemResource(file), resource);
}
origin: google/guava

@AndroidIncompatible // TODO(cpovirk): How significant is this failure?
public void testGetFinalizerUrl() {
 assertNotNull(getClass().getResource("internal/Finalizer.class"));
}
origin: google/guava

 private void doExtensiveTest(String resourceName) throws IOException {
  Splitter splitter = Splitter.on(CharMatcher.whitespace());
  URL url = getClass().getResource(resourceName);
  for (String line : Resources.readLines(url, UTF_8)) {
   Iterator<String> iterator = splitter.split(line).iterator();
   String input = iterator.next();
   String expectedOutput = iterator.next();
   assertFalse(iterator.hasNext());
   assertEquals(expectedOutput, simplifyPath(input));
  }
 }
}
origin: spring-projects/spring-framework

@Test(expected = FileNotFoundException.class)
public void testReadableChannelNotFoundOnFileSystemResource() throws IOException {
  new FileSystemResource(getClass().getResource("Resource.class").getFile()).createRelative("X").readableChannel();
}
origin: spring-projects/spring-framework

@Test // SPR-12624
public void checkRelativeLocation() throws Exception {
  String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
  Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework"));
  List<Resource> locations = singletonList(location);
  assertNotNull(this.resolver.resolveResource(null, "main.css", locations, null).block(TIMEOUT));
}
origin: spring-projects/spring-framework

@Test
public void checkRelativeLocation() throws Exception {
  String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
  Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework"));
  assertNotNull(this.resolver.resolveResource(null, "main.css", Collections.singletonList(location), null));
}
origin: spring-projects/spring-framework

@Test
public void testFileSystemResourceWithImport() throws URISyntaxException {
  String file = getClass().getResource(RESOURCE_CONTEXT.getPath()).toURI().getPath();
  DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
  new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new FileSystemResource(file));
  // comes from "resourceImport.xml"
  xbf.getBean("resource1", ResourceTestBean.class);
  // comes from "resource.xml"
  xbf.getBean("resource2", ResourceTestBean.class);
}
origin: spring-projects/spring-framework

@Test
public void testUrlResourceWithImport() {
  URL url = getClass().getResource(RESOURCE_CONTEXT.getPath());
  DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
  new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new UrlResource(url));
  // comes from "resourceImport.xml"
  xbf.getBean("resource1", ResourceTestBean.class);
  // comes from "resource.xml"
  xbf.getBean("resource2", ResourceTestBean.class);
}
origin: spring-projects/spring-framework

@Test
public void testUrlResource() throws IOException {
  Resource resource = new UrlResource(getClass().getResource("Resource.class"));
  doTestResource(resource);
  assertEquals(new UrlResource(getClass().getResource("Resource.class")), resource);
  Resource resource2 = new UrlResource("file:core/io/Resource.class");
  assertEquals(resource2, new UrlResource("file:core/../core/io/./Resource.class"));
  assertEquals("test.txt", new UrlResource("file:/dir/test.txt?argh").getFilename());
  assertEquals("test.txt", new UrlResource("file:\\dir\\test.txt?argh").getFilename());
  assertEquals("test.txt", new UrlResource("file:\\dir/test.txt?argh").getFilename());
}
java.langClassgetResource

Javadoc

Returns the URL of the given resource, or null if the resource is not found. The mapping between the resource name and the URL is managed by the class' class loader.

Popular methods of Class

  • getName
    Returns the name of the class represented by this Class. For a description of the format which is us
  • getSimpleName
  • getClassLoader
  • isAssignableFrom
    Determines if the class or interface represented by this Class object is either the same as, or is a
  • forName
    Returns the Class object associated with the class or interface with the given string name, using th
  • newInstance
    Returns a new instance of the class represented by this Class, created by invoking the default (that
  • getMethod
    Returns a Method object that reflects the specified public member method of the class or interface r
  • getResourceAsStream
  • getSuperclass
    Returns the Class representing the superclass of the entity (class, interface, primitive type or voi
  • getConstructor
  • cast
    Casts an object to the class or interface represented by this Class object.
  • isInstance
  • cast,
  • isInstance,
  • getCanonicalName,
  • getDeclaredField,
  • isArray,
  • getAnnotation,
  • getDeclaredFields,
  • getDeclaredMethod,
  • getMethods

Popular in Java

  • Making http post requests using okhttp
  • scheduleAtFixedRate (Timer)
  • notifyDataSetChanged (ArrayAdapter)
  • getSharedPreferences (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Socket (java.net)
    Provides a client-side TCP socket.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • JFileChooser (javax.swing)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now