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);
        }
    }
  • 相关阅读:
    VMware安装centos7
    Docker Compose 启动mysql,redis,rabbitmq
    mysql升级到5.7
    Docker Compose搭建ELK
    Spring Boot源码(八):Spring AOP源码
    Spring AOP-基于@AspectJ风格
    JDK动态代理
    Spring Boot源码(七):循环依赖
    Spring Boot源码(六):Bean的创建详解
    Spring Boot源码(五):BeanFactoryPostProcessor和BeanPostProcessor
  • 原文地址:https://www.cnblogs.com/jpit/p/8057180.html
Copyright © 2011-2022 走看看