comparison src/org/eclipse/jetty/io/AbstractBuffer.java @ 1044:dd71a59fcf72

remove buffer marking
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Nov 2016 02:26:54 -0600
parents ae1c92957739
children a8c92b0a08ed
comparison
equal deleted inserted replaced
1043:ae1c92957739 1044:dd71a59fcf72
44 protected int _get; 44 protected int _get;
45 protected int _put; 45 protected int _put;
46 protected int _hash; 46 protected int _hash;
47 protected int _hashGet; 47 protected int _hashGet;
48 protected int _hashPut; 48 protected int _hashPut;
49 protected int _mark;
50 49
51 /** 50 /**
52 * Constructor for BufferView 51 * Constructor for BufferView
53 * 52 *
54 * @param access 1==READONLY, 2==READWRITE 53 * @param access 1==READONLY, 2==READWRITE
55 */ 54 */
56 protected AbstractBuffer(int access) 55 protected AbstractBuffer(int access)
57 { 56 {
58 setMarkIndex(-1);
59 _access = access; 57 _access = access;
60 } 58 }
61 59
62 private byte[] asArray() 60 private byte[] asArray()
63 { 61 {
75 return this; 73 return this;
76 } 74 }
77 75
78 public void clear() 76 public void clear()
79 { 77 {
80 setMarkIndex(-1);
81 setGetIndex(0); 78 setGetIndex(0);
82 setPutIndex(0); 79 setPutIndex(0);
83 } 80 }
84 81
85 public void compact() 82 public void compact()
86 { 83 {
87 if (isReadOnly()) throw new IllegalStateException(__READONLY); 84 if (isReadOnly()) throw new IllegalStateException(__READONLY);
88 int s = markIndex() >= 0 ? markIndex() : getIndex(); 85 int s = getIndex();
89 if (s > 0) 86 if (s > 0)
90 { 87 {
91 byte array[] = array(); 88 byte array[] = array();
92 int length = putIndex() - s; 89 int length = putIndex() - s;
93 if (length > 0) 90 if (length > 0)
95 if (array != null) 92 if (array != null)
96 System.arraycopy(array(), s, array(), 0, length); 93 System.arraycopy(array(), s, array(), 0, length);
97 else 94 else
98 poke(0, peek(s, length)); 95 poke(0, peek(s, length));
99 } 96 }
100 if (markIndex() > 0) setMarkIndex(markIndex() - s);
101 setGetIndex(getIndex() - s); 97 setGetIndex(getIndex() - s);
102 setPutIndex(putIndex() - s); 98 setPutIndex(putIndex() - s);
103 } 99 }
104 } 100 }
105 101
218 public int remaining() 214 public int remaining()
219 { 215 {
220 return _put - _get; 216 return _put - _get;
221 } 217 }
222 218
223 public void mark()
224 {
225 setMarkIndex(_get - 1);
226 }
227
228 public int markIndex()
229 {
230 return _mark;
231 }
232
233 public byte peek() 219 public byte peek()
234 { 220 {
235 return peek(_get); 221 return peek(_get);
236 } 222 }
237 223
342 public final int putIndex() 328 public final int putIndex()
343 { 329 {
344 return _put; 330 return _put;
345 } 331 }
346 332
347 public void rewind() 333 public final void rewind()
348 { 334 {
349 setGetIndex(0); 335 setGetIndex(0);
350 setMarkIndex(-1);
351 } 336 }
352 337
353 public void setGetIndex(int getIndex) 338 public void setGetIndex(int getIndex)
354 { 339 {
355 _get = getIndex; 340 _get = getIndex;
356 _hash=0; 341 _hash=0;
357 }
358
359 public void setMarkIndex(int index)
360 {
361 _mark = index;
362 } 342 }
363 343
364 public void setPutIndex(int putIndex) 344 public void setPutIndex(int putIndex)
365 { 345 {
366 _put = putIndex; 346 _put = putIndex;
377 public Buffer slice() 357 public Buffer slice()
378 { 358 {
379 return peek(getIndex(), remaining()); 359 return peek(getIndex(), remaining());
380 } 360 }
381 361
382 public Buffer sliceFromMark() 362 public final Buffer sliceFrom(int index) {
383 { 363 return peek(index, getIndex()-index-1);
384 return sliceFromMark(getIndex() - markIndex() - 1);
385 }
386
387 public Buffer sliceFromMark(int length)
388 {
389 if (markIndex() < 0) return null;
390 Buffer view = peek(markIndex(), length);
391 setMarkIndex(-1);
392 return view;
393 } 364 }
394 365
395 public int space() 366 public int space()
396 { 367 {
397 return capacity() - _put; 368 return capacity() - _put;
402 StringBuilder buf = new StringBuilder(); 373 StringBuilder buf = new StringBuilder();
403 buf.append("["); 374 buf.append("[");
404 buf.append(super.hashCode()); 375 buf.append(super.hashCode());
405 buf.append(","); 376 buf.append(",");
406 buf.append(this.buffer().hashCode()); 377 buf.append(this.buffer().hashCode());
407 buf.append(",m=");
408 buf.append(markIndex());
409 buf.append(",g="); 378 buf.append(",g=");
410 buf.append(getIndex()); 379 buf.append(getIndex());
411 buf.append(",p="); 380 buf.append(",p=");
412 buf.append(putIndex()); 381 buf.append(putIndex());
413 buf.append(",c="); 382 buf.append(",c=");
414 buf.append(capacity()); 383 buf.append(capacity());
415 buf.append("]={"); 384 buf.append("]={");
416 if (markIndex() >= 0)
417 {
418 for (int i = markIndex(); i < getIndex(); i++)
419 {
420 byte b = peek(i);
421 TypeUtil.toHex(b,buf);
422 }
423 buf.append("}{");
424 }
425 int count = 0; 385 int count = 0;
426 for (int i = getIndex(); i < putIndex(); i++) 386 for (int i = getIndex(); i < putIndex(); i++)
427 { 387 {
428 byte b = peek(i); 388 byte b = peek(i);
429 TypeUtil.toHex(b,buf); 389 TypeUtil.toHex(b,buf);