【发布时间】:2012-03-06 06:02:49
【问题描述】:
我正在尝试向 Solr 发送一个编码字符串,然后在检索时对其进行解码。我的编码看起来像:
public static String compress(String inputString) {
try {
if (inputString == null || inputString.length() == 0) {
return null;
}
return new String(compress(inputString.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
private static byte[] compress(byte[] input) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(input);
gzip.close();
return out.toByteArray();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
然后我将它发送到 SOLR,当我尝试取回它时(暂时忽略解码,因为它在这里失败)
SolrDocument resultDoc = iter.next();
String content = (String) resultDoc.getFieldValue("source");
System.out.println(content);
如果我发送一个字符串,例如“你好,我的名字是 Chris”,编码后的样子(忽略堆栈溢出的变化);
ã�������ÛHÕ……W»≠T»KÃMU»,VpŒ( ,�ìùùG���
然而我从 SOLR 得到的是
#31;ã#8;#0;#0;#0;#0;#0;#0;#0;ÛHÕ……W»≠T»KÃMU»,VpŒ( ,#6;#0;ìùùG#22;#0;#0;#0;
这显然会使解码失败。我尝试使用 Jetty 安装和 Tomcat 都遇到同样的问题。
【问题讨论】: