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


Java URLConnection.setDefaultUseCaches方法代码示例

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


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

示例1: main

import java.net.URLConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
    int len = conn.getContentLength();
    byte[] data = new byte[len];
    InputStream is = conn.getInputStream();
    is.read(data);
    is.close();
    conn.setDefaultUseCaches(false);
    File jar = File.createTempFile("B7050028", ".jar");
    jar.deleteOnExit();
    OutputStream os = new FileOutputStream(jar);
    ZipOutputStream zos = new ZipOutputStream(os);
    ZipEntry ze = new ZipEntry("B7050028.class");
    ze.setMethod(ZipEntry.STORED);
    ze.setSize(len);
    CRC32 crc = new CRC32();
    crc.update(data);
    ze.setCrc(crc.getValue());
    zos.putNextEntry(ze);
    zos.write(data, 0, len);
    zos.closeEntry();
    zos.finish();
    zos.close();
    os.close();
    System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:B7050028.java

示例2: 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

示例3: defaultUseCachesSetsInitialValueOnly

import java.net.URLConnection; //导入方法依赖的package包/类
@Test public void defaultUseCachesSetsInitialValueOnly() throws Exception {
  URL url = new URL("http://localhost/");
  URLConnection c1 = openConnection(url);
  URLConnection c2 = openConnection(url);
  assertTrue(c1.getDefaultUseCaches());
  c1.setDefaultUseCaches(false);
  try {
    assertTrue(c1.getUseCaches());
    assertTrue(c2.getUseCaches());
    URLConnection c3 = openConnection(url);
    assertFalse(c3.getUseCaches());
  } finally {
    c1.setDefaultUseCaches(true);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:ResponseCacheTest.java

示例4: defaultUseCachesSetsInitialValueOnly

import java.net.URLConnection; //导入方法依赖的package包/类
@Test public void defaultUseCachesSetsInitialValueOnly() throws Exception {
  URL url = new URL("http://localhost/");
  URLConnection c1 = urlFactory.open(url);
  URLConnection c2 = urlFactory.open(url);
  assertTrue(c1.getDefaultUseCaches());
  c1.setDefaultUseCaches(false);
  try {
    assertTrue(c1.getUseCaches());
    assertTrue(c2.getUseCaches());
    URLConnection c3 = urlFactory.open(url);
    assertFalse(c3.getUseCaches());
  } finally {
    c1.setDefaultUseCaches(true);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:UrlConnectionCacheTest.java

示例5: checkHTTP

import java.net.URLConnection; //导入方法依赖的package包/类
void checkHTTP() throws IOException {
    // check default default is true
    URLConnection httpURLConn = httpURL.openConnection();
    assertTrue(httpURLConn.getDefaultUseCaches());

    // set default for http to false and check
    URLConnection.setDefaultUseCaches("HTTP", false);

    httpURLConn = httpURL.openConnection();
    assertTrue(httpURLConn.getDefaultUseCaches());
    assertFalse(httpURLConn.getUseCaches());
    assertFalse(URLConnection.getDefaultUseCaches("http"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:SetDefaultUseCaches.java

示例6: checkFile

import java.net.URLConnection; //导入方法依赖的package包/类
void checkFile() throws IOException {
    URLConnection fileURLConn = fileURL.openConnection();
    assertTrue(fileURLConn.getDefaultUseCaches());

    // set default default to false and check other values the same
    fileURLConn.setDefaultUseCaches(false);
    fileURLConn.setDefaultUseCaches("fiLe", true);
    assertFalse(fileURLConn.getDefaultUseCaches());
    assertTrue(URLConnection.getDefaultUseCaches("fiLE"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:SetDefaultUseCaches.java

示例7: openConnection

import java.net.URLConnection; //导入方法依赖的package包/类
private static URLConnection openConnection(final URL url) throws IOException {
    URLConnection conn = url.openConnection();
    conn.setReadTimeout(TIMEOUT);
    conn.setDefaultUseCaches(false);
    conn.setUseCaches(false);
    return conn;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:8,代码来源:FastaUtils.java

示例8: getInputStream

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * Gets an input stream for the specified resource.
 *
 * @param filename The filename of a resource within this
 *     collection of data.  If this object represents a directory
 *     then the provided filename should be relative towards the
 *     path of the directory.  In case of a compressed archive it
 *     should be the path within the archive.
 * @return An {@code InputStream} to read the resource with.
 * @exception IOException if an error occurs
 */
public BufferedInputStream getInputStream(String filename) throws IOException {
    final URLConnection connection = getURI(filename).toURL()
        .openConnection();
    connection.setDefaultUseCaches(false);
    return new BufferedInputStream(connection.getInputStream());
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:18,代码来源:FreeColDataFile.java


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