• 大小: 213KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 其他
  • 标签: 工具  

资源简介

diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具diffy工具

资源截图

代码片段和文件信息

import java.net.InetSocketAddress;
import java.io.IOException;
import java.io.OutputStream;
import java.util.function.Function;
import java.util.stream.Stream;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

public class ExampleServers {
    public static void main(String[] args) throws Exception {
        int primary = Integer.parseInt(args[0]);
        int secondary = Integer.parseInt(args[1]);
        int candidate = Integer.parseInt(args[2]);
        Thread p = new Thread(() -> bind(primary x -> x.toLowerCase()));
        Thread s = new Thread(() -> bind(secondary x -> x.toLowerCase()));
        Thread c = new Thread(() -> bind(candidate x -> x.toUpperCase()));
        p.start();
        s.start();
        c.start();
        while(true){
            Thread.sleep(10);
        }
    }

    public static void bind(int port Function lambda) {
        try {
            HttpServer server = HttpServer.create(new InetSocketAddress(port) 0);
            server.createContext(
                    “/json“
                    new Handler(
                            “{\“name\“:\“%s\“ \“timestamp\“:\“%s\“}“
                            “application/json“
                            lambda));
            server.createContext(
                    “/html“
                    new Handler(
                            “%s%s
                            “text/html“
                            lambda));
            server.setExecutor(null);
            server.start();
        } catch (Exception exception) {
            System.err.println(“!!!failed to start!!!“);
        }
    }
}
class Handler implements HttpHandler {
    private String template;
    private String contentType;
    private Function lambda;
    public Handler(String template String contentType Function lambda) {
        super();
        this.template = template;
        this.contentType = contentType;
        this.lambda = lambda;
    }

    @Override
    public void handle(HttpExchange t) throws IOException {
        String name  = lambda.apply(t.getRequestURI().getQuery());
        String response = String.format(template name System.currentTimeMillis());
        System.out.println(response);
        t.getResponseHeaders().add(“Content-Type“ contentType);
        t.sendResponseHeaders(200 response.length());
        OutputStream os = t.getResponseBody();
        os.write(response.getBytes());
        os.close();
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-31 02:41  diffy-master\
     文件         200  2018-03-31 02:41  diffy-master\.gitignore
     文件         436  2018-03-31 02:41  diffy-master\.travis.yml
     文件         373  2018-03-31 02:41  diffy-master\BUILD
     文件         526  2018-03-31 02:41  diffy-master\Dockerfile
     文件       11358  2018-03-31 02:41  diffy-master\LICENSE
     文件        6174  2018-03-31 02:41  diffy-master\README.md
     文件        4627  2018-03-31 02:41  diffy-master\build.sbt
     目录           0  2018-03-31 02:41  diffy-master\example\
     文件        2610  2018-03-31 02:41  diffy-master\example\ExampleServers.java
     文件         790  2018-03-31 02:41  diffy-master\example\run.sh
     目录           0  2018-03-31 02:41  diffy-master\project\
     文件          19  2018-03-31 02:41  diffy-master\project\build.properties
     文件         607  2018-03-31 02:41  diffy-master\project\plugins.sbt
     文件        1184  2018-03-31 02:41  diffy-master\sbt
     文件        4387  2018-03-31 02:41  diffy-master\scalastyle-config.xml
     目录           0  2018-03-31 02:41  diffy-master\src\
     目录           0  2018-03-31 02:41  diffy-master\src\main\
     目录           0  2018-03-31 02:41  diffy-master\src\main\resources\
     文件          92  2018-03-31 02:41  diffy-master\src\main\resources\BUILD
     目录           0  2018-03-31 02:41  diffy-master\src\main\resources\templates\
     文件        2609  2018-03-31 02:41  diffy-master\src\main\resources\templates\cron_report.mustache
     文件       12330  2018-03-31 02:41  diffy-master\src\main\resources\templates\dashboard.mustache
     目录           0  2018-03-31 02:41  diffy-master\src\main\scala\
     文件         292  2018-03-31 02:41  diffy-master\src\main\scala\BUILD
     目录           0  2018-03-31 02:41  diffy-master\src\main\scala\com\
     目录           0  2018-03-31 02:41  diffy-master\src\main\scala\com\twitter\
     目录           0  2018-03-31 02:41  diffy-master\src\main\scala\com\twitter\diffy\
     文件        6486  2018-03-31 02:41  diffy-master\src\main\scala\com\twitter\diffy\ApiController.scala
     文件         259  2018-03-31 02:41  diffy-master\src\main\scala\com\twitter\diffy\BUILD
     文件        4020  2018-03-31 02:41  diffy-master\src\main\scala\com\twitter\diffy\DiffyServiceModule.scala
............此处省略87个文件信息

评论

共有 条评论