java.net.URLConnection.setDefaultUseCaches()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(257)

本文整理了Java中java.net.URLConnection.setDefaultUseCaches()方法的一些代码示例,展示了URLConnection.setDefaultUseCaches()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLConnection.setDefaultUseCaches()方法的具体详情如下:
包路径:java.net.URLConnection
类名称:URLConnection
方法名:setDefaultUseCaches

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

  1. @Override
  2. public void setDefaultUseCaches(boolean defaultusecaches) {
  3. jarFileURLConnection.setDefaultUseCaches(defaultusecaches);
  4. }

代码示例来源:origin: openmrs/openmrs-core

  1. /**
  2. * Creates the instance for the OpenmrsClassLoader
  3. */
  4. public OpenmrsClassLoader(ClassLoader parent) {
  5. super(new URL[0], parent);
  6. if (parent instanceof OpenmrsClassLoader) {
  7. throw new IllegalArgumentException("Parent must not be OpenmrsClassLoader nor null");
  8. } else if (parent instanceof ModuleClassLoader) {
  9. throw new IllegalArgumentException("Parent must not be ModuleClassLoader");
  10. }
  11. OpenmrsClassLoaderHolder.INSTANCE = this;
  12. if (log.isDebugEnabled()) {
  13. log.debug("Creating new OpenmrsClassLoader instance with parent: {}", parent);
  14. }
  15. //disable caching so the jars aren't locked
  16. //if performance is effected, this can be disabled in favor of
  17. //copying all opened jars to a temp location
  18. //(ala org.apache.catalina.loader.WebappClassLoader antijarlocking)
  19. URLConnection urlConnection = new OpenmrsURLConnection();
  20. urlConnection.setDefaultUseCaches(false);
  21. }

代码示例来源:origin: openmrs/openmrs-core

  1. /**
  2. * Downloads the contents of a URL and copies them to a string (Borrowed from oreilly)
  3. *
  4. * @param url
  5. * @return InputStream of contents
  6. * @should return a valid input stream for old module urls
  7. */
  8. public static InputStream getURLStream(URL url) {
  9. InputStream in = null;
  10. try {
  11. URLConnection uc = url.openConnection();
  12. uc.setDefaultUseCaches(false);
  13. uc.setUseCaches(false);
  14. uc.setRequestProperty("Cache-Control", "max-age=0,no-cache");
  15. uc.setRequestProperty("Pragma", "no-cache");
  16. log.debug("Logging an attempt to connect to: " + url);
  17. in = openConnectionCheckRedirects(uc);
  18. }
  19. catch (IOException io) {
  20. log.warn("io while reading: " + url, io);
  21. }
  22. return in;
  23. }

代码示例来源:origin: org.glassfish.metro/webservices-tools

  1. @Override
  2. protected void finalize() throws Throwable {
  3. //see http://java.net/jira/browse/JAX_WS-1087
  4. if (doReset) {
  5. c.setDefaultUseCaches(true);
  6. }
  7. }
  8. }

代码示例来源:origin: stackoverflow.com

  1. public class URLConnectionNoCache extends URLConnection {
  2. protected URLConnectionNoCache(URL url) {
  3. super(url);
  4. setDefaultUseCaches(false);
  5. }
  6. public void connect() throws IOException {
  7. }
  8. }

代码示例来源:origin: ch.qos.cal10n/cal10n-api

  1. private InputStream openConnectionForUrl(URL url) throws IOException {
  2. URLConnection urlConnection = url.openConnection();
  3. urlConnection.setDefaultUseCaches(false);
  4. InputStream in = urlConnection.getInputStream();
  5. return in;
  6. }
  7. }

代码示例来源:origin: samtools/htsjdk

  1. private static URLConnection openConnection(final URL url) throws IOException{
  2. final URLConnection conn = url.openConnection();
  3. conn.setReadTimeout(3000);
  4. conn.setDefaultUseCaches(false);
  5. conn.setUseCaches(false);
  6. return conn;
  7. }

代码示例来源:origin: org.utgenome.thirdparty/picard

  1. private static URLConnection openConnection(final URL url) throws IOException{
  2. URLConnection conn = url.openConnection();
  3. conn.setReadTimeout(3000);
  4. conn.setDefaultUseCaches(false);
  5. conn.setUseCaches(false);
  6. return conn;
  7. }

代码示例来源:origin: org.seqdoop/htsjdk

  1. private static URLConnection openConnection(final URL url) throws IOException{
  2. URLConnection conn = url.openConnection();
  3. conn.setReadTimeout(3000);
  4. conn.setDefaultUseCaches(false);
  5. conn.setUseCaches(false);
  6. return conn;
  7. }

