Example usage for java.net URL getFile

List of usage examples for java.net URL getFile

Introduction

In this page you can find the example usage for java.net URL getFile.

Prototype

public String getFile() 

Source Link

Document

Gets the file name of this URL .

Usage

From source file:de.brendamour.jpasskit.signing.PKPassTemplateFolder.java

public PKPassTemplateFolder(URL fileUrlOfTemplateDirectory) throws UnsupportedEncodingException {
    pathToTemplateDirectory = URLDecoder.decode(fileUrlOfTemplateDirectory.getFile(), "UTF-8");
}

From source file:org.openmrs.module.clinicalsummary.rule.EvaluableSummaryRuleProvider.java

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *///from  w  w w.j a  v a2s .c  o  m
@Override
public void afterStartup() {

    if (log.isDebugEnabled())
        log.debug("Registering clinical summary rules ...");

    try {
        ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(CLINICAL_SUMMARY_MODULE);
        for (URL url : moduleClassLoader.getURLs()) {
            String filename = url.getFile();
            if (StringUtils.contains(filename, CLINICAL_SUMMARY_MODULE_API)) {
                ZipFile zipFile = new ZipFile(filename);
                for (Enumeration list = zipFile.entries(); list.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) list.nextElement();
                    String zipFileName = FilenameUtils.getBaseName(entry.getName());
                    String zipFileExtension = FilenameUtils.getExtension(entry.getName());
                    if (StringUtils.endsWith(zipFileName, RULE_CLASS_SUFFIX)
                            && StringUtils.equals(zipFileExtension, CLASS_SUFFIX)) {
                        EvaluableRuleVisitor visitor = new EvaluableRuleVisitor();
                        ClassReader classReader = new ClassReader(zipFile.getInputStream(entry));
                        classReader.accept(visitor, false);
                    }
                }
                zipFile.close();
            }
        }
    } catch (IOException e) {
        log.error("Processing rule classes failed. Rule might not get registered.");
    }
}

From source file:org.openmrs.module.amrsreports.rule.MohEvaluableRuleProvider.java

/**
 * @see org.openmrs.logic.rule.provider.RuleProvider#afterStartup()
 *///from   w w w.j  a v a 2s .  c o  m
@Override
public void afterStartup() {

    if (log.isDebugEnabled())
        log.debug("Registering AMRS reports summary rules ...");

    try {
        ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(AMRS_REPORT_MODULE);
        for (URL url : moduleClassLoader.getURLs()) {
            String filename = url.getFile();
            if (StringUtils.contains(filename, AMRS_REPORT_MODULE_API)) {
                ZipFile zipFile = new ZipFile(filename);
                for (Enumeration list = zipFile.entries(); list.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) list.nextElement();
                    String zipFileName = FilenameUtils.getBaseName(entry.getName());
                    String zipFileExtension = FilenameUtils.getExtension(entry.getName());
                    if (StringUtils.endsWith(zipFileName, RULE_CLASS_SUFFIX)
                            && StringUtils.equals(zipFileExtension, CLASS_SUFFIX)) {
                        MohEvaluableRuleVisitor visitor = new MohEvaluableRuleVisitor();
                        ClassReader classReader = new ClassReader(zipFile.getInputStream(entry));
                        classReader.accept(visitor, false);
                    }
                }
                zipFile.close();
            }
        }
    } catch (IOException e) {
        log.error("Processing rule classes failed. Rule might not get registered.");
    }
}

From source file:framework.ReloadingServer.java

public ReloadingServer() throws InterruptedException, IOException {
    URLClassLoader urlClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
    ReloadingClassLoader pParent = new ReloadingClassLoader(urlClassLoader);
    final ReloadingClassLoader loader = new ReloadingClassLoader(pParent);
    for (URL url : urlClassLoader.getURLs()) {
        String file = url.getFile();
        if (!file.contains("commons-jci")) {
            if (file.endsWith(".jar") || file.endsWith("/web.xml") || file.endsWith(".properties")) {
                pParent.addResourceStore(new JarResourceStore(file));
            } else {
                pParent.addResourceStore(new FileResourceStore(new File(file)));
            }//www .j  av a 2s .c o  m
        }
    }
    Thread.currentThread().setContextClassLoader(loader);

    String classesDir = new File("target/classes").getAbsolutePath();
    int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED | JNotify.FILE_MODIFIED | JNotify.FILE_RENAMED;
    boolean watchSubtree = true;
    try {
        int watchID = JNotify.addWatch(classesDir, mask, watchSubtree, new JNotifyAdapter() {
            @Override
            public void fileModified(int wd, String rootPath, String name) {
                if (name.endsWith(".class")) {
                    modified = true;
                }
            }
        });
    } catch (Exception e) {
        Loggers.SERVER.error(e.getMessage(), e);
    }
    startJetty();
    while (true) {
        try {
            Thread.sleep(400);
        } catch (InterruptedException e) {
            break;
        }
        synchronized (ReloadingServer.class) {
            if (modified) {
                stopJetty();
                ReloadingClassLoader contextClassLoader = (ReloadingClassLoader) Thread.currentThread()
                        .getContextClassLoader();
                contextClassLoader.handleNotification();
                ReloadingClassLoader parent = (ReloadingClassLoader) contextClassLoader.getParent();
                parent.handleNotification();
                Thread.currentThread().setContextClassLoader(new ReloadingClassLoader(parent));
                startJetty();
                modified = false;
            }
        }
    }
}

