Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:cc.aileron.commons.resource.ResourceConvertUtils.java

/**
 * java.net.URL? Resource ?/*from  w  ww  . java 2s  .c o m*/
 * 
 * @param url
 * @return Resource
 * @throws FileSystemException
 * @throws ResourceNotFoundException
 */
public static Resource convertUrl(final URL url) throws FileSystemException, ResourceNotFoundException {
    return ResourceUtils.resource(ResourceLoaders.manager.resolveFile(url.toString()).getContent());
}

From source file:com.cdancy.artifactory.rest.util.ArtifactoryUtils.java

public static String getBasePath(URL url, String endpoint) {
    String pathFromUrl = url.toString().replaceFirst(endpoint, "");
    if (url.getQuery() != null) {
        int index = url.getQuery().lastIndexOf("?");
        if (index != -1) {
            pathFromUrl = url.getQuery().substring(0, index);
        }//from ww  w .  jav  a2  s.c o  m
    }

    return pathFromUrl;
}

From source file:com.intuit.cto.selfservice.service.Util.java

/**
 * Extract files from a package on the classpath into a directory.
 * @param packagePath e.g. "com/stuff" (always forward slash not backslash, never dot)
 * @param toDir directory to extract to//from   w w w.  j  a v  a 2  s .c om
 * @return int the number of files copied
 * @throws java.io.IOException if something goes wrong, including if nothing was found on classpath
 */
public static int extractFromClasspathToFile(String packagePath, File toDir) throws IOException {
    String locationPattern = "classpath*:" + packagePath + "/**";
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resourcePatternResolver.getResources(locationPattern);
    if (resources.length == 0) {
        throw new IOException("Nothing found at " + locationPattern);
    }
    int counter = 0;
    for (Resource resource : resources) {
        if (resource.isReadable()) { // Skip hidden or system files
            URL url = resource.getURL();
            String path = url.toString();
            if (!path.endsWith("/")) { // Skip directories
                int p = path.lastIndexOf(packagePath) + packagePath.length();
                path = path.substring(p);
                File targetFile = new File(toDir, path);
                long len = resource.contentLength();
                if (!targetFile.exists() || targetFile.length() != len) { // Only copy new files
                    FileUtils.copyURLToFile(url, targetFile);
                    counter++;
                }
            }
        }
    }
    logger.info("Unpacked {} files from {} to {}", new Object[] { counter, locationPattern, toDir });
    return counter;
}

From source file:at.beris.virtualfile.util.UrlUtils.java

public static URL newUrlReplacePath(URL context, String path) throws IOException {
    String contextUrlString = context.toString();
    String newUrlString = contextUrlString.substring(0, contextUrlString.length() - context.getPath().length());
    newUrlString += path;/*  w  w  w . j  av  a 2 s .  c  o  m*/
    return new URL(newUrlString);
}

From source file:com.tesora.dve.common.PELogUtils.java

private static Attributes readManifestFile() throws PEException {
    try {/*from w  w w . j  a v  a  2  s.c om*/
        Enumeration<URL> resources = PELogUtils.class.getClassLoader().getResources(MANIFEST_FILE_NAME);

        Attributes attrs = new Attributes();
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            if (url.toString().contains(CORE_PROJECT_NAME)) {
                Manifest manifest = new Manifest(url.openStream());
                attrs = manifest.getMainAttributes();
                break;
            }
        }
        return attrs;
    } catch (Exception e) {
        throw new PEException("Error retrieving build manifest", e);
    }
}

From source file:no.norrs.projects.andronary.service.utils.HttpUtil.java

public static HttpResponse PUT(final URL uri, List<NameValuePair> data) throws IOException {
    return PUT(uri.toString(), data);
}

From source file:com.adamrosenfield.wordswithcrosses.net.AbstractDownloader.java

public static String scrubUrl(URL url) {
    return scrubUrl(url.toString());
}

From source file:no.norrs.projects.andronary.service.utils.HttpUtil.java

public static HttpResponse POST(final URL uri, List<NameValuePair> data) throws IOException {
    return POST(uri.toString(), data);
}

From source file:com.linkedin.pinot.common.TestUtils.java

public static String getFileFromResourceUrl(URL resourceUrl) {
    System.out.println(resourceUrl);
    // Check if we need to extract the resource to a temporary directory
    String resourceUrlStr = resourceUrl.toString();
    if (resourceUrlStr.contains("jar!")) {
        try {/*ww  w  .  j av  a 2  s .c  om*/
            String extension = resourceUrlStr.substring(resourceUrlStr.lastIndexOf('.'));
            File tempFile = File.createTempFile("pinot-test-temp", extension);
            LOGGER.info("Extractng from " + resourceUrlStr + " to " + tempFile.getAbsolutePath());
            System.out.println("Extractng from " + resourceUrlStr + " to " + tempFile.getAbsolutePath());
            FileUtils.copyURLToFile(resourceUrl, tempFile);
            return tempFile.getAbsolutePath();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        System.out.println("Not extracting plain file " + resourceUrl);
        return resourceUrl.getFile();
    }
}

From source file:com.worldline.easycukes.commons.helpers.FileHelper.java

/**
 * Downloads some content from an URL to a specific directory
 *
 * @param from a {@link String} representation of the URL on which the
 *             content should be downloaded
 * @param to   the path on which the content should be downloaded
 * @throws IOException if anything's going wrong while downloading the content to
 *                     the specified directory
 *///from   w ww . ja v a2 s .co m
public static void download(@NonNull String from, @NonNull String to) throws IOException {
    final URL url = new URL(from);
    log.debug("Downloading from: " + url.toString() + " to: " + to.toString());
    final String zipFilePath = to + url.getFile().substring(url.getFile().lastIndexOf('/'));
    FileUtils.copyURLToFile(url, new File(zipFilePath), 30000, 300000);
}