Souce のコンストラクタに URLを渡した場合は、ヘッダー情報の Content-Type の charset からエンコードが取得できるかもだが(Jericho が取得しているかは未調査)、BODY 部分のストリームを渡す場合、取得出来ないため内容から自動判別すようで、そこがおかしくなっているようだった。
なので指定してやることに、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | HttpClient http = new DefaultHttpClient(); if (res.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { LOG.error( "Failed to load uri." ); return false ; } InputStream in = res.getEntity().getContent(); if (res.getHeaders( "Content-Encoding" ).length > 0 && "gzip" .equals(res.getHeaders( "Content-Encoding" )[ 0 ].getValue())) in = new GZIPInputStream(in); String charset = EntityUtils.getContentCharSet(res.getEntity()); Source source = null ; if (charset != null ) source = new Source( new InputStreamReader(in, charset)); else source = new Source(in); |
Source(final Reader reader) の実装が、
1 | this (reader,(reader instanceof InputStreamReader) ? ((InputStreamReader)reader).getEncoding() : null ); |
Content-Type の charset がなければ今まで通り自動判別。
もっとスマートにいかないものか・・・
0 件のコメント:
コメントを投稿