本文整理了Java中java.net.URLConnection.setDefaultUseCaches()
方法的一些代码示例,展示了URLConnection.setDefaultUseCaches()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLConnection.setDefaultUseCaches()
方法的具体详情如下:
包路径:java.net.URLConnection
类名称:URLConnection
方法名:setDefaultUseCaches
[英]Sets the default value for the flag indicating whether this connection allows to use caches. Existing URLConnections are unaffected.
[中]设置标志的默认值,该标志指示此连接是否允许使用缓存。现有的URL连接不受影响。
代码示例来源:origin: robovm/robovm
@Override
public void setDefaultUseCaches(boolean defaultusecaches) {
jarFileURLConnection.setDefaultUseCaches(defaultusecaches);
}
代码示例来源:origin: openmrs/openmrs-core
/**
* Creates the instance for the OpenmrsClassLoader
*/
public OpenmrsClassLoader(ClassLoader parent) {
super(new URL[0], parent);
if (parent instanceof OpenmrsClassLoader) {
throw new IllegalArgumentException("Parent must not be OpenmrsClassLoader nor null");
} else if (parent instanceof ModuleClassLoader) {
throw new IllegalArgumentException("Parent must not be ModuleClassLoader");
}
OpenmrsClassLoaderHolder.INSTANCE = this;
if (log.isDebugEnabled()) {
log.debug("Creating new OpenmrsClassLoader instance with parent: {}", parent);
}
//disable caching so the jars aren't locked
//if performance is effected, this can be disabled in favor of
//copying all opened jars to a temp location
//(ala org.apache.catalina.loader.WebappClassLoader antijarlocking)
URLConnection urlConnection = new OpenmrsURLConnection();
urlConnection.setDefaultUseCaches(false);
}
代码示例来源:origin: openmrs/openmrs-core
/**
* Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)
*
* @param url
* @return InputStream of contents
* @should return a valid input stream for old module urls
*/
public static InputStream getURLStream(URL url) {
InputStream in = null;
try {
URLConnection uc = url.openConnection();
uc.setDefaultUseCaches(false);
uc.setUseCaches(false);
uc.setRequestProperty("Cache-Control", "max-age=0,no-cache");
uc.setRequestProperty("Pragma", "no-cache");
log.debug("Logging an attempt to connect to: " + url);
in = openConnectionCheckRedirects(uc);
}
catch (IOException io) {
log.warn("io while reading: " + url, io);
}
return in;
}
代码示例来源:origin: org.glassfish.metro/webservices-tools
@Override
protected void finalize() throws Throwable {
//see http://java.net/jira/browse/JAX_WS-1087
if (doReset) {
c.setDefaultUseCaches(true);
}
}
}
代码示例来源:origin: stackoverflow.com
public class URLConnectionNoCache extends URLConnection {
protected URLConnectionNoCache(URL url) {
super(url);
setDefaultUseCaches(false);
}
public void connect() throws IOException {
}
}
代码示例来源:origin: ch.qos.cal10n/cal10n-api
private InputStream openConnectionForUrl(URL url) throws IOException {
URLConnection urlConnection = url.openConnection();
urlConnection.setDefaultUseCaches(false);
InputStream in = urlConnection.getInputStream();
return in;
}
}
代码示例来源:origin: samtools/htsjdk
private static URLConnection openConnection(final URL url) throws IOException{
final URLConnection conn = url.openConnection();
conn.setReadTimeout(3000);
conn.setDefaultUseCaches(false);
conn.setUseCaches(false);
return conn;
}
代码示例来源:origin: org.utgenome.thirdparty/picard
private static URLConnection openConnection(final URL url) throws IOException{
URLConnection conn = url.openConnection();
conn.setReadTimeout(3000);
conn.setDefaultUseCaches(false);
conn.setUseCaches(false);
return conn;
}
代码示例来源:origin: org.seqdoop/htsjdk
private static URLConnection openConnection(final URL url) throws IOException{
URLConnection conn = url.openConnection();
conn.setReadTimeout(3000);
conn.setDefaultUseCaches(false);
conn.setUseCaches(false);
return conn;
}
代码示例来源:origin: com.github.samtools/htsjdk
private static URLConnection openConnection(final URL url) throws IOException{
final URLConnection conn = url.openConnection();
conn.setReadTimeout(3000);
conn.setDefaultUseCaches(false);
conn.setUseCaches(false);
return conn;
}
代码示例来源:origin: org.apache.tuscany.sca/tuscany-extensibility
public InputStream run() throws IOException {
URLConnection connection = url.openConnection();
// TUSCANY-2539
// Don't cache connections by default to stop Tuscany locking contribution jar files
// done here as this is one of the first places we open a stream and the only way to
// set the default is to set it on an instance of URLConnection
connection.setDefaultUseCaches(false);
connection.setUseCaches(false);
return url.openStream();
}
});
代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime
public InputStream run() throws IOException {
URLConnection connection = url.openConnection();
// TUSCANY-2539
// Don't cache connections by default to stop Tuscany locking contribution jar files
// done here as this is one of the first places we open a stream and the only way to
// set the default is to set it on an instance of URLConnection
connection.setDefaultUseCaches(false);
connection.setUseCaches(false);
return url.openStream();
}
});
代码示例来源:origin: wala/WALA
public static Reader getStream(URL url) throws IOException {
URLConnection conn = url.openConnection();
conn.setDefaultUseCaches(false);
conn.setUseCaches(false);
return new InputStreamReader(conn.getInputStream());
}
}
代码示例来源:origin: com.ibm.wala/com.ibm.wala.cast.js
public static Reader getStream(URL url) throws IOException {
URLConnection conn = url.openConnection();
conn.setDefaultUseCaches(false);
conn.setUseCaches(false);
return new InputStreamReader(conn.getInputStream());
}
}
代码示例来源:origin: caskdata/cdap
/**
* Utility method to set {@link URLConnection#setDefaultUseCaches(boolean)}.
*/
public static void setDefaultUseCaches(boolean useCaches) throws IOException {
LOG.info("Turning off default caching in URLConnection");
final String currentDir = System.getProperty("user.dir");
new File(currentDir).toURI().toURL().openConnection().setDefaultUseCaches(useCaches);
}
}
代码示例来源:origin: co.cask.cdap/cdap-common
/**
* Utility method to set {@link URLConnection#setDefaultUseCaches(boolean)}.
*/
public static void setDefaultUseCaches(boolean useCaches) throws IOException {
LOG.info("Turning off default caching in URLConnection");
final String currentDir = System.getProperty("user.dir");
new File(currentDir).toURI().toURL().openConnection().setDefaultUseCaches(useCaches);
}
}
代码示例来源:origin: stackoverflow.com
URL url = new URL("jar:file://dummy.jar!/");
URLConnection uConn = new URLConnection(url) {
@Override
public void connect() throws IOException {
// NOOP
}
};
uConn.setDefaultUseCaches(false);
代码示例来源:origin: com.github.samtools/htsjdk
public HTTPHelper(URL url) {
this.url = url;
proxy = null;
try {
URLConnection conn = openConnection();
conn.setDefaultUseCaches(false);
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: org.utgenome.thirdparty/picard
public HTTPHelper(URL url) {
this.url = url;
proxy = null;
try {
URLConnection conn = openConnection();
conn.setDefaultUseCaches(false);
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: mjiderhamn/classloader-leak-prevention
@Override
public void doOutsideClassLoader(ClassLoaderLeakPreventor preventor) {
// This probably does not affect classloaders, but prevents some problems with .jar files
try {
// URL needs to be well-formed, but does not need to exist
new URL("jar:file://dummy.jar!/").openConnection().setDefaultUseCaches(false);
}
catch (Exception ex) {
preventor.error(ex);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!