23 namespace Lucene.Net.Index
41 protected internal byte[] data;
44 protected internal int internalOffset;
47 protected internal int internalLength;
62 public Payload(byte[] data):this(data, 0, data.Length)
77 public Payload(byte[] data,
int offset,
int length)
79 if (offset < 0 || offset + length > data.Length)
81 throw new System.ArgumentException();
84 this.internalOffset = offset;
85 this.internalLength = length;
92 public virtual void SetData(byte[] value,
int offset,
int length)
95 this.internalOffset = offset;
96 this.internalLength = length;
102 public virtual void SetData(byte[] value)
104 SetData(value, 0, value.Length);
110 public virtual byte[] GetData()
116 public virtual int Offset
118 get {
return this.internalOffset; }
122 public virtual int Length
124 get {
return this.internalLength; }
128 public virtual byte ByteAt(
int index)
130 if (0 <= index && index < this.internalLength)
132 return this.data[this.internalOffset + index];
134 throw new System. IndexOutOfRangeException(
"Index of bound " + index);
138 public virtual byte[] ToByteArray()
140 byte[] retArray =
new byte[this.internalLength];
141 Array.Copy(this.data, this.internalOffset, retArray, 0, this.internalLength);
152 public virtual void CopyTo(byte[] target,
int targetOffset)
154 if (this.internalLength > target.Length + targetOffset)
156 throw new System.IndexOutOfRangeException();
158 Array.Copy(this.data, this.internalOffset, target, targetOffset, this.internalLength);
164 public virtual System.Object Clone()
171 if (internalOffset == 0 && internalLength == data.Length)
174 clone.data =
new byte[data.Length];
175 data.CopyTo(clone.data, 0);
180 clone.data = this.ToByteArray();
181 clone.internalOffset = 0;
185 catch (System.Exception e)
187 throw new System.SystemException(e.Message, e);
191 public override bool Equals(System.Object obj)
198 if (internalLength == other.internalLength)
200 for (
int i = 0; i < internalLength; i++)
201 if (data[internalOffset + i] != other.data[other.internalOffset + i])
212 public override int GetHashCode()
214 return ArrayUtil.HashCode(data, internalOffset, internalOffset + internalLength);