comparison src/org/eclipse/jetty/io/AbstractBuffer.java @ 1038:b71ad168fe34

rename Buffer.length() to remaining()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Nov 2016 22:16:11 -0600
parents 3c4c7cc7904f
children a7319f14ba1e
comparison
equal deleted inserted replaced
1037:3c4c7cc7904f 1038:b71ad168fe34
61 _access = access; 61 _access = access;
62 } 62 }
63 63
64 public byte[] asArray() 64 public byte[] asArray()
65 { 65 {
66 byte[] bytes = new byte[length()]; 66 byte[] bytes = new byte[remaining()];
67 byte[] array = array(); 67 byte[] array = array();
68 if (array != null) 68 if (array != null)
69 System.arraycopy(array, getIndex(), bytes, 0, bytes.length); 69 System.arraycopy(array, getIndex(), bytes, 0, bytes.length);
70 else 70 else
71 peek(getIndex(), bytes, 0, length()); 71 peek(getIndex(), bytes, 0, remaining());
72 return bytes; 72 return bytes;
73 } 73 }
74 74
75 public Buffer buffer() 75 public Buffer buffer()
76 { 76 {
114 // reject non buffers; 114 // reject non buffers;
115 if (obj == null || !(obj instanceof Buffer)) return false; 115 if (obj == null || !(obj instanceof Buffer)) return false;
116 Buffer b = (Buffer) obj; 116 Buffer b = (Buffer) obj;
117 117
118 // reject different lengths 118 // reject different lengths
119 if (b.length() != length()) return false; 119 if (b.remaining() != remaining()) return false;
120 120
121 // reject AbstractBuffer with different hash value 121 // reject AbstractBuffer with different hash value
122 if (_hash != 0 && obj instanceof AbstractBuffer) 122 if (_hash != 0 && obj instanceof AbstractBuffer)
123 { 123 {
124 AbstractBuffer ab = (AbstractBuffer) obj; 124 AbstractBuffer ab = (AbstractBuffer) obj;
143 } 143 }
144 144
145 public int get(byte[] b, int offset, int length) 145 public int get(byte[] b, int offset, int length)
146 { 146 {
147 int gi = getIndex(); 147 int gi = getIndex();
148 int l=length(); 148 int l=remaining();
149 if (l==0) 149 if (l==0)
150 return -1; 150 return -1;
151 151
152 if (length>l) 152 if (length>l)
153 length=l; 153 length=l;
220 public boolean isReadOnly() 220 public boolean isReadOnly()
221 { 221 {
222 return _access <= READONLY; 222 return _access <= READONLY;
223 } 223 }
224 224
225 public int length() 225 public int remaining()
226 { 226 {
227 return _put - _get; 227 return _put - _get;
228 } 228 }
229 229
230 public void mark() 230 public void mark()
268 @Override 268 @Override
269 public int poke(int index, Buffer src) 269 public int poke(int index, Buffer src)
270 { 270 {
271 _hash=0; 271 _hash=0;
272 272
273 int length=src.length(); 273 int length=src.remaining();
274 if (index + length > capacity()) 274 if (index + length > capacity())
275 { 275 {
276 length=capacity()-index; 276 length=capacity()-index;
277 /* 277 /*
278 if (length<0) 278 if (length<0)
394 _hash=0; 394 _hash=0;
395 } 395 }
396 396
397 public int skip(int n) 397 public int skip(int n)
398 { 398 {
399 if (length() < n) n = length(); 399 if (remaining() < n) n = remaining();
400 setGetIndex(getIndex() + n); 400 setGetIndex(getIndex() + n);
401 return n; 401 return n;
402 } 402 }
403 403
404 public Buffer slice() 404 public Buffer slice()
405 { 405 {
406 return peek(getIndex(), length()); 406 return peek(getIndex(), remaining());
407 } 407 }
408 408
409 public Buffer sliceFromMark() 409 public Buffer sliceFromMark()
410 { 410 {
411 return sliceFromMark(getIndex() - markIndex() - 1); 411 return sliceFromMark(getIndex() - markIndex() - 1);
472 { 472 {
473 /* 473 /*
474 if (isImmutable()) 474 if (isImmutable())
475 { 475 {
476 if (_string == null) 476 if (_string == null)
477 _string = new String(asArray(), 0, length()); 477 _string = new String(asArray(), 0, remaining());
478 return _string; 478 return _string;
479 } 479 }
480 return new String(asArray(), 0, length()); 480 return new String(asArray(), 0, remaining());
481 */ 481 */
482 return toString("ISO-8859-1"); 482 return toString("ISO-8859-1");
483 } 483 }
484 484
485 @Override 485 @Override
492 { 492 {
493 try 493 try
494 { 494 {
495 byte[] bytes=array(); 495 byte[] bytes=array();
496 if (bytes!=null) 496 if (bytes!=null)
497 return new String(bytes,getIndex(),length(),charset); 497 return new String(bytes,getIndex(),remaining(),charset);
498 return new String(asArray(), 0, length(),charset); 498 return new String(asArray(), 0, remaining(),charset);
499 499
500 } 500 }
501 catch(Exception e) 501 catch(Exception e)
502 { 502 {
503 LOG.warn("",e); 503 LOG.warn("",e);
504 return new String(asArray(), 0, length()); 504 return new String(asArray(), 0, remaining());
505 } 505 }
506 } 506 }
507 507
508 @Override 508 @Override
509 public final String toString(Charset charset) 509 public final String toString(Charset charset)
510 { 510 {
511 try 511 try
512 { 512 {
513 byte[] bytes=array(); 513 byte[] bytes=array();
514 if (bytes!=null) 514 if (bytes!=null)
515 return new String(bytes,getIndex(),length(),charset); 515 return new String(bytes,getIndex(),remaining(),charset);
516 return new String(asArray(), 0, length(),charset); 516 return new String(asArray(), 0, remaining(),charset);
517 } 517 }
518 catch(Exception e) 518 catch(Exception e)
519 { 519 {
520 LOG.warn("",e); 520 LOG.warn("",e);
521 return new String(asArray(), 0, length()); 521 return new String(asArray(), 0, remaining());
522 } 522 }
523 } 523 }
524 524
525 /* ------------------------------------------------------------ */ 525 /* ------------------------------------------------------------ */
526 public String toDebugString() 526 public String toDebugString()