From source file:Main.java

public String downloadWWWPage(URL pageURL) throws Exception {
    String host, file;//from w  w  w  .  j  av a  2 s  .c  o m
    host = pageURL.getHost();
    file = pageURL.getFile();

    InputStream pageStream = getWWWPageStream(host, file);
    if (pageStream == null) {
        return "";
    }

    DataInputStream in = new DataInputStream(pageStream);
    StringBuffer pageBuffer = new StringBuffer();
    String line;

    while ((line = in.readUTF()) != null) {
        pageBuffer.append(line);
    }
    in.close();
    return pageBuffer.toString();
}

From source file:io.scigraph.owlapi.postprocessors.CliqueConfigurationTest.java

@Before
public void setup() throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
    URL url = this.getClass().getResource("/cliqueConfiguration.yaml");
    File configFile = new File(url.getFile());

    assertThat(configFile.exists(), is(true));

    OwlLoadConfigurationLoader owlLoadConfigurationLoader = new OwlLoadConfigurationLoader(configFile);
    loaderConfig = owlLoadConfigurationLoader.loadConfig();
    cliqueConfiguration = loaderConfig.getCliqueConfiguration().get();
}

From source file:com.sastix.cms.server.services.cache.CacheFileUtilsServiceTest.java

@Test
public void downloadOnlineResourceTest() throws IOException, URISyntaxException {
    //from online resource
    URL localFile = getClass().getClassLoader().getResource("./logo.png");
    byte[] expected = Files.readAllBytes(Paths.get(localFile.getFile()));
    byte[] bytesFound = cacheFileUtilsService.downloadResource(
            new URL("https://raw.githubusercontent.com/sastix/cms/master/server/src/test/resources/logo.png"));
    Assert.assertArrayEquals(expected, bytesFound);
}

From source file:com.amalto.core.servlet.FileChunkLoaderTest.java

private File getFile(String filename) {
    URL url = getClass().getClassLoader().getResource(filename);
    assertNotNull(url);/*from w  ww .  j  av  a 2s.  c  o  m*/
    return new File(url.getFile());
}

From source file:net.famzangl.minecraft.minebot.settings.MinebotDirectoryCreator.java

public File createDirectory(File dir) throws IOException {
    CodeSource src = MinebotDirectoryCreator.class.getProtectionDomain().getCodeSource();
    if (src != null) {
        URL jar = src.getLocation();
        if (jar.getFile().endsWith("class") && !jar.getFile().contains(".jar!")) {
            System.out.println("WARNING: Using the dev directory for settings.");
            // We are in a dev enviroment.
            return new File(new File(jar.getFile()).getParentFile(), "minebot");
        }//  w w  w. j  a  v  a 2 s .  c om
        if (dir.isFile()) {
            dir.delete();
        }

        dir.mkdirs();
        ZipInputStream zip = new ZipInputStream(jar.openStream());
        try {
            ZipEntry zipEntry;
            while ((zipEntry = zip.getNextEntry()) != null) {
                String name = zipEntry.getName();
                if (name.startsWith(BASE)) {
                    String[] localName = name.substring(BASE.length()).split("/");
                    File currentDir = dir;
                    for (int i = 0; i < localName.length; i++) {
                        currentDir = new File(currentDir, localName[i]);
                        currentDir.mkdir();
                    }
                    File copyTo = new File(currentDir, localName[localName.length - 1]);
                    extract(zip, copyTo);
                }
            }
        } finally {
            zip.close();
        }
        return dir;
    } else {
        throw new IOException("Could not find minebot directory to extract.");
    }
}

From source file:io.scigraph.owlapi.loader.OwlLoadConfigurationLoaderTest.java

@Before
public void setup() throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
    URL url = this.getClass().getResource("/pizzaExample.yaml");
    File pizzaFile = new File(url.getFile());

    assertThat(pizzaFile.exists(), is(true));
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    rawConfig = mapper.readValue(pizzaFile, OwlLoadConfiguration.class);

    OwlLoadConfigurationLoader owlLoadConfigurationLoader = new OwlLoadConfigurationLoader(pizzaFile);
    loaderConfig = owlLoadConfigurationLoader.loadConfig();
    curieUtil = new CurieUtil(rawConfig.getGraphConfiguration().getCuries());
}