코드 사본은 다음과 같습니다.
java.io.unsupportedencodingException 가져 오기;
import java.net.urldecoder;
import java.net.urlencoder;
import org.apache.commons.codec.decoderexception;
import org.apache.commons.codec.binary.base64;
import org.apache.commons.codec.binary.hex;
import org.apache.commons.lang.stringescapeutils;
/**
* 다양한 형식의 인코딩 및 코딩 도구.
*
* Commons-Codec, Commons-Lang 및 JDK가 제공하는 인코딩 및 코덱 방법을 통합합니다.
*
*
*/
공개 클래스 encodeutils {
개인 정적 최종 문자열 default_url_encoding = "UTF-8";
/**
* 16 진수 인코딩.
*/
/*public static string hexencode (byte [] input) {
반환 hex.encodeHexString (입력);
}*/
/**
* 16 진 디코딩.
*/
public static byte [] hexdecode (문자열 입력) {
노력하다 {
return hex.decodeHex (input.tochararray ());
} catch (decoderexception e) {
새로운 불법 스테이트 exception ( "Hex Decoder Exception", e)을 던지십시오.
}
}
/**
* Base64 인코딩.
*/
public static string base64encode (byte [] input) {
새 문자열을 반환합니다 (base64.encodebase64 (입력));
}
/**
* Base64 인코딩, URL 보안 (Base64의 불법 URL 문자를 다른 문자로 변환하려면 RFC3548 참조).
*/
public static string base64urlsafeencode (byte [] input) {
return base64.encodebase64urlsafestring (입력);
}
/**
* Base64 디코딩.
*/
public static byte [] base64decode (문자열 입력) {
return base64.decodebase64 (입력);
}
/**
* URL 인코딩, 기본값을 UTF-8로 인코딩합니다.
*/
public static string urlencode (문자열 입력) {
노력하다 {
return urlencoder.encode (input, default_url_encoding);
} catch (UnsupportedEncodingException e) {
새로운 불법 행정 exception ( "지원되지 않는 인코딩 예외", e)를 던지십시오.
}
}
/**
* URL 디코딩, 기본값을 UTF-8로 인코딩합니다.
*/
public static string urldecode (문자열 입력) {
노력하다 {
return urldecoder.decode (input, default_url_encoding);
} catch (UnsupportedEncodingException e) {
새로운 불법 행정 exception ( "지원되지 않는 인코딩 예외", e)를 던지십시오.
}
}
/**
* HTML 트랜스 코딩.
*/
공개 정적 문자열 htmlescape (String html) {
return stringescapeutils.escapehtml (html);
}
/**
* HTML 디코딩.
*/
공개 정적 문자열 htmlunescape (String htmlescaped) {
return stringescapeutils.unescapehtml (htmlescaped);
}
/**
* XML 트랜스 코딩.
*/
public static string xmlescape (String xml) {
Return StringEscapeUtils.escapexml (xml);
}
/**
* XML 디코딩.
*/
public static string xmlunescape (String xmlescaped) {
return stringescapeutils.unescapexml (xmlescaped);
}
}