DecompressString() public static méthode

Decompress the byte array (referenced by the provided BytesRef) previously returned by compressString back into a String
public static DecompressString ( BytesRef bytes ) : string
bytes BytesRef
Résultat string
Exemple #1
0
        public virtual void TestCompressionTools()
        {
            IIndexableField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.Compress(BinaryValCompressed.GetBytes(Encoding.UTF8)));
            IIndexableField 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, Similarity, TimeZone))
                {
                    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));
                    }
                }
        }
        public virtual void  TestCompressionTools()
        {
            Fieldable binaryFldCompressed = new Field("binaryCompressed", CompressionTools.Compress(System.Text.UTF8Encoding.UTF8.GetBytes(binaryValCompressed)), Field.Store.YES);
            Fieldable stringFldCompressed = new Field("stringCompressed", CompressionTools.CompressString(binaryValCompressed), Field.Store.YES);

            Document doc = new Document();

            doc.Add(binaryFldCompressed);
            doc.Add(stringFldCompressed);

            /** add the doc to a ram index */
            MockRAMDirectory dir    = new MockRAMDirectory();
            IndexWriter      writer = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);

            writer.AddDocument(doc);
            writer.Close();

            /** open a reader and fetch the document */
            IndexReader reader        = IndexReader.Open(dir);
            Document    docFromReader = reader.Document(0);

            Assert.IsTrue(docFromReader != null);

            /** fetch the binary compressed field and compare it's content with the original one */
            System.String binaryFldCompressedTest = new System.String(System.Text.UTF8Encoding.UTF8.GetChars(CompressionTools.Decompress(docFromReader.GetBinaryValue("binaryCompressed"))));
            Assert.IsTrue(binaryFldCompressedTest.Equals(binaryValCompressed));
            Assert.IsTrue(CompressionTools.DecompressString(docFromReader.GetBinaryValue("stringCompressed")).Equals(binaryValCompressed));

            reader.Close();
            dir.Close();
        }
        public virtual void TestCompressionTools()
        {
            IIndexableField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.Compress(BinaryValCompressed.GetBytes(Encoding.UTF8)));
            IIndexableField stringFldCompressed = new StoredField("stringCompressed", CompressionTools.CompressString(BinaryValCompressed));

            var doc = new Documents.Document {
                binaryFldCompressed, stringFldCompressed
            };

            using (Directory dir = NewDirectory())
                using (RandomIndexWriter writer = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                           this,
#endif
                           Random, dir))
                {
                    writer.AddDocument(doc);

                    using (IndexReader reader = writer.GetReader())
                    {
                        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, StringComparison.Ordinal));
                        Assert.IsTrue(
                            CompressionTools.DecompressString(docFromReader.GetBinaryValue("stringCompressed"))
                            .Equals(BinaryValCompressed, StringComparison.Ordinal));
                    }
                }
        }