Example usage for java.net URL hashCode

List of usage examples for java.net URL hashCode

Introduction

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

Prototype

int hashCode

To view the source code for java.net URL hashCode.

Click Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    try {/* w  ww  .ja  va 2  s.c  o  m*/
        URL url = new URL("http://www.java2s.com");
        System.out.println("URL is " + url.hashCode());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.redhat.rhn.testing.TestUtils.java

/**
 * method to find a file relative to the calling class.  primarily
 * useful when writing tests that need access to external data.
 * this lets you put the data relative to the test class file.
 *
 * @param path the path, relative to caller's location
 * @return URL a URL referencing the file
 * @throws ClassNotFoundException if the calling class can not be found
 * (i.e., should not happen)//ww w  .  j  av  a2s .  c o m
 * @throws IOException if the specified file in an archive (eg. jar) and
 * it cannot be copied to a temporary location
 */
public static URL findTestData(String path) throws ClassNotFoundException, IOException {
    Throwable t = new Throwable();
    StackTraceElement[] ste = t.getStackTrace();

    String className = ste[1].getClassName();
    Class clazz = Class.forName(className);

    URL ret = clazz.getResource(path);

    if (ret.toString().contains("!")) { // file is from an archive
        String tempPath = "/tmp/" + filePrefix + ret.hashCode();
        InputStream input = clazz.getResourceAsStream(path);

        OutputStream output = new FileOutputStream(tempPath);
        IOUtils.copy(input, output);

        return new File(tempPath).toURI().toURL();
    }

    return ret;
}

From source file:com.manning.blogapps.chapter11.rome.DiskFeedInfoCache.java

public void setFeedInfo(URL url, SyndFeedInfo feedInfo) {

    String fileName = cachePath + File.separator + "feed_" + url.hashCode();
    FileOutputStream fos;//from  ww w . java  2s. c o m
    try {
        fos = new FileOutputStream(fileName);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(feedInfo);
        fos.flush();
        fos.close();
    } catch (Exception e) {
        // Error writing to cahce is fatal
        throw new RuntimeException("Attempting to write to cache", e);
    }
}

From source file:com.manning.blogapps.chapter11.rome.DiskFeedInfoCache.java

public SyndFeedInfo getFeedInfo(URL url) {
    SyndFeedInfo info = null;/*  ww  w  . ja  v  a2  s. c  o  m*/
    String fileName = cachePath + File.separator + "feed_" + url.hashCode();
    FileInputStream fis;
    try {
        fis = new FileInputStream(fileName);
        ObjectInputStream ois = new ObjectInputStream(fis);
        info = (SyndFeedInfo) ois.readObject();
        fis.close();
    } catch (FileNotFoundException fnfe) {
        logger.debug("Cache miss for " + url.toString());
    } catch (ClassNotFoundException cnfe) {
        // Error writing to cahce is fatal
        throw new RuntimeException("Attempting to read from cache", cnfe);
    } catch (IOException fnfe) {
        // Error writing to cahce is fatal
        throw new RuntimeException("Attempting to read from cache", fnfe);
    }
    if (info == null)
        logger.info("Cache MISS!");
    return info;
}

From source file:org.jboss.web.loadbalancer.scheduler.SchedulerBase.java

protected void setStickyCookie(URL host, HttpServletRequest request, HttpServletResponse response) {
    Cookie cookie = new Cookie(stickyCookieName, Integer.toString(host.hashCode()));
    cookie.setPath("/");
    cookie.setMaxAge(-1);//from   w ww .  j a  v a2 s.c  o m
    response.addCookie(cookie);
}

From source file:org.jboss.web.loadbalancer.scheduler.SchedulerBase.java

/**
 * Find the sticky host for the given request
 * @param request The request we want to find the sticky host for
 * @return null=host not found, otherwise the sticky host URL for this request
 *//*  w  w  w  . j av a  2s. com*/
protected URL findStickyHost(HttpServletRequest request) {
    URL host = null;
    if (useStickySession) {
        Cookie[] cookies = request.getCookies();

        for (int i = 0; cookies != null && i < cookies.length; ++i) {
            Cookie cookie = cookies[i];

            if (cookie.getName().equals(stickyCookieName)) {
                log.debug("Sticky Cookie found!");
                int cookieHash = Integer.parseInt(cookie.getValue());
                Iterator iter = hostsUp.iterator();

                while (iter.hasNext()) {
                    URL url = (URL) iter.next();
                    if (url.hashCode() == cookieHash) {
                        host = url;
                        if (log.isDebugEnabled()) {
                            log.debug("Sticky Cookie sticks client to host with URL " + url.toExternalForm());
                        }
                        break;
                    }
                }
                break;
            }
        }
        return host;
    } else {
        return null;
    }
}

From source file:sapience.features.streams.kml.KMLRetriever.java

/**
 * Tries to fetch a KML file from the given URL. If it points to a zipped KML, it will
 * be extracted. Makes use of caching./*from ww  w.  j  av a  2s  .c  o  m*/
 * 
 * @param url
 * @return
 * @throws IOException
 */
public File fetch(URL url) throws IOException {
    StringBuffer pre = new StringBuffer(System.getProperty("java.io.tmpdir"));
    if (!(pre.toString().endsWith("/") || pre.toString().endsWith("\\")))
        pre.append(System.getProperty("file.separator"));
    pre.append("cached");
    pre.append(url.hashCode());

    File kml = new File(pre.toString() + ".kml");

    if (kml.createNewFile()) {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = fetchStream(url);
            out = new FileOutputStream(kml);
            IOUtils.copy(in, out);
        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
    }
    return kml;
}

From source file:sapience.features.streams.util.Cache.java

/**
 * Tries to fetch a KML file from the given URL. If it points to a zipped KML, it will
 * be extracted. Makes use of caching.// w  w  w . ja  v a2  s.com
 * 
 * @param url
 * @return
 * @throws IOException
 */
public File fetch(URL url) throws IOException {

    StringBuffer pre = new StringBuffer(System.getProperty("java.io.tmpdir"));
    if (!(pre.toString().endsWith("/") || pre.toString().endsWith("\\")))
        pre.append(System.getProperty("file.separator"));
    pre.append("cached");
    pre.append(url.hashCode());

    File kml = new File(pre.toString().concat(".temp"));

    if (kml.createNewFile()) {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = fetchStream(url);
            out = new FileOutputStream(kml);
            IOUtils.copy(in, out);
        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
    }
    return kml;
}