コード例 #1
0
ファイル: SegmentReader.cs プロジェクト: nzdunic/ravendb
			// Load & cache full bytes array.  Returns bytes.
			public byte[] Bytes()
			{
				lock (this)
				{
					System.Diagnostics.Debug.Assert(refCount > 0 &&(origNorm == null || origNorm.refCount > 0));
					if (bytes == null)
					{
						// value not yet read
						System.Diagnostics.Debug.Assert(bytesRef == null);
						if (origNorm != null)
						{
							// Ask origNorm to load so that for a series of
							// reopened readers we share a single read-only
							// byte[]
							bytes = origNorm.Bytes();
							bytesRef = origNorm.bytesRef;
							bytesRef.IncRef();
							
							// Once we've loaded the bytes we no longer need
							// origNorm:
							origNorm.DecRef();
							origNorm = null;
						}
						else
						{
							// We are the origNorm, so load the bytes for real
							// ourself:
							int count = Enclosing_Instance.MaxDoc();
							bytes = new byte[count];
							
							// Since we are orig, in must not be null
							System.Diagnostics.Debug.Assert(in_Renamed != null);
							
							// Read from disk.
							lock (in_Renamed)
							{
								in_Renamed.Seek(normSeek);
								in_Renamed.ReadBytes(bytes, 0, count, false);
							}
							
							bytesRef = new Ref();
							CloseInput();
						}
					}
					
					return bytes;
				}
			}