woshikid / blog

Apache License 2.0
8 stars 1 forks source link

Java18新特性 #179

Open woshikid opened 2 years ago

woshikid commented 2 years ago

默认UTF-8

Charset.defaultCharset()默认为UTF-8 可使用-Dfile.encoding=UTF-8修改默认字符集

简易Http服务器

命令行工具

jwebserver [-b 0.0.0.0] [-p 8080] [-d /path/to/dir] [-o verbose]

API

HttpServer httpServer = SimpleFileServer.createFileServer(new InetSocketAddress(8080), Path.of("/path/to/dir"), OutputLevel.INFO);
httpServer.start();
HttpHandler handler = SimpleFileServer.createFileHandler(Path.of("/path/to/dir"));
Filter filter = SimpleFileServer.createOutputFilter(System.out, OutputLevel.INFO);
HttpServer httpServer = HttpServer.create(new InetSocketAddress(8080), 0, "/", handler, filter);
//httpServer.createContext("/url/path", handler);
httpServer.start();

JavaDoc @snippet

内联片段

/**
 * The following code shows how to use {@code Optional.isPresent}:
 * {@snippet :
 * if (v.isPresent()) {
 *     System.out.println("v: " + v.get());
 * }
 * }
 */

外部片段

/**
 * The following code shows how to use {@code Optional.isPresent}:
 * {@snippet file="ShowOptional.java" region="example"}
 */
public class ShowOptional {
    void show(Optional<String> v) {
        // @start region="example"
        if (v.isPresent()) {
            System.out.println("v: " + v.get());
        }
        // @end
    }
}

准备删除finalize()

@Deprecated(since="9", forRemoval=true)
protected void finalize() throws Throwable {}