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


Java FileURLConnection类代码示例

本文整理汇总了Java中sun.net.www.protocol.file.FileURLConnection的典型用法代码示例。如果您正苦于以下问题:Java FileURLConnection类的具体用法?Java FileURLConnection怎么用?Java FileURLConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileURLConnection类属于sun.net.www.protocol.file包,在下文中一共展示了FileURLConnection类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import sun.net.www.protocol.file.FileURLConnection; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

    File jarFile = new File(TEST_JAR_PATH);
    URL jarFileURL = jarFile.toURI().toURL();

    String jarEntryUrlString = "jar:" + jarFileURL.toString() + "!/org/apache/markt/leaks/test.txt";
    URL jarEntryUrl = new URL(jarEntryUrlString);

    // Disable caching by default for JAR URLs
    URLConnection.setDefaultUseCaches("JAR", false);

    // Check caching for a URL type other than JAR
    // File is the simplest
    FileURLConnection fileUrlConn = (FileURLConnection) jarFileURL.openConnection();
    System.out.println(fileUrlConn.getUseCaches());
    fileUrlConn.connect();
    System.out.println(fileUrlConn.getUseCaches());
    fileUrlConn.getInputStream().close();
    
    // Check JARs
    JarURLConnection jarEntryUrlConn = (JarURLConnection) jarEntryUrl.openConnection();
    System.out.println(jarEntryUrlConn.getUseCaches());
    jarEntryUrlConn.connect();
    System.out.println(jarEntryUrlConn.getUseCaches());
    jarEntryUrlConn.getInputStream().close();
}
 
开发者ID:markt-asf,项目名称:memory-leaks,代码行数:27,代码来源:TestJava9CacheFix.java

示例2: loadPackageMatches

import sun.net.www.protocol.file.FileURLConnection; //导入依赖的package包/类
private <T> void loadPackageMatches(Class<T> mask, Set<Class<T>> plugins)
        throws IOException {
    String pkg = mask.getPackage().getName();
    String pkgPath = pkg.replace('.', '/');
    Enumeration<URL> e = getResources(pkgPath);
    while (e.hasMoreElements()) {
        URL url = e.nextElement();
        URLConnection connection = url.openConnection();
        if (connection instanceof JarURLConnection) {
            processJAR(mask, plugins, (JarURLConnection) connection);
        }
        else if (connection instanceof FileURLConnection) {
            String filePath = URLDecoder.decode(url.getPath(), "UTF-8");
            String[] fileList = new File(filePath).list();
            if (fileList != null) {
                for (String file : fileList) {
                    String fileName = new File(pkgPath, file).getPath();
                    addIfMatch(mask, plugins, fileName);
                }
            }
        }
    }
}
 
开发者ID:yawlfoundation,项目名称:yawl,代码行数:24,代码来源:YPluginLoader.java

示例3: ping

import sun.net.www.protocol.file.FileURLConnection; //导入依赖的package包/类
/**
 * Found on http://stackoverflow.com/questions/3584210/preferred-java-way-to-ping-a-http-url-for-availability
 * Pings a HTTP URL. This effectively sends a HEAD request and returns <code>true</code> if the response code is in
 * the 200-399 range.
 * @param url The HTTP URL to be pinged.
 * @param timeout The timeout in millis for both the connection timeout and the response read timeout. Note that
 * the total timeout is effectively two times the given timeout.
 * @return <code>true</code> if the given HTTP URL has returned response code 200-399 on a HEAD request within the
 * given timeout, otherwise <code>false</code>.
 */
public static boolean ping(String url, int timeout) {
    try {
        URLConnection conn  = new URL(url).openConnection();
        if (conn instanceof FileURLConnection) {
            return true;
        }
        HttpURLConnection connection = (HttpURLConnection) conn;
        connection.setConnectTimeout(timeout);
        connection.setReadTimeout(timeout);
        connection.setRequestMethod("HEAD");
        int responseCode = connection.getResponseCode();
        return (200 <= responseCode && responseCode <= 399);
    } catch (IOException exception) {
        return false;
    }
}
 
开发者ID:magnetsystems,项目名称:r2m-plugin-android,代码行数:27,代码来源:ExampleChooserHelper.java

示例4: copyResourcesRecursively

