public virtual void TestCompressionTools() { IndexableField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.Compress(BinaryValCompressed.GetBytes(Encoding.UTF8))); IndexableField stringFldCompressed = new StoredField("stringCompressed", CompressionTools.CompressString(BinaryValCompressed)); var doc = new Documents.Document {binaryFldCompressed, stringFldCompressed}; using (Directory dir = NewDirectory()) using (RandomIndexWriter writer = new RandomIndexWriter(Random(), dir)) { writer.AddDocument(doc); using (IndexReader reader = writer.Reader) { Documents.Document docFromReader = reader.Document(0); Assert.IsTrue(docFromReader != null); string binaryFldCompressedTest = Encoding.UTF8.GetString( CompressionTools.Decompress(docFromReader.GetBinaryValue("binaryCompressed"))); //new string(CompressionTools.Decompress(docFromReader.GetBinaryValue("binaryCompressed")), IOUtils.CHARSET_UTF_8); Assert.IsTrue(binaryFldCompressedTest.Equals(BinaryValCompressed)); Assert.IsTrue( CompressionTools.DecompressString(docFromReader.GetBinaryValue("stringCompressed")) .Equals(BinaryValCompressed)); } } }
private byte[] Uncompress(byte[] b) { try { return(CompressionTools.Decompress(b)); } catch (Exception e) { // this will happen if the field is not compressed throw new CorruptIndexException("field data are in wrong format: " + e, e); } }