Class Percent

java.lang.Object
org.aoju.bus.core.codec.Percent
All Implemented Interfaces:
Serializable, Encoder<byte[],byte[]>

public class Percent extends Object implements Encoder<byte[],byte[]>, Serializable
百分号编码(Percent-encoding), 也称作URL编码(URL encoding) 百分号编码可用于URI的编码,也可以用于"application/x-www-form-urlencoded"的MIME准备数据
  • URI:遵循RFC 3986保留字规范
  • application/x-www-form-urlencoded,遵循W3C HTML Form content types规范,如空格须转+
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • Percent

      public Percent()
      构造 [a-zA-Z0-9]默认不被编码
    • Percent

      public Percent(BitSet safeCharacters)
      构造
      Parameters:
      safeCharacters - 安全字符,安全字符不被编码
  • Method Details

    • isSafe

      public boolean isSafe(char c)
      检查给定字符是否为安全字符
      Parameters:
      c - 字符
      Returns:
      true表示安全,否则非安全字符
    • encode

      public byte[] encode(byte[] bytes)
      Description copied from interface: Encoder
      执行编码
      Specified by:
      encode in interface Encoder<byte[],byte[]>
      Parameters:
      bytes - 被编码的数据
      Returns:
      编码后的数据
    • encode

      public String encode(CharSequence path, Charset charset, char... customSafeChar)
      将URL中的字符串编码为%形式
      Parameters:
      path - 需要编码的字符串
      charset - 编码, null返回原字符串,表示不编码
      customSafeChar - 自定义安全字符
      Returns:
      编码后的字符串