Example usage for java.net URLConnection getDefaultUseCaches

List of usage examples for java.net URLConnection getDefaultUseCaches

Introduction

In this page you can find the example usage for java.net URLConnection getDefaultUseCaches.

Prototype

public boolean getDefaultUseCaches() 

Source Link

Document

Returns the default value of a URLConnection 's useCaches flag.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    uc.setDefaultUseCaches(true);//from   w w w  .ja v  a  2  s .  co m
    System.out.println(uc.getDefaultUseCaches());
}

From source file:org.jvnet.hudson.test.JenkinsRule.java

/**
 * Override to set up your specific external resource.
 * @throws Throwable if setup fails (which will disable {@code after}
 *//*from   w w w .  j av a2 s  .  c  om*/
public void before() throws Throwable {
    if (Functions.isWindows()) {
        // JENKINS-4409.
        // URLConnection caches handles to jar files by default,
        // and it prevents delete temporary directories on Windows.
        // Disables caching here.
        // Though defaultUseCache is a static field,
        // its setter and getter are provided as instance methods.
        URLConnection aConnection = new File(".").toURI().toURL().openConnection();
        origDefaultUseCache = aConnection.getDefaultUseCaches();
        aConnection.setDefaultUseCaches(false);
    }

    // Not ideal (https://github.com/junit-team/junit/issues/116) but basically works.
    if (Boolean.getBoolean("ignore.random.failures")) {
        RandomlyFails rf = testDescription.getAnnotation(RandomlyFails.class);
        if (rf != null) {
            throw new AssumptionViolatedException("Known to randomly fail: " + rf.value());
        }
    }

    env = new TestEnvironment(testDescription);
    env.pin();
    recipe();
    AbstractProject.WORKSPACE.toString();
    User.clear();

    try {
        jenkins = hudson = newHudson();
    } catch (Exception e) {
        // if Hudson instance fails to initialize, it leaves the instance field non-empty and break all the rest of the tests, so clean that up.
        Field f = Jenkins.class.getDeclaredField("theInstance");
        f.setAccessible(true);
        f.set(null, null);
        throw e;
    }
    jenkins.setNoUsageStatistics(true); // collecting usage stats from tests are pointless.

    jenkins.setCrumbIssuer(new TestCrumbIssuer());

    jenkins.servletContext.setAttribute("app", jenkins);
    jenkins.servletContext.setAttribute("version", "?");
    WebAppMain.installExpressionFactory(new ServletContextEvent(jenkins.servletContext));

    // set a default JDK to be the one that the harness is using.
    jenkins.getJDKs().add(new JDK("default", System.getProperty("java.home")));

    configureUpdateCenter();

    // expose the test instance as a part of URL tree.
    // this allows tests to use a part of the URL space for itself.
    jenkins.getActions().add(this);

    JenkinsLocationConfiguration.get().setUrl(getURL().toString());

    setUpTimeout();
}