import sun.net.www.protocol.file.FileURLConnection; //导入依赖的package包/类
public static void copyResourcesRecursively(URL originUrl, File destination) throws Exception {
    URLConnection urlConnection = originUrl.openConnection();
    if (urlConnection instanceof JarURLConnection) {
        copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection);
    } else if (urlConnection instanceof FileURLConnection) {
        FileUtils.copyDirectory(new File(originUrl.getPath()), destination);
    } else {
        die("Unsupported URL type: " + urlConnection);
    }
}
 
开发者ID:lebronzj,项目名称:pysonar2,代码行数:11,代码来源:$.java

示例5: copyDirectory

import sun.net.www.protocol.file.FileURLConnection; //导入依赖的package包/类
public static void copyDirectory(URL originUrl, File destination) throws IOException {
    URLConnection urlConnection = originUrl.openConnection();
    if (urlConnection instanceof JarURLConnection) {
        copyJarDirectory(destination, (JarURLConnection) urlConnection);
    } else if (urlConnection instanceof FileURLConnection) {
        FileUtils.copyDirectory(new File(originUrl.getPath()), destination);
    } else {
        throw new IOException("URLConnection[" + urlConnection.getClass().getSimpleName() +
                "] is not a recognized/implemented connection type.");
    }
}
 
开发者ID:loadtestgo,项目名称:pizzascript,代码行数:12,代码来源:ResourceUtils.java

示例6: getUrlScanner

import sun.net.www.protocol.file.FileURLConnection; //导入依赖的package包/类
/**
 * Obtains an appropriate scanning algorithm given the type of the passed in URL.
 *
 * @param url The URL for which a scanner is needed
 * @return an appropriate {@link ScanAlgorithm} instance for this URL type
 * @throws ClassNotFoundException if there is no known implementation of {@link ScanAlgorithm} for this URL type
 * @throws IOException if it was not possible to open a connection to the URL or decode its path
 */
public ScanAlgorithm getUrlScanner(URL url) throws ClassNotFoundException, IOException {
    URLConnection connection = url.openConnection();

    if (connection instanceof JarURLConnection)
        return new ArchiveScanAlgorithm(classLoader, ((JarURLConnection) connection).getJarFile());
    else if (connection instanceof FileURLConnection)
        return new DirectoryScanAlgorithm(classLoader, new File(URLDecoder.decode(url.getPath(), "UTF-8")));
    else if (connection instanceof LevelAssetsURLConnection)
        return new LevelAssetsScanAlgorithm(classLoader, ((LevelAssetsURLConnection) connection).getContainer());
    else
        throw new ClassNotFoundException("Cannot get archive scanner for URL \"" + url.getPath() + "\"");
}
 
开发者ID:fdi2-epsilon,项目名称:teams-game,代码行数:21,代码来源:PackageScanTools.java

示例7: find

import sun.net.www.protocol.file.FileURLConnection; //导入依赖的package包/类
public static Macro find(String name) throws WarpScriptException {    
  Macro macro = (Macro) macros.get(name);
  
  //
  // The macro is not (yet) known, we will attempt to load it from the
  // classpath
  //
  
  if (null == macro) {
    String rsc = name + WarpScriptMacroRepository.WARPSCRIPT_FILE_EXTENSION;
    URL url = WarpScriptMacroLibrary.class.getClassLoader().getResource(rsc);
    
    if (null != url) {
      try {
        URLConnection conn = url.openConnection();
        
        if (conn instanceof JarURLConnection) {
          //
          // This case is when the requested macro is in a jar
          //
          final JarURLConnection connection = (JarURLConnection) url.openConnection();
          final URL fileurl = connection.getJarFileURL();
          File f = new File(fileurl.toURI());
          addJar(f.getAbsolutePath(), rsc);
          macro = (Macro) macros.get(name);
        } else if (conn instanceof FileURLConnection) {
          //
          // This case is when the requested macro is in the classpath but not in a jar.
          // In this case we do not cache the parsed macro, allowing for dynamic modification.
          //
          String urlstr = url.toString();
          File root = new File(urlstr.substring(0, urlstr.length() - name.length()  - WarpScriptMacroRepository.WARPSCRIPT_FILE_EXTENSION.length()));
          macro = loadMacro(root, conn.getInputStream());
        }          
      } catch (URISyntaxException use) {
        throw new WarpScriptException("Error while loading '" + name + "'", use);
      } catch (IOException ioe) {
        throw new WarpScriptException("Error while loading '" + name + "'", ioe);
      }
    }
  }
  
  return macro;
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:45,代码来源:WarpScriptMacroLibrary.java


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