DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Store.ObjectStream Class Reference
Inheritance diagram for Deveel.Data.Store.ObjectStream:

Public Member Functions

 ObjectStream (ILargeObject largeObject)
 
override void Flush ()
 
override long Seek (long offset, SeekOrigin origin)
 
override void SetLength (long value)
 
override int Read (byte[] buffer, int offset, int count)
 
override void Write (byte[] buffer, int offset, int count)
 

Protected Member Functions

override void Dispose (bool disposing)
 

Properties

override bool CanRead [get]
 
override bool CanSeek [get]
 
override bool CanWrite [get]
 
override long Length [get]
 
override long Position [get, set]
 

Private Member Functions

void ReadPageContent (byte[] buffer, long pos, int length)
 
void FillBuffer (long pos)
 

Private Attributes

readonly ILargeObject largeObject
 
long position
 
Stream outTempStream
 
long readBufferPos
 
readonly byte[] readBuf
 
const int BufferSize = 64*1024
 

Detailed Description

Definition at line 21 of file ObjectStream.cs.

Constructor & Destructor Documentation

Deveel.Data.Store.ObjectStream.ObjectStream ( ILargeObject  largeObject)
inline

Definition at line 31 of file ObjectStream.cs.

31  {
32  if (largeObject == null)
33  throw new ArgumentNullException("largeObject");
34 
35  this.largeObject = largeObject;
36  outTempStream = new MemoryStream(64*1024);
37 
38  readBuf = new byte[BufferSize];
39  readBufferPos = -1;
40  }
readonly ILargeObject largeObject
Definition: ObjectStream.cs:22

Member Function Documentation

override void Deveel.Data.Store.ObjectStream.Dispose ( bool  disposing)
inlineprotected

Definition at line 55 of file ObjectStream.cs.

55  {
56  if (disposing) {
57  if (outTempStream != null)
58  outTempStream.Dispose();
59  }
60 
61  outTempStream = null;
62  base.Dispose(disposing);
63  }
void Deveel.Data.Store.ObjectStream.FillBuffer ( long  pos)
inlineprivate

Definition at line 46 of file ObjectStream.cs.

46  {
47  long readPos = (pos/BufferSize)*BufferSize;
48  int toRead = (int) System.Math.Min(BufferSize, (largeObject.RawSize - readPos));
49  if (toRead > 0) {
50  ReadPageContent(readBuf, readPos, toRead);
51  readBufferPos = readPos;
52  }
53  }
readonly ILargeObject largeObject
Definition: ObjectStream.cs:22
void ReadPageContent(byte[] buffer, long pos, int length)
Definition: ObjectStream.cs:42
long RawSize
Gets the raw byte size of the object.
Definition: ILargeObject.cs:56
override void Deveel.Data.Store.ObjectStream.Flush ( )
inline

Definition at line 65 of file ObjectStream.cs.

65  {
66  if (outTempStream == null ||
67  outTempStream.Length == 0)
68  return;
69 
70  try {
71  long offset = 0;
72  var buffer = new byte[BufferSize];
73  var totalLength = outTempStream.Length;
74 
75  outTempStream.Seek(0, SeekOrigin.Begin);
76 
77  while (offset < totalLength) {
78  // Fill the buffer
79  int index = 0;
80  int blockRead = (int) System.Math.Min((long) BufferSize, (totalLength - offset));
81  int toRead = blockRead;
82  while (toRead > 0) {
83  int count = outTempStream.Read(buffer, index, toRead);
84  if (count == 0)
85  break;
86 
87  index += count;
88  toRead -= count;
89  }
90 
91  // Send the part of the streamable object to the database.
92  largeObject.Write(offset, buffer, blockRead);
93  // Increment the offset and upload the next part of the object.
94  offset += blockRead;
95  }
96  } finally {
97  outTempStream.SetLength(0);
98  }
99  }
readonly ILargeObject largeObject
Definition: ObjectStream.cs:22
void Write(long offset, byte[] buffer, int length)
Write the given binary content into the object, starting at the given offset for the number of bytes ...
override int Deveel.Data.Store.ObjectStream.Read ( byte[]  buffer,
int  offset,
int  count 
)
inline

Definition at line 109 of file ObjectStream.cs.

