Example usage for java.lang ClassLoader getSystemResource

List of usage examples for java.lang ClassLoader getSystemResource

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResource.

Prototype

public static URL getSystemResource(String name) 

Source Link

Document

Find a resource of the specified name from the search path used to load classes.

Usage

From source file:org.commonvox.hbase_column_manager.TestRepositoryAdmin.java

private void validateXmlAgainstXsd(File xmlFile) throws IOException {
    Document hsaDocument = null;//from  w w w . java 2s  .  c  o m
    Schema hsaSchema = null;
    try {
        hsaDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFile);
    } catch (ParserConfigurationException pce) {
        fail(TEST_ENVIRONMENT_SETUP_PROBLEM + " parser config exception thrown: " + pce.getMessage());
    } catch (SAXException se) {
        fail(REPOSITORY_ADMIN_FAILURE + " SAX exception thrown while loading test document: "
                + se.getMessage());
    }
    try {
        hsaSchema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
                .newSchema(Paths
                        .get(ClassLoader.getSystemResource(XmlSchemaGenerator.DEFAULT_OUTPUT_FILE_NAME).toURI())
                        .toFile());
    } catch (URISyntaxException ue) {
        fail(TEST_ENVIRONMENT_SETUP_PROBLEM + " URI syntax exception thrown: " + ue.getMessage());
    } catch (SAXException se) {
        fail(REPOSITORY_ADMIN_FAILURE + " SAX exception thrown while loading XML-schema: " + se.getMessage());
    }
    // validate against XSD
    try {
        hsaSchema.newValidator().validate(new DOMSource(hsaDocument));
    } catch (SAXException se) {
        fail(REPOSITORY_ADMIN_FAILURE + " exported HSA file is invalid with respect to " + "XML schema: "
                + se.getMessage());
    }
}

From source file:org.commonvox.hbase_column_manager.TestRepositoryAdmin.java

private void compareResourceFileToExportedFile(String resourceFileString, File exportedFile, String methodName)
        throws IOException, URISyntaxException {
    Path resourcePath = Paths.get(ClassLoader.getSystemResource(resourceFileString).toURI());
    assertEquals(CHANGE_EVENT_FAILURE + "unexpected item count from " + methodName + " method",
            Files.lines(resourcePath).count(), Files.lines(exportedFile.toPath()).count());
    // NOTE: timestamps on sequential events can sometimes be equal (if processing is TOO quick!)
    // so reliable comparison requires stripping initial timestamp from each line and reordering
    // remainder via TreeSets, then doing comparison.
    TreeSet<String> resourceLinesTruncated = new TreeSet<>();
    TreeSet<String> exportedLinesTruncated = new TreeSet<>();
    Iterator<String> resourceLinesIterator = Files.lines(resourcePath).iterator();
    Iterator<String> exportedLinesIterator = Files.lines(exportedFile.toPath()).iterator();
    int skipCount = 0;
    while (resourceLinesIterator.hasNext()) {
        if (skipCount++ < 3) {
            resourceLinesIterator.next(); // skip comment and header lines in both files
            exportedLinesIterator.next(); // skip comment and header lines in both files
            continue;
        }//  ww  w . ja  va2  s. com
        resourceLinesTruncated.add(resourceLinesIterator.next().substring(14)); // strip timestamp
        exportedLinesTruncated.add(exportedLinesIterator.next().substring(14)); // strip timestamp
    }
    Iterator<String> resourceLinesTruncatedIterator = resourceLinesTruncated.iterator();
    Iterator<String> exportedLinesTruncatedIterator = exportedLinesTruncated.iterator();
    while (resourceLinesTruncatedIterator.hasNext()) {
        assertEquals(CHANGE_EVENT_FAILURE + "unexpected content returned by " + methodName,
                resourceLinesTruncatedIterator.next(), exportedLinesTruncatedIterator.next());
    }
}

From source file:paintbasico2d.VentanaPrincipal.java

/** Metodo sobreescrito para cambiar el icono de la imagen de la aplicacion.
* 
* 
* @return         Devuelve el icono a cambiar en la aplicacion
*//*from www  .j  av a  2 s. c  o  m*/
public Image getIconImage() { //metodo para cambiar el icono de la imagen del programa

    Image ret = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("iconos/PlayPressed_48x48.png"));
    return ret;
}

From source file:osu.beatmapdownloader.JFrame.java

@Override
   public Image getIconImage() {
       Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("Icon.png"));
       return retValue;
   }// ww  w .  j a v a  2  s. c om

From source file:com.kodemore.utility.Kmu.java

/**
 * Read a resource from the class path.//from   w w  w  .j  a v  a2  s.  c  om
 * For example: to read a file named "abc.txt"
 * located in the package com.kodemore you could use:
 * Kmu.readClassResource("com/kodemore/abc.txt");
 */
public static byte[] readResourceBytes(String path) {
    URL url = ClassLoader.getSystemResource(path);

    try (InputStream in = url.openStream(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        while (true) {
            int b = in.read();
            if (b < 0)
                break;

            out.write(b);
        }

        return out.toByteArray();
    } catch (IOException ex) {
        KmLog.error(ex, "Cannot read class resource(%s)", path);
        return null;
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

private void mnuHelpContentsActionPerformed(java.awt.event.ActionEvent evt) {
    URL index = ClassLoader.getSystemResource("./Help/index.html");
    new HelpWindow("Indigo Help", index, theSettingsPath);
}