Ejemplo n.º 1
0
        public static ContainerIndex OpenRead(string indexPath)
        {
            ContainerIndex index = new ContainerIndex();

            index.Read(File.OpenRead(indexPath));
            return(index);
        }
Ejemplo n.º 2
0
        public void RewriteOptimized(BufferedWriter writer, string containerIndexPath = null, string searchIndexPath = null)
        {
            int[] map = _compressor.OptimizeIndex();

            using (BufferedReader inner = BufferedReader.FromArray(_reader.Buffer, 0, 0))
                using (ContainerIndex containerIndex = (containerIndexPath == null ? null : ContainerIndex.OpenWrite(containerIndexPath)))
                    using (SearchIndexWriter indexWriter = (searchIndexPath == null ? null : new SearchIndexWriter(searchIndexPath, map.Length, 128 * 1024)))
                    {
                        long last = 0;

                        while (this.Read())
                        {
                            int length = (int)(this.BytesRead - last);
                            writer.EnsureSpace(length);

                            if (LengthLookup[(byte)_currentMarker] >= 0)
                            {
                                // Everything but compressed text: write bytes out
                                Buffer.BlockCopy(_reader.Buffer, _reader.Index - length, writer.Buffer, writer.Index, length);
                                writer.Index += length;
                            }
                            else
                            {
                                writer.Buffer[writer.Index++] = (byte)_currentMarker;

                                // Compressed Test: Rewrite the text segment
                                inner.ReadSlice(_reader.Buffer, _reader.Index - _currentLength, _reader.Index - 1);
                                _compressor.RewriteOptimized(map, inner, writer, indexWriter);

                                writer.Buffer[writer.Index++] = (byte)BionMarker.EndValue;
                            }

                            if ((byte)_currentMarker >= (byte)BionMarker.EndArray)
                            {
                                if ((byte)_currentMarker >= (byte)BionMarker.StartArray)
                                {
                                    containerIndex?.Start(writer.BytesWritten - 1);
                                }
                                else
                                {
                                    containerIndex?.End(writer.BytesWritten);
                                }
                            }

                            last = this.BytesRead;
                        }
                    }
        }
Ejemplo n.º 3
0
 public BionWriter(BufferedWriter writer, ContainerIndex containerIndex = null, WordCompressor compressor = null)
 {
     _writer         = writer;
     _containerIndex = containerIndex;
     _compressor     = compressor;
 }
Ejemplo n.º 4
0
 public BionWriter(Stream stream, ContainerIndex containerIndex = null, WordCompressor compressor = null) : this(new BufferedWriter(stream), containerIndex, compressor)
 {
 }
Ejemplo n.º 5
0
 public BionReader(BufferedReader reader, ContainerIndex containerIndex = null, WordCompressor compressor = null)
 {
     _reader         = reader;
     _compressor     = compressor;
     _containerIndex = containerIndex;
 }