0
我想将编码字符串发送到Solr,然后在检索时对其进行解码。我的编码是这样的: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);
如果我发送一个字符串,因为“你好我的名字是克里斯”编码将看起来像(忽略什么堆栈溢出改变);
ã�������Û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都有相同的问题。