本文整理汇总了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()));
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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"));
}
示例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"));
}
示例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;
}
示例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());
}