zoukankan      html  css  js  c++  java
  • AnyHandler

    package cc.vcode.main;
    
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.net.URLStreamHandler;
    import java.net.URLStreamHandlerFactory;
    
    import cc.vcode.torrent.TOTorrent;
    import cc.vcode.torrent.TOTorrentFactory;
    
    public class TestMain {
    
        public static void main(String[] args) throws Exception {
            register();
            test01();
        }
    
        public static void test01() throws Exception {
            File f = new File("D:\opt\nodejs\ubuntu.torrent");
            String tarPathString = "VCode";
            TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedFile(f, tarPathString);
            torrent.serialiseToBEncodedFile(new File("D:\opt\nodejs\ubuntu-target.torrent"));
            System.out.println("success!");
        }
    
        public static void register() throws MalformedURLException {
            URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
    
                @Override
                public URLStreamHandler createURLStreamHandler(String protocol) {
                    return new AnyHandler();
                }
            });
        }
    }
    
    class AnyHandler extends URLStreamHandler {
    
        /**
         * Shared instance.
         */
        public static final AnyHandler INSTANCE = new AnyHandler();
    
        /**
         * Returns a new URLConnection for this URL.
         * 
         * @param url
         *            the JavaScript URL
         * @return the connection
         */
        @Override
        protected URLConnection openConnection(final URL url) {
            // throw new UnsupportedOperationException();
            throw new RuntimeException("Unsupported protocol for open connection to " + url);
        }
    }
  • 相关阅读:
    Python-函数
    Python-运数符
    Python-条件判断
    Python-变量
    移动端页面布局的那些事儿
    关于ie7下display:inline-block;不支持的解决方案
    SuperSlidev2.1 轮播图片和无缝滚动
    解决xmapp中Apache端口号占用问题
    npm 常用命令详解
    python函数总结
  • 原文地址:https://www.cnblogs.com/jpit/p/8057180.html
Copyright © 2011-2022 走看看