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);
        }
    }
  • 相关阅读:
    Ajax_ajax模板引擎 ---tmplate.js处理数据和标签拼接
    Ajax_ajax请求中的跨域问题---浏览器不允许ajax跨域获取服务器数据,那我们就用jsonp来实现跨域
    Ajax_jquery库中Ajax方法的使用
    第一阶段冲刺 second day
    第11周周总结
    用户场景分析
    第一阶段冲刺 first day
    第10周周总结
    第9周周总结
    查找水王
  • 原文地址:https://www.cnblogs.com/jpit/p/8057180.html
Copyright © 2011-2022 走看看