Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/AbstractBuffer.java @ 1031:921c25a05eaa
remove Buffer.asReadOnlyBuffer()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 02:04:40 -0600 |
parents | 80cad9086593 |
children | eca26899c4bc |
comparison
equal
deleted
inserted
replaced
1030:80cad9086593 | 1031:921c25a05eaa |
---|---|
35 { | 35 { |
36 private static final Logger LOG = LoggerFactory.getLogger(AbstractBuffer.class); | 36 private static final Logger LOG = LoggerFactory.getLogger(AbstractBuffer.class); |
37 | 37 |
38 private final static boolean __boundsChecking = Boolean.getBoolean("org.eclipse.jetty.io.AbstractBuffer.boundsChecking"); | 38 private final static boolean __boundsChecking = Boolean.getBoolean("org.eclipse.jetty.io.AbstractBuffer.boundsChecking"); |
39 | 39 |
40 protected final static String | 40 protected final static String __READONLY = "READONLY"; |
41 __IMMUTABLE = "IMMUTABLE", | |
42 __READONLY = "READONLY", | |
43 __READWRITE = "READWRITE", | |
44 __VOLATILE = "VOLATILE"; | |
45 | 41 |
46 protected int _access; | 42 protected int _access; |
47 | 43 |
48 protected int _get; | 44 protected int _get; |
49 protected int _put; | 45 protected int _put; |
59 * | 55 * |
60 * @param access 0==IMMUTABLE, 1==READONLY, 2==READWRITE | 56 * @param access 0==IMMUTABLE, 1==READONLY, 2==READWRITE |
61 */ | 57 */ |
62 protected AbstractBuffer(int access) | 58 protected AbstractBuffer(int access) |
63 { | 59 { |
64 // if (access == IMMUTABLE && isVolatile) | |
65 // throw new IllegalArgumentException("IMMUTABLE && VOLATILE"); | |
66 setMarkIndex(-1); | 60 setMarkIndex(-1); |
67 _access = access; | 61 _access = access; |
68 } | 62 } |
69 | 63 |
70 /* | |
71 * @see org.eclipse.io.Buffer#toArray() | |
72 */ | |
73 public byte[] asArray() | 64 public byte[] asArray() |
74 { | 65 { |
75 byte[] bytes = new byte[length()]; | 66 byte[] bytes = new byte[length()]; |
76 byte[] array = array(); | 67 byte[] array = array(); |
77 if (array != null) | 68 if (array != null) |
78 System.arraycopy(array, getIndex(), bytes, 0, bytes.length); | 69 System.arraycopy(array, getIndex(), bytes, 0, bytes.length); |
79 else | 70 else |
80 peek(getIndex(), bytes, 0, length()); | 71 peek(getIndex(), bytes, 0, length()); |
81 return bytes; | 72 return bytes; |
82 } | |
83 | |
84 private ByteArrayBuffer duplicate(int access) | |
85 { | |
86 return new ByteArrayBuffer(asArray(), 0, length(), access); | |
87 } | |
88 | |
89 /* | |
90 * @see org.eclipse.util.Buffer#asReadOnlyBuffer() | |
91 */ | |
92 public Buffer asReadOnlyBuffer() | |
93 { | |
94 if (isReadOnly()) return this; | |
95 return new View(this, markIndex(), getIndex(), putIndex(), READONLY); | |
96 } | 73 } |
97 | 74 |
98 public Buffer buffer() | 75 public Buffer buffer() |
99 { | 76 { |
100 return this; | 77 return this; |
290 | 267 |
291 @Override | 268 @Override |
292 public int poke(int index, Buffer src) | 269 public int poke(int index, Buffer src) |
293 { | 270 { |
294 _hash=0; | 271 _hash=0; |
295 /* | |
296 if (isReadOnly()) | |
297 throw new IllegalStateException(__READONLY); | |
298 if (index < 0) | |
299 throw new IllegalArgumentException("index<0: " + index + "<0"); | |
300 */ | |
301 | 272 |
302 int length=src.length(); | 273 int length=src.length(); |
303 if (index + length > capacity()) | 274 if (index + length > capacity()) |
304 { | 275 { |
305 length=capacity()-index; | 276 length=capacity()-index; |
337 | 308 |
338 | 309 |
339 public int poke(int index, byte[] b, int offset, int length) | 310 public int poke(int index, byte[] b, int offset, int length) |
340 { | 311 { |
341 _hash=0; | 312 _hash=0; |
342 /* | |
343 if (isReadOnly()) | |
344 throw new IllegalStateException(__READONLY); | |
345 if (index < 0) | |
346 throw new IllegalArgumentException("index<0: " + index + "<0"); | |
347 */ | |
348 if (index + length > capacity()) | 313 if (index + length > capacity()) |
349 { | 314 { |
350 length=capacity()-index; | 315 length=capacity()-index; |
351 /* if (length<0) | 316 /* if (length<0) |
352 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); | 317 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity()); |
412 setMarkIndex(-1); | 377 setMarkIndex(-1); |
413 } | 378 } |
414 | 379 |
415 public void setGetIndex(int getIndex) | 380 public void setGetIndex(int getIndex) |
416 { | 381 { |
417 /* bounds checking | |
418 if (isImmutable()) | |
419 throw new IllegalStateException(__IMMUTABLE); | |
420 if (getIndex < 0) | |
421 throw new IllegalArgumentException("getIndex<0: " + getIndex + "<0"); | |
422 if (getIndex > putIndex()) | |
423 throw new IllegalArgumentException("getIndex>putIndex: " + getIndex + ">" + putIndex()); | |
424 */ | |
425 _get = getIndex; | 382 _get = getIndex; |
426 _hash=0; | 383 _hash=0; |
427 } | 384 } |
428 | 385 |
429 public void setMarkIndex(int index) | 386 public void setMarkIndex(int index) |
430 { | 387 { |
431 /* | |
432 if (index>=0 && isImmutable()) | |
433 throw new IllegalStateException(__IMMUTABLE); | |
434 */ | |
435 _mark = index; | 388 _mark = index; |
436 } | 389 } |
437 | 390 |
438 public void setPutIndex(int putIndex) | 391 public void setPutIndex(int putIndex) |
439 { | 392 { |
440 /* bounds checking | |
441 if (isImmutable()) | |
442 throw new IllegalStateException(__IMMUTABLE); | |
443 if (putIndex > capacity()) | |
444 throw new IllegalArgumentException("putIndex>capacity: " + putIndex + ">" + capacity()); | |
445 if (getIndex() > putIndex) | |
446 throw new IllegalArgumentException("getIndex>putIndex: " + getIndex() + ">" + putIndex); | |
447 */ | |
448 _put = putIndex; | 393 _put = putIndex; |
449 _hash=0; | 394 _hash=0; |
450 } | 395 } |
451 | 396 |
452 public int skip(int n) | 397 public int skip(int n) |