コードコピーは次のとおりです。
java.io.unsupportedencodingexceptionをインポートします。
java.net.urldeCoderをインポートします。
java.net.urlencoderをインポートします。
Import org.apache.commons.codec.decoderexception;
org.apache.commons.codec.binary.base64をインポートします。
Import org.apache.commons.codec.binary.hex;
org.apache.commons.lang.stringescapeutilsをインポートします。
/**
*さまざまな形式のエンコードおよびコーディングツール。
*
* Commons-Codec、Commons-Lang、JDKが提供するエンコーディングおよびコーデックメソッドを統合します。
*
*
*/
パブリッククラスのecodeutils {
プライベート静的最終文字列default_url_encoding = "utf-8";
/**
*ヘックスエンコーディング。
*/
/*public static string hexencode(byte [] input){
return hex.encodehexstring(input);
}*/
/**
*ヘックスデコード。
*/
public static byte [] hexdecode(string input){
試す {
return hex.decodehex(input.tochararray());
} catch(decoderexception e){
新しいIllegalStateException( "Hex Decoder Exception"、e)を投げます。
}
}
/**
* base64エンコーディング。
*/
public static string base64encode(byte [] input){
新しい文字列(base64.encodebase64(input))を返します。
}
/**
* base64エンコーディング、URLセキュリティ(base64で違法なURL文字を変換する、 /=他の文字に、RFC3548を参照)。
*/
public static string base64urlsafeencode(byte [] input){
base64.encodebase64urlsafestring(input);
}
/**
* base64デコード。
*/
public static byte [] base64Decode(string input){
base64.decodebase64(input);
}
/**
* URLエンコード、エンコードデフォルトはUTF-8です。
*/
public static string urlencode(string input){
試す {
return urlencoder.encode(input、default_url_encoding);
} catch(unsupportedencodingexception e){
新しいIllegalargumentException(「サポートされていないエンコード例外」、e)を投げます。
}
}
/**
* URLデコード、エンコードデフォルトはUTF-8です。
*/
public static string urldecode(string input){
試す {
return urldecoder.decode(input、default_url_encoding);
} catch(unsupportedencodingexception e){
新しいIllegalargumentException(「サポートされていないエンコード例外」、e)を投げます。
}
}
/**
* HTMLトランスコーディング。
*/
public static string htmlescape(string html){
stringescapeutils.escapehtml(html);
}
/**
* HTMLデコード。
*/
public static string htmlunescape(string htmlescaped){
stringescapeutils.unescapehtml(htmlescaped);
}
/**
* XMLトランスコーディング。
*/
public static string xmlescape(string xml){
stringescapeutils.escapexml(xml);
}
/**
* XMLデコード。
*/
public static string xmlunescape(string xmlescaped){
stringescapeutils.unescapexml(xmlescaped);
}
}