首页 > 编程语言 >20230627 java.net.URI

20230627 java.net.URI

时间:2023-08-29 17:14:34浏览次数:39  
标签:20230627 Console String fragment URI uri java net log

介绍

  • java.net.URI
  • public final class URI implements Comparable, Serializable
  • URI 是个纯粹的语法结构,包含用来指定 Web 资源的字符串的各种组成部分
  • URL 是 URI 的一个特例,它包含了用于定位 Web 资源的足够信息

URI 语法

URI 具有以下句法:

[scheme:]schemeSpecficPart[#fragment]

一个分层 URI schemeSpecificPart 具有以下结构:

[//authority][path][?query]

对于那些基于服务器的 URI , authority 部分具有以下形式:

[user-info@]host[:port]

API

static

  • create

构造器

  • URI(String str) throws URISyntaxException
  • URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
  • URI(String scheme, String authority, String path, String query, String fragment) throws URISyntaxException
  • URI(String scheme, String host, String path, String fragment) throws URISyntaxException
  • URI(String scheme, String ssp, String fragment) throws URISyntaxException

public

  • resolve

    • 解析相对化
  • relativize

    • resolve
    • 相对化
  • normalize

    • 正常化
  • isAbsolute

  • isOpaque

    • 是否不透明的
    • 当绝对 URI 的 schemeSpecficPart 不是以 / 开头的
  • toASCIIString

    • 以 US-ASCII 字符串形式返回此 URI 的内容
    • 会进行转码
  • toURL

    • URL
  • parseServerAuthority

    • 尝试将此 URI 的 authority 解析为 user-info, host, port

URI 句法:

  • getScheme
  • getRawSchemeSpecificPart, getSchemeSpecificPart
    • 方法名不带 raw 表示解码后的
  • getRawFragment, getFragment

分层 SchemeSpecificPart 结构:

  • getRawAuthority, getAuthority
  • getRawPath, getPath
  • getRawQuery, getQuery

authority 结构:

  • getRawUserInfo, getUserInfo
  • getHost
  • getPort
    • 返回 -1 表示未定义

示例代码

import cn.hutool.core.lang.Console;

import java.net.URI;

public class TestURI {
    public static void main(String[] args) {
        URI uri = URI.create(
                "https://www.bilibili.com/video/BV1Rj411D7Eg/?spm_id_from=333.1007.tianma.1-1-1"
                        + ".click&vd_source=4a4c5fa550920bace1f35eeab12544f0");

        Console.log(uri);

        Console.log("Scheme :: ", uri.getScheme());
        Console.log("SchemeSpecificPart :: ", uri.getSchemeSpecificPart());
        Console.log("Fragment :: ", uri.getFragment());
        Console.log("Authority :: ", uri.getAuthority());
        Console.log("Path :: ", uri.getPath());
        Console.log("Query :: ", uri.getQuery());
        Console.log("UserInfo :: ", uri.getUserInfo());
        Console.log("Host :: ", uri.getHost());
        Console.log("Port :: ", uri.getPort());
        
    }
}

打印结果

https://www.bilibili.com/video/BV1Rj411D7Eg/?spm_id_from=333.1007.tianma.1-1-1.click&vd_source=4a4c5fa550920bace1f35eeab12544f0
Scheme ::  https
SchemeSpecificPart ::  //www.bilibili.com/video/BV1Rj411D7Eg/?spm_id_from=333.1007.tianma.1-1-1.click&vd_source=4a4c5fa550920bace1f35eeab12544f0
Fragment ::  null
Authority ::  www.bilibili.com
Path ::  /video/BV1Rj411D7Eg/
Query ::  spm_id_from=333.1007.tianma.1-1-1.click&vd_source=4a4c5fa550920bace1f35eeab12544f0
UserInfo ::  null
Host ::  www.bilibili.com
Port ::  -1

标签:20230627,Console,String,fragment,URI,uri,java,net,log
From: https://www.cnblogs.com/huangwenjie/p/17650396.html

相关文章

  • 20230627 java.net.Socket
    介绍java.net.SocketpublicclassSocketimplementsjava.io.Closeable套接字(Socket)是网络软件中的一个抽象概念,负责启动该程序内部和外部之间的通信API构造器Socket()Socket(Proxyproxy)Socket(Stringhost,intport)throwsUnknownHostException,IOException......
  • 20230627 java.net.ServerSocket
    介绍java.net.ServerSocketpublicclassServerSocketimplementsjava.io.Closeable服务器套接字ServerSocket类用于建立套接字,accept用于告诉程序不停地等待,直到有客户端连接到这个端口。一旦有人通过网络发送了正确的连接请求,并以此连接到了端口上,该方法就会返回一个表......
  • 20230627 java.net.InetSocketAddress
    介绍java.net.InetSocketAddresspublicclassInetSocketAddressextendsSocketAddressAPI构造器InetSocketAddress(intport)InetSocketAddress(InetAddressaddr,intport)InetSocketAddress(Stringhostname,intport)publiccreateUnresolved创建未解析的I......
  • 20230627 java.net.InetAddress
    介绍java.net.InetAddresspublicclassInetAddressimplementsjava.io.Serializable因特网地址,是一串数字表示的主机地址(IPv4是4字节,IPv6是16字节)支持在主机名和因特网地址之间进行转换封装了一个字节序列(IPv4是4字节),byte的取值范围是[-126,125),IPv4的大小......
  • 20230627 java.nio.channels.SocketChannel
    介绍java.nio.channels.SocketChannelpublicabstractclassSocketChannelextendsAbstractSelectableChannelimplementsByteChannel,ScatteringByteChannel,GatheringByteChannel,NetworkChannelAPIopen打开一个套接字通道,并将其连接到远程地址bindconne......
  • 20230627 java.nio.channels.Channels
    介绍java.nio.channels.ChannelsAPIstaticnewInputStreamnewOutputStreamnewChannelReadableByteChannelnewChannel(InputStreamin)WritableByteChannelnewChannel(OutputStreamout)newReadernewWriter......
  • 20230626 java.nio.CharBuffer
    介绍java.nio.CharBufferpublicabstractclassCharBufferextendsBufferimplementsComparable,Appendable,CharSequence,Readablechar缓冲区,内部是char[]APIstaticallocate分配wrap包裹publicgetputcompact压缩将缓冲区当前位置(position)与......
  • 20230626 java.nio.ByteBuffer
    介绍java.nio.ByteBufferpublicabstractclassByteBufferextendsBufferimplementsComparable最常用的Buffer子类APIstaticallocateDirect直接使用本地内存,而不是通过JVM堆空间allocatewrappublicgetputcompact压缩将缓冲区当前位置(positi......
  • 20230621 java.nio.Buffer
    介绍java.nio.BufferpublicabstractclassBuffer缓冲区都具有mark,可选的标记,用于重复一个读入或写出操作,默认-1position,读写位置,下一个值将在此进行读写,默认0limit,界限,超过它进行读写是没有意义的capacity,容量,它永远不能改变这些值满足下面的条件:0<=......
  • 20230517 java.nio.file.Path
    介绍java.nio.file.PathpublicinterfacePathextendsComparable<Path>,Iterable<Path>,Watchable不推荐使用Paths工具类,相关方法在Path接口中都有静态方法代表系统相关的文件路径,可用于在文件系统中定位文件表示分层路径此接口的实现是不可变的,线程安全经常和Fi......