代码示例来源:origin: com.github.samtools/htsjdk

  1. private static URLConnection openConnection(final URL url) throws IOException{
  2. final URLConnection conn = url.openConnection();
  3. conn.setReadTimeout(3000);
  4. conn.setDefaultUseCaches(false);
  5. conn.setUseCaches(false);
  6. return conn;
  7. }

代码示例来源:origin: org.apache.tuscany.sca/tuscany-extensibility

  1. public InputStream run() throws IOException {
  2. URLConnection connection = url.openConnection();
  3. // TUSCANY-2539
  4. // Don't cache connections by default to stop Tuscany locking contribution jar files
  5. // done here as this is one of the first places we open a stream and the only way to
  6. // set the default is to set it on an instance of URLConnection
  7. connection.setDefaultUseCaches(false);
  8. connection.setUseCaches(false);
  9. return url.openStream();
  10. }
  11. });

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

  1. public InputStream run() throws IOException {
  2. URLConnection connection = url.openConnection();
  3. // TUSCANY-2539
  4. // Don't cache connections by default to stop Tuscany locking contribution jar files
  5. // done here as this is one of the first places we open a stream and the only way to
  6. // set the default is to set it on an instance of URLConnection
  7. connection.setDefaultUseCaches(false);
  8. connection.setUseCaches(false);
  9. return url.openStream();
  10. }
  11. });

代码示例来源:origin: wala/WALA

  1. public static Reader getStream(URL url) throws IOException {
  2. URLConnection conn = url.openConnection();
  3. conn.setDefaultUseCaches(false);
  4. conn.setUseCaches(false);
  5. return new InputStreamReader(conn.getInputStream());
  6. }
  7. }

代码示例来源:origin: com.ibm.wala/com.ibm.wala.cast.js

  1. public static Reader getStream(URL url) throws IOException {
  2. URLConnection conn = url.openConnection();
  3. conn.setDefaultUseCaches(false);
  4. conn.setUseCaches(false);
  5. return new InputStreamReader(conn.getInputStream());
  6. }
  7. }

代码示例来源:origin: caskdata/cdap

  1. /**
  2. * Utility method to set {@link URLConnection#setDefaultUseCaches(boolean)}.
  3. */
  4. public static void setDefaultUseCaches(boolean useCaches) throws IOException {
  5. LOG.info("Turning off default caching in URLConnection");
  6. final String currentDir = System.getProperty("user.dir");
  7. new File(currentDir).toURI().toURL().openConnection().setDefaultUseCaches(useCaches);
  8. }
  9. }

代码示例来源:origin: co.cask.cdap/cdap-common

  1. /**
  2. * Utility method to set {@link URLConnection#setDefaultUseCaches(boolean)}.
  3. */
  4. public static void setDefaultUseCaches(boolean useCaches) throws IOException {
  5. LOG.info("Turning off default caching in URLConnection");
  6. final String currentDir = System.getProperty("user.dir");
  7. new File(currentDir).toURI().toURL().openConnection().setDefaultUseCaches(useCaches);
  8. }
  9. }

代码示例来源:origin: stackoverflow.com

  1. URL url = new URL("jar:file://dummy.jar!/");
  2. URLConnection uConn = new URLConnection(url) {
  3. @Override
  4. public void connect() throws IOException {
  5. // NOOP
  6. }
  7. };
  8. uConn.setDefaultUseCaches(false);

代码示例来源:origin: com.github.samtools/htsjdk

  1. public HTTPHelper(URL url) {
  2. this.url = url;
  3. proxy = null;
  4. try {
  5. URLConnection conn = openConnection();
  6. conn.setDefaultUseCaches(false);
  7. } catch (IOException e) {
  8. e.printStackTrace();
  9. }
  10. }

代码示例来源:origin: org.utgenome.thirdparty/picard

  1. public HTTPHelper(URL url) {
  2. this.url = url;
  3. proxy = null;
  4. try {
  5. URLConnection conn = openConnection();
  6. conn.setDefaultUseCaches(false);
  7. } catch (IOException e) {
  8. e.printStackTrace();
  9. }
  10. }

代码示例来源:origin: mjiderhamn/classloader-leak-prevention

  1. @Override
  2. public void doOutsideClassLoader(ClassLoaderLeakPreventor preventor) {
  3. // This probably does not affect classloaders, but prevents some problems with .jar files
  4. try {
  5. // URL needs to be well-formed, but does not need to exist
  6. new URL("jar:file://dummy.jar!/").openConnection().setDefaultUseCaches(false);
  7. }
  8. catch (Exception ex) {
  9. preventor.error(ex);
  10. }
  11. }
  12. }

相关文章

URLConnection类方法