protected bool FillIndex() { try { string IndexFQN = targetDir + "/" + IndexFileName; //Console.WriteLine("***************** filling index : "+ IndexFQN); if (File.Exists(IndexFQN)) { FileStream iout = new FileStream(IndexFQN, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader index_br = new BinaryReader(iout); long latest_ts = 0; try { while (true) { string key = index_br.ReadString(); IKey ikey = SerializerHelper <KeyType> .DeserializeFromJsonStream(key) as IKey; int num_offsets = index_br.ReadInt32(); List <DataBlockInfo> offsets = new List <DataBlockInfo>(num_offsets); for (int i = 0; i < num_offsets; i++) { long ts = index_br.ReadInt64(); long offset = index_br.ReadInt64(); DataBlockInfo tso = new DataBlockInfo(ts, offset); if (streamtype == StreamFactory.StreamSecurityType.Secure) { Int32 h_len = index_br.ReadInt32(); if (h_len > 0) { tso.hashValue = index_br.ReadBytes(h_len); } } offsets.Add(tso); if (ts > latest_ts) { latest_ts = ts; latest_key = ikey; } } index[ikey] = offsets; IncrementIndexSize(offsets.Count); } } catch (Exception) { // done // } // finally // { if (streamtype == StreamFactory.StreamSecurityType.Secure) { iout.Position = 0; IndexHash = hasher.ComputeHash(iout); } // Console.WriteLine("********************* closed " + IndexFQN); index_br.Close(); iout.Close(); GC.Collect(); } } else { return(false); } } catch (Exception exp) { Console.WriteLine("{0} Exception caught.", exp); return(false); } return(true); }
public object DeserializeFromJsonStream(string json) { return(SerializerHelper <T> .DeserializeFromJsonStream(json)); }
//*** private void BuildIndexHeader() { FileStream iout; BinaryReader index_br; indexHeader = new Dictionary <IKey, long>(); string IndexFilePath = targetDir + "/" + IndexFileName; if (!File.Exists(IndexFilePath)) { return; } //Console.WriteLine(DateTime.Now+" ******** filling indexheader " + IndexFilePath); iout = new FileStream(IndexFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); index_br = new BinaryReader(iout); try { while (true) { long keyOffset = index_br.BaseStream.Position; string key = index_br.ReadString(); IKey ikey = SerializerHelper <KeyType> .DeserializeFromJsonStream(key) as IKey; indexHeader[ikey] = keyOffset; int num_offsets = index_br.ReadInt32(); for (int i = 0; i < num_offsets; i++) { index_br.ReadBytes(16);//timestamp and offset if (streamtype == StreamFactory.StreamSecurityType.Secure) { index_br.ReadUInt32(); //key_version Int32 h_len = index_br.ReadInt32(); //h_len? index_br.ReadBytes(h_len); //hashvalue } } } } catch (Exception) { // done // } // catch(Exception e) // { // Console.Write("Exception in buildindexheader: "+e); // } // finally // { if (streamtype == StreamFactory.StreamSecurityType.Secure) { iout.Position = 0; IndexHash = hasher.ComputeHash(iout); } GC.Collect(); index_br.Close(); iout.Close(); //Console.WriteLine(DateTime.Now+" ******** closed indexheader " + IndexFilePath); GC.Collect(); } }