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:com.thoughtworks.go.plugin.infra.MultipleExtensionPluginWithPluginManagerIntegrationTest.java

@Before
public void setUpPluginInfrastructure() {
    pluginManager.startInfrastructure(false);

    URL multiExtensionJar = MultipleExtensionPluginWithPluginManagerIntegrationTest.class.getClassLoader()
            .getResource("defaultFiles/valid-plugin-with-multiple-extensions.jar");
    jarChangeListener.pluginJarAdded(new PluginFileDetails(new File(multiExtensionJar.getFile()), false));
}

From source file:com.k42b3.aletheia.response.html.Images.java

private String getFileName(URL url) {
    String path = url.getFile();
    int pos = path.lastIndexOf('/');

    if (pos != -1) {
        return path.substring(pos + 1);
    } else {//  ww  w.j  a v a2  s . c  om
        return path;
    }
}

From source file:cc.pp.analyzer.paoding.knife.PaodingMaker.java

private static Properties loadProperties(Properties p, String path) throws IOException {
    URL url;
    File file;//from w w  w. j  a v a2s  .com
    String absolutePath;
    InputStream in;
    // ifexists??
    boolean skipWhenNotExists = false;
    if (path.startsWith("ifexists:")) {
        skipWhenNotExists = true;
        path = path.substring("ifexists:".length());
    }
    if (path.startsWith("classpath:")) {
        path = path.substring("classpath:".length());
        url = getClassLoader().getResource(path);
        if (url == null) {
            if (skipWhenNotExists) {
                return p;
            }
            throw new FileNotFoundException("Not found " + path + " in classpath.");
        }
        file = new File(url.getFile());
        in = url.openStream();
    } else {
        if (path.startsWith("dic-home:")) {
            File dicHome = new File(getDicHome(p));
            path = path.substring("dic-home:".length());
            file = new File(dicHome, path);
        } else {
            file = new File(path);
        }
        if (skipWhenNotExists && !file.exists()) {
            return p;
        }
        in = new FileInputStream(file);
    }
    absolutePath = file.getAbsolutePath();
    p.load(in);
    in.close();
    String lastModifieds = p.getProperty("paoding.analysis.properties.lastModifieds");
    String files = p.getProperty("paoding.analysis.properties.files");
    String absolutePaths = p.getProperty("paoding.analysis.properties.files.absolutepaths");
    if (lastModifieds == null) {
        p.setProperty("paoding.dic.properties.path", path);
        lastModifieds = String.valueOf(getFileLastModified(file));
        files = path;
        absolutePaths = absolutePath;
    } else {
        lastModifieds = lastModifieds + ";" + getFileLastModified(file);
        files = files + ";" + path;
        absolutePaths = absolutePaths + ";" + absolutePath;
    }
    p.setProperty("paoding.analysis.properties.lastModifieds", lastModifieds);
    p.setProperty("paoding.analysis.properties.files", files);
    p.setProperty("paoding.analysis.properties.files.absolutepaths", absolutePaths);
    String importsValue = p.getProperty("paoding.imports");
    if (importsValue != null) {
        p.remove("paoding.imports");
        String[] imports = importsValue.split(";");
        for (int i = 0; i < imports.length; i++) {
            loadProperties(p, imports[i]);
        }
    }
    return p;
}

From source file:org.openeos.attachments.internal.dao.AttachmentServiceImpl.java

@Override
@Transactional//ww  w . jav  a 2 s. c o m
public <T> Attachment attachFile(Class<T> entityClass, T entity, String attachmentType, URL url) {
    try {
        InputStream is = url.openStream();
        Attachment result = attachFile(entityClass, entity, attachmentType,
                FilenameUtils.getName(url.getPath()), getMimeType(url.getFile()), is);
        is.close();
        return result;
    } catch (IOException e) {
        throw new RuntimeException("Unable to set content to attachement model object", e);
    }
}

From source file:org.openeos.attachments.internal.dao.AttachmentServiceImpl.java

@Override
public Attachment attachFile(Class<?> entityClass, String entityId, String attachmentType, URL url) {
    try {//from  w  ww  .j  a  v  a2 s  .  c o m
        InputStream is = url.openStream();
        Attachment result = attachFile(entityClass, entityId, attachmentType,
                FilenameUtils.getName(url.getPath()), getMimeType(url.getFile()), is);
        is.close();
        return result;
    } catch (IOException e) {
        throw new RuntimeException("Unable to set content to attachement model object", e);
    }
}

From source file:de.chdev.artools.loga.lang.KeywordLoader.java

private List<Configuration> getAllConfigurations() {
    List<Configuration> localConfigurationList = new ArrayList<Configuration>();
    try {//from w  ww . j a  v  a2s  .c  o m
        // File path = new File("./config");

        // File[] listFiles = path.listFiles();

        FilenameFilter filter = new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                if (name.startsWith("keywords")) {
                    return true;
                } else {
                    return false;
                }
            }

        };

        /* TESTCODE */
        // Bundle location = Activator.getDefault().getBundle();
        // Enumeration entryPaths =
        // Activator.getDefault().getBundle().getEntryPaths("/");
        URL configEntry = Activator.getDefault().getBundle().getEntry("config");
        URL configPath = FileLocator.resolve(configEntry);
        File path = new File(configPath.getFile());
        // String[] list2 = resFile.list();
        // File file = new ConfigurationScope().getLocation().toFile();
        // String[] list = file.list();
        // IProject project = root.getProject();
        // IFolder files = project.getFolder("");
        // IResource[] members = files.members();
        /* TESTCODE END */

        String[] fileNames = path.list(filter);
        supportedLanguages.clear();

        for (String fileName : fileNames) {
            File fileObj = new File(path, fileName);
            CompositeConfiguration configuration = new CompositeConfiguration();

            PropertiesConfiguration keywords = new PropertiesConfiguration(fileObj);
            configuration.addConfiguration(keywords);
            configuration.addProperty("filename", fileName);
            localConfigurationList.add(configuration);
            supportedLanguages.add(configuration.getString("language.name"));
            nameConfigMap.put(configuration.getString("language.name"), configuration);
        }

        // for (String fileName : fileNames) {
        // CompositeConfiguration configuration = new
        // CompositeConfiguration();
        //
        // PropertiesConfiguration keywords = new PropertiesConfiguration(
        // "config/" + fileName);
        // configuration.addConfiguration(keywords);
        // configuration.addProperty("filename", fileName);
        // localConfigurationList.add(configuration);
        // }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return localConfigurationList;
}

From source file:com.krikelin.spotifysource.AppInstaller.java

protected File downloadJar(URL file) throws IOException {
    // TODO FIx this later!!!!

    // Download the Jar file {

    InputStream in = file.openStream();
    File c = new File(SPContainer.EXTENSION_DIR + "\\jar\\"
            + file.getFile().split("/")[file.getFile().split("/").length - 1]);
    c.createNewFile();/*from   w  ww . j a  va  2  s.  c o  m*/
    FileOutputStream fos = new FileOutputStream(c);

    this.app_jar = c;
    return c;
    // }

}

From source file:com.redhat.rhn.frontend.servlets.RhnHttpServletRequest.java

/**
 * {@inheritDoc}//w ww  .  java 2 s .c o  m
 */
public StringBuffer getRequestURL() {
    try {
        URL u = new URL(super.getRequestURL().toString());
        StringBuffer sb = new StringBuffer(
                new URL(getProtocol(), getServerName(), u.getPort(), u.getFile()).toExternalForm());
        return sb;
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Bad argument when creating URL");
    }
}

From source file:info.novatec.testit.livingdoc.maven.plugin.SpecificationRunnerMojo.java

private boolean containsLivingDocCore(List<URL> urls) {

    for (Iterator<URL> it = urls.iterator(); it.hasNext();) {
        URL url = it.next();

        if (url.getFile().indexOf("livingdoc-core") != -1 && url.getFile().endsWith(".jar")) {
            return true;
        }//from   w  ww.  jav a  2 s .  c  om
    }

    return false;
}

From source file:business.UploadTests.java

@Test(groups = "upload", dependsOnMethods = "createRequest")
public void uploadFileNoMimetype() throws IOException {
    UserAuthenticationToken requester = getRequester();
    SecurityContext securityContext = SecurityContextHolder.getContext();
    securityContext.setAuthentication(requester);

    RequestRepresentation representation = requestController.getRequestById(requester, processInstanceId);
    log.info("Status: " + representation.getStatus());
    int attachmentCount = representation.getAttachments().size();

    ClassLoader classLoader = getClass().getClassLoader();
    URL resource = classLoader.getResource("test/Utrecht_Oude_Gracht_Hamburgerbrug_(LOC).jpg");
    InputStream input = resource.openStream();
    MultipartFile file = new MockMultipartFile(resource.getFile(), input);
    //MultipartFile file = new MockMultipartFile(resource.getFile(), resource.getFile().toString(), "undefined", input);

    Integer flowTotalChunks = 1;// ww w.j a v a  2s. c o m
    Integer flowChunkNumber = 1;
    String flowIdentifier = "flow";

    representation = requestController.uploadRequestAttachment(requester, processInstanceId, resource.getFile(),
            flowTotalChunks, flowChunkNumber, flowIdentifier, file);

    assertEquals(attachmentCount + 1, representation.getAttachments().size());
    printFiles(representation.getAttachments());

    SecurityContextHolder.clearContext();
}