2010年3月15日月曜日

Java文字列エンコード関連メモ

とにかく標準は
Windows-31J
だからね!

日本語が通らなければかます(送信側)
customerName = StringUtility.decodeHttpStr(customerName);

SQLにかます
customerName = StringUtility.strAsteriskToPercent(customerName);

XMLに変換?
StringBuffer buff = GXml.toStringBuffer( srchCustomerLstJDBC(customerName) );


XMLヘッダ
UTF変換エラーが出るようなときは、
たいていヘッダが設定されていなかったり、
同じファイル名のXMLがあったり、うっかりしてることがあるので注意。



■InputStreamのエンコード指定
InputStream is = new CorpClient().post(name);
String line;
String requestID = "CustomerSrch";
InputSource isrc = new InputSource(is);
isrc.setEncoding("Windows-31J");

InputStreamはInputStreamReaderかInputSourceを経由することでしか
エンコーディングを指定できない。
のでそれをかぶせてやれば、parserなんかで読み込むときも
Windows31-Jでいけるんだと思うんだけど、あんまり自信がない。

0 件のコメント:

コメントを投稿