109  {
110  if (!largeObject.IsComplete)
111  throw new IOException("The underlying object is not complete.");
112 
113  if (count <= 0) {
114  return 0;
115  }
116 
117  if (readBufferPos == -1) {
119  }
120 
121  int p = (int) (position - readBufferPos);
122  long bufferEnd = System.Math.Min(readBufferPos + BufferSize, largeObject.RawSize);
123  int toRead = (int) System.Math.Min((long) count, bufferEnd - position);
124  if (toRead <= 0) {
125  return 0;
126  }
127  int hasRead = 0;
128  while (toRead > 0) {
129  Array.Copy(readBuf, p, buffer, offset, toRead);
130  hasRead += toRead;
131  p += toRead;
132  offset += toRead;
133  count -= toRead;
134  position += toRead;
135  if (p >= BufferSize) {
137  p -= BufferSize;
138  }
139  bufferEnd = System.Math.Min(readBufferPos + BufferSize, largeObject.RawSize);
140  toRead = (int) System.Math.Min((long)count, bufferEnd - position);
141  }
142 
143  return hasRead;
144  }
readonly ILargeObject largeObject
Definition: ObjectStream.cs:22
long RawSize
Gets the raw byte size of the object.
Definition: ILargeObject.cs:56
bool IsComplete
Gets a value indicating if the object is in its complete state, that means it cannot be written furth...
Definition: ILargeObject.cs:69
void Deveel.Data.Store.ObjectStream.ReadPageContent ( byte[]  buffer,
long  pos,
int  length 
)
inlineprivate

Definition at line 42 of file ObjectStream.cs.

42  {
43  largeObject.Read(pos, buffer, length);
44  }
readonly ILargeObject largeObject
Definition: ObjectStream.cs:22
int Read(long offset, byte[] buffer, int length)
Reads the content of the object, starting at a given offset, into the buffer given, for the number of bytes specified.
override long Deveel.Data.Store.ObjectStream.Seek ( long  offset,
SeekOrigin  origin 
)
inline

Definition at line 101 of file ObjectStream.cs.

101  {
102  throw new NotImplementedException();
103  }
override void Deveel.Data.Store.ObjectStream.SetLength ( long  value)
inline

Definition at line 105 of file ObjectStream.cs.

105  {
106  throw new NotSupportedException("The lenght of the underlying object cannot be changed.");
107  }
override void Deveel.Data.Store.ObjectStream.Write ( byte[]  buffer,
int  offset,
int  count 
)
inline

Definition at line 146 of file ObjectStream.cs.

146  {
148  throw new IOException("The underlying object is complete.");
149 
150  outTempStream.Write(buffer, offset, count);
151  position += count;
152  }
readonly ILargeObject largeObject
Definition: ObjectStream.cs:22
bool IsComplete
Gets a value indicating if the object is in its complete state, that means it cannot be written furth...
Definition: ILargeObject.cs:69

Member Data Documentation

const int Deveel.Data.Store.ObjectStream.BufferSize = 64*1024
private

Definition at line 29 of file ObjectStream.cs.

readonly ILargeObject Deveel.Data.Store.ObjectStream.largeObject
private

Definition at line 22 of file ObjectStream.cs.

Stream Deveel.Data.Store.ObjectStream.outTempStream
private

Definition at line 24 of file ObjectStream.cs.

long Deveel.Data.Store.ObjectStream.position
private

Definition at line 23 of file ObjectStream.cs.

readonly byte [] Deveel.Data.Store.ObjectStream.readBuf
private

Definition at line 27 of file ObjectStream.cs.

long Deveel.Data.Store.ObjectStream.readBufferPos
private

Definition at line 26 of file ObjectStream.cs.

Property Documentation

override bool Deveel.Data.Store.ObjectStream.CanRead
get

Definition at line 154 of file ObjectStream.cs.

override bool Deveel.Data.Store.ObjectStream.CanSeek
get

Definition at line 158 of file ObjectStream.cs.

override bool Deveel.Data.Store.ObjectStream.CanWrite
get

Definition at line 162 of file ObjectStream.cs.

override long Deveel.Data.Store.ObjectStream.Length
get

Definition at line 166 of file ObjectStream.cs.

override long Deveel.Data.Store.ObjectStream.Position
getset

Definition at line 170 of file ObjectStream.cs.


The documentation for this class was generated from the following file: