当前位置: 首页>>代码示例>>Java>>正文


Java URLConnection.setUseCaches方法代码示例

本文整理汇总了Java中java.net.URLConnection.setUseCaches方法的典型用法代码示例。如果您正苦于以下问题:Java URLConnection.setUseCaches方法的具体用法?Java URLConnection.setUseCaches怎么用?Java URLConnection.setUseCaches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URLConnection的用法示例。


在下文中一共展示了URLConnection.setUseCaches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: load

import java.net.URLConnection; //导入方法依赖的package包/类
public TemplateLoader load()
{
    try
    {
        URLConnection urlConnection = new URL(url).openConnection();
        urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
        urlConnection.setUseCaches(false);
        urlConnection.connect();
        Files.copy(urlConnection.getInputStream(), Paths.get(dest));
        ((HttpURLConnection)urlConnection).disconnect();
    } catch (IOException e)
    {
        e.printStackTrace();
    }
    return this;
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:17,代码来源:TemplateLoader.java

示例2: testFind

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * Test ModuleReader#find
 */
void testFind(ModuleReader reader, String name, byte[] expectedBytes)
    throws IOException
{
    Optional<URI> ouri = reader.find(name);
    assertTrue(ouri.isPresent());

    URL url = ouri.get().toURL();
    if (!url.getProtocol().equalsIgnoreCase("jmod")) {
        URLConnection uc = url.openConnection();
        uc.setUseCaches(false);
        try (InputStream in = uc.getInputStream()) {
            byte[] bytes = in.readAllBytes();
            assertTrue(Arrays.equals(bytes, expectedBytes));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ModuleReaderTest.java

示例3: checkJAR

import java.net.URLConnection; //导入方法依赖的package包/类
void checkJAR(boolean defaultValue) throws IOException {
    URLConnection.setDefaultUseCaches("JAR", defaultValue);
    assertEquals(URLConnection.getDefaultUseCaches("JAr"), defaultValue);

    URLConnection jarFileURLConn = jarFileURL.openConnection();
    URLConnection jarHttpURLConn = jarHttpURL.openConnection();
    assertEquals(jarFileURLConn.getUseCaches(), defaultValue);
    assertEquals(jarHttpURLConn.getUseCaches(), defaultValue);
    jarFileURLConn.setUseCaches(!defaultValue);
    jarHttpURLConn.setUseCaches(!defaultValue);
    assertEquals(jarFileURLConn.getUseCaches(), !defaultValue);
    assertEquals(jarHttpURLConn.getUseCaches(), !defaultValue);

    URLConnection.setDefaultUseCaches("JaR", !defaultValue); // case-insensitive
    assertEquals(URLConnection.getDefaultUseCaches("jAR"), !defaultValue);

    jarFileURLConn = jarFileURL.openConnection();
    jarHttpURLConn = jarHttpURL.openConnection();
    assertEquals(jarFileURLConn.getUseCaches(), !defaultValue);
    assertEquals(jarHttpURLConn.getUseCaches(), !defaultValue);
    jarFileURLConn.setUseCaches(defaultValue);
    jarHttpURLConn.setUseCaches(defaultValue);
    assertEquals(jarFileURLConn.getUseCaches(), defaultValue);
    assertEquals(jarHttpURLConn.getUseCaches(), defaultValue);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SetDefaultUseCaches.java

示例4: parse

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * Parse the content of the given URL as a provider-configuration file.
 */
private Iterator<String> parse(URL u) {
    Set<String> names = new LinkedHashSet<>(); // preserve insertion order
    try {
        URLConnection uc = u.openConnection();
        uc.setUseCaches(false);
        try (InputStream in = uc.getInputStream();
             BufferedReader r
                 = new BufferedReader(new InputStreamReader(in, "utf-8")))
        {
            int lc = 1;
            while ((lc = parseLine(u, r, lc, names)) >= 0);
        }
    } catch (IOException x) {
        fail(service, "Error accessing configuration file", x);
    }
    return names.iterator();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ServiceLoader.java

示例5: openInputStream

import java.net.URLConnection; //导入方法依赖的package包/类
public InputStream openInputStream() throws IOException
{
  // Get the inputstream from the connection to avoid duplicate calls
  // to URL.openConnection
  _lastModifiedTime = URLUtils.getLastModified(_url);
  URLConnection connection = _url.openConnection();

  // avoid URL caching
  // if we use URL caching the files which changed do not get loaded completely
  connection.setUseCaches(false);

  // In theory, should not need to close
  InputStream base = connection.getInputStream();

  if (base instanceof BufferedInputStream)
    return base;
  else
    return new BufferedInputStream(base);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:20,代码来源:URLInputStreamProvider.java

示例6: getResource

import java.net.URLConnection; //导入方法依赖的package包/类
private InputStream getResource(String filename) {
    if (filename == null) {
        throw new IllegalArgumentException("Filename cannot be null");
    }

    try {
        URL url = classLoader.getResource(filename);

        if (url == null) {
            return null;
        }

        URLConnection connection = url.openConnection();
        connection.setUseCaches(false);
        return connection.getInputStream();
    } catch (IOException ex) {
        return null;
    }
}
 
开发者ID:avaire,项目名称:avaire,代码行数:20,代码来源:Configuration.java

示例7: main

import java.net.URLConnection; //导入方法依赖的package包/类
public static void main (String[] args) throws Exception {
    setup();
    URL url = new URL("jar:file:./foo2.jar!/bar.txt");
    URLConnection urlc = url.openConnection();
    urlc.setUseCaches(false);
    InputStream is = urlc.getInputStream();
    is.read();
    is.close();
    File file = new File("foo2.jar");
    if (!file.delete()) {
        throw new RuntimeException("Could not delete foo2.jar");
    }
    if (file.exists()) {
        throw new RuntimeException("foo2.jar still exists");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:B5105410.java

示例8: getResourceAsStream

import java.net.URLConnection; //导入方法依赖的package包/类
@Override
public InputStream getResourceAsStream(
                                        String name ) {

    URL url = getResource(name);
    try {
        if (url != null) {
            URLConnection urlConnection = url.openConnection();
            urlConnection.setUseCaches(false);
            return urlConnection.getInputStream();
        } else {
            return null;
        }
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:18,代码来源:ReversedDelegationClassLoader.java

示例9: loadProperties

import java.net.URLConnection; //导入方法依赖的package包/类
public static Properties loadProperties(URL url) {
    try {
        URLConnection uc = url.openConnection();
        uc.setUseCaches(false);
        return loadProperties(uc.getInputStream());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:GUtil.java

示例10: useCachesFalseDoesNotWriteToCache

import java.net.URLConnection; //导入方法依赖的package包/类
@Test public void useCachesFalseDoesNotWriteToCache() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  URLConnection connection = openConnection(server.url("/").url());
  connection.setUseCaches(false);
  assertEquals("A", readAscii(connection));
  assertEquals("B", readAscii(openConnection(server.url("/").url())));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:ResponseCacheTest.java

示例11: useCachesFalseDoesNotWriteToCache

import java.net.URLConnection; //导入方法依赖的package包/类
@Test public void useCachesFalseDoesNotWriteToCache() throws Exception {
  server.enqueue(
      new MockResponse().addHeader("Cache-Control: max-age=60").setBody("A").setBody("A"));
  server.enqueue(new MockResponse().setBody("B"));

  URLConnection connection = urlFactory.open(server.url("/").url());
  connection.setUseCaches(false);
  assertEquals("A", readAscii(connection));
  assertEquals("B", readAscii(urlFactory.open(server.url("/").url())));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:UrlConnectionCacheTest.java

示例12: useCachesFalseDoesNotReadFromCache

import java.net.URLConnection; //导入方法依赖的package包/类
@Test public void useCachesFalseDoesNotReadFromCache() throws Exception {
  server.enqueue(
      new MockResponse().addHeader("Cache-Control: max-age=60").setBody("A").setBody("A"));
  server.enqueue(new MockResponse().setBody("B"));

  assertEquals("A", readAscii(urlFactory.open(server.url("/").url())));
  URLConnection connection = urlFactory.open(server.url("/").url());
  connection.setUseCaches(false);
  assertEquals("B", readAscii(connection));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:UrlConnectionCacheTest.java

示例13: registerAT

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * Register access transformer from jar resource
 *
 * @param url AT url from {@link Class#getResource(String)}
 */
public static void registerAT(@NotNull URL url) {
    try {
        /* Test connection */
        URLConnection urlConnection = url.openConnection();
        urlConnection.setUseCaches(false);
        urlConnection.connect();
        BlackboardKey.<List<URL>>get(BlackboardKey.AT_URLS).add(url);
        logger.debug("Registered AT {}", url);
    } catch (IOException e) {
        logger.warn("Failed to register AT {}", url);
    }
}
 
开发者ID:OrionMinecraft,项目名称:Orion,代码行数:18,代码来源:OrionAccessTransformer.java

示例14: validateProxy

import java.net.URLConnection; //导入方法依赖的package包/类
/**
	 * Validate a proxy over a given http page
	 * @param proxyAddress
	 * @param proxyPort
	 * @param testUrl the page to fetch (must include the third slash if just the host, like "http://somehost.com/"
	 * @param timeoutMillis
	 * @param username proxy basic authentication, or null when not needed
	 * @param password proxy basic authentication, or null when not needed
	 * @param userAgent to use when connecting (can be null for the default). E.g. "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0"
	 * @return the milliseconds taken to fetch the page, or -1 in case of error/timeout
	 */
	public long validateProxy(String proxyAddress, int proxyPort, URL testUrl, int timeoutMillis, String username, String password, String userAgent) {
		long start = System.currentTimeMillis();
		Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyAddress, proxyPort));
		try {
			URLConnection connection = testUrl.openConnection(proxy);
			connection.setReadTimeout(timeoutMillis);
			connection.setConnectTimeout(timeoutMillis);
			connection.setUseCaches(false);
			connection.getRequestProperty(password);
			if (userAgent!=null) {
				connection.setRequestProperty("User-Agent", userAgent);
			}
			if (username!=null && password !=null) {
				String auth = "Basic " + Base64Utils.encodeToString((username + ":" + password).getBytes());
				connection.setRequestProperty("Proxy-Connection", "Keep-Alive");
				connection.setRequestProperty("Proxy-Authorization", auth);
			}
			connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
			connection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
			connection.setRequestProperty("Accept-Encoding", "gzip, deflate");
			BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String inputLine = null;
			while ((inputLine = in.readLine()) != null); 
			in.close();
			return System.currentTimeMillis()-start;
		} catch (IOException e) {
			log.debug("Failed to validate proxy {}", proxyAddress, e);
		}
		return -1;
//		Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.10.100.100", 80));
//		HttpURLConnection connection =(HttpURLConnection)new URL("http://abc.abcd.com").openConnection(proxy);
//		connection.setDoOutput(true);
//		connection.setDoInput(true);
//		connection.setRequestProperty("Content-type", "text/xml");
//		connection.setRequestProperty("Accept", "text/xml, application/xml");
//		connection.setRequestMethod("POST");
	}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:49,代码来源:YadaHttpUtil.java

示例15: createJarInputStream

import java.net.URLConnection; //导入方法依赖的package包/类
private NonClosingJarInputStream createJarInputStream() throws IOException {
    JarURLConnection jarConn = (JarURLConnection) url.openConnection();
    URL resourceURL = jarConn.getJarFileURL();
    URLConnection resourceConn = resourceURL.openConnection();
    resourceConn.setUseCaches(false);
    return new NonClosingJarInputStream(resourceConn.getInputStream());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:UrlJar.java


注:本文中的java.net.URLConnection.setUseCaches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。