Home | History | Annotate | Download | only in util

Lines Matching refs:offset

49     public void consume(byte[] buf, int offset, int length) throws IOException {
50 if (offset < 0) {
53 throw new IndexOutOfBoundsException("offset: " + offset);
55 if (offset > buf.length) {
59 "offset: " + offset + ", buf.length: " + buf.length);
66 System.arraycopy(buf, offset, mArray, mSize, length);
116 public ByteBuffer getByteBuffer(long offset, int size) {
117 checkChunkValid(offset, size);
119 // checkChunkValid ensures that it's OK to cast offset to int.
120 return ByteBuffer.wrap(mArray, (int) offset, size).slice();
124 public void feed(long offset, long size, DataSink sink) throws IOException {
125 checkChunkValid(offset, size);
127 // checkChunkValid ensures that it's OK to cast offset and size to int.
128 sink.consume(mArray, (int) offset, (int) size);
132 public void copyTo(long offset, int size, ByteBuffer dest) throws IOException {
133 checkChunkValid(offset, size);
135 // checkChunkValid ensures that it's OK to cast offset to int.
136 dest.put(mArray, (int) offset, size);
139 private void checkChunkValid(long offset, long size) {
140 if (offset < 0) {
141 throw new IndexOutOfBoundsException("offset: " + offset);
146 if (offset > mSize) {
148 "offset (" + offset + ") > source size (" + mSize + ")");
150 long endOffset = offset + size;
151 if (endOffset < offset) {
153 "offset (" + offset + ") + size (" + size + ") overflow");
157 "offset (" + offset + ") + size (" + size + ") > source size (" + mSize + ")");
162 public DataSource slice(long offset, long size) {
163 checkChunkValid(offset, size);
164 // checkChunkValid ensures that it's OK to cast offset and size to int.
165 return new SliceDataSource((int) offset, (int) size);
169 * Slice of the growable byte array. The slice's offset and size in the array are fixed.
175 private SliceDataSource(int offset, int size) {
176 mSliceOffset = offset;
186 public void feed(long offset, long size, DataSink sink) throws IOException {
187 checkChunkValid(offset, size);
189 // that mSliceOffset + offset does not overflow and that it's fine to cast size to int.
190 sink.consume(mArray, (int) (mSliceOffset + offset), (int) size);
194 public ByteBuffer getByteBuffer(long offset, int size) throws IOException {
195 checkChunkValid(offset, size);
197 // that mSliceOffset + offset does not overflow.
198 return ByteBuffer.wrap(mArray, (int) (mSliceOffset + offset), size).slice();
202 public void copyTo(long offset, int size, ByteBuffer dest) throws IOException {
203 checkChunkValid(offset, size);
205 // that mSliceOffset + offset does not overflow.
206 dest.put(mArray, (int) (mSliceOffset + offset), size);
210 public DataSource slice(long offset, long size) {
211 checkChunkValid(offset, size);
213 // that mSliceOffset + offset does not overflow and that it's fine to cast size to int.
214 return new SliceDataSource((int) (mSliceOffset + offset), (int) size);
217 private void checkChunkValid(long offset, long size) {
218 if (offset < 0) {
219 throw new IndexOutOfBoundsException("offset: " + offset);
224 if (offset > mSliceSize) {
226 "offset (" + offset + ") > source size (" + mSliceSize + ")");
228 long endOffset = offset + size;
229 if (endOffset < offset) {
231 "offset (" + offset + ") + size (" + size + ") overflow");
235 "offset (" + offset + ") + size (" + size + ") > source size (" + mSliceSize