Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="record"></param>
        public void WriteRecord(DataRecord record)
        {
            if (_outputStream == null) {
                OpenOutputStream();
                _outputWriter = new VariableLengthBinaryWriter(_outputStream);
                EmptyInternalSource e = new EmptyInternalSource();

                e.CurrentRecord = record; // updates the record info
                e.WriteProperties(_outputStream);
            }

            _outputWriter.WriteVariableLength((uint)record.KeyBytes.Length);
            _outputWriter.Write(record.KeyBytes);

            // output data
            if (record.Data != null) {
                _outputWriter.WriteVariableLength((uint)record.Data.Length);
                _outputWriter.Write(record.Data);
            }
            else {
                _outputWriter.WriteVariableLength((uint)0);
            }

            // slow do elsewhere _totalRecordBytesEstimate += rawRecord.Length;
            _totalRecordsEstimate++;
        }
Example #2
0
        /// <summary>
        /// Constructor for Uri class.
        /// </summary>
        /// <param name="uri">The protocol and filepath of the uri.</param>
        public TStoreUri(string uri)
        {
            _rawUri = uri;

            if (_rawUri.StartsWith("records:") || _rawUri.StartsWith("recs:")) {
                int colon = _rawUri.IndexOf(':');
                _filePath = _rawUri.Substring(colon+1);
                _storageType = TStorageType.RecordFile;
            }

            else if (_rawUri.StartsWith("store:") || _rawUri.StartsWith("tstore:")) {
                int colon = _rawUri.IndexOf(':');
                _filePath = _rawUri.Substring(colon+1);
                _storageType = TStorageType.TStore;
            }

            else if (_rawUri.StartsWith("dir:") || _rawUri.StartsWith("directory:")) {
                int colon = _rawUri.IndexOf(':');
                _filePath = _rawUri.Substring(colon+1);
                _storageType = TStorageType.Directory;
            }

            else {
                _filePath = _rawUri;
                // it may be that the user just forgot to put the proper leading protocol
                // try to figure out if this is the case so they don't have to.

                // if this is a directory then the input is either a Directory or TStore.
                if (Directory.Exists(_rawUri)) {
                    if (File.Exists(Path.Combine(_rawUri, "keys-data"))) { // this is a cheat
                        _storageType = TStorageType.TStore;
                    }

                    else _storageType = TStorageType.Directory;
                }

                    // directory doesn't exist
                else if (File.Exists(_rawUri)) {
                    EmptyInternalSource source = new EmptyInternalSource();
                    //FileStream fs = new FileStream(RawUri, FileMode.Open);
                    //FileStream fs = new FileStream(RawUri, FileMode.Open, FileAccess.Read, FileShare.Read);
                    Stream fs = ZStreamIn.Open(_rawUri); // so we can read gz files

                    bool flatFile = false;
                    try {
                        // try reading the properties of a recordsFile.
                        source.ReadProperties(fs);
                    }
                    catch {
                        flatFile = true;
                    }

                    fs.Close();

                    if (flatFile) _storageType = TStorageType.FlatFile;
                    else _storageType = TStorageType.RecordFile;
                }
            }
        }