annotate src/org/eclipse/jetty/io/ByteArrayBuffer.java @ 1030:80cad9086593

remove Buffer.isVolatile()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Nov 2016 01:10:09 -0600
parents 4e5e9e3c25b3
children b71ad168fe34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.io;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.io.InputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.io.OutputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import java.io.UnsupportedEncodingException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import org.eclipse.jetty.util.StringUtil;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 1010
diff changeset
28
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 public class ByteArrayBuffer extends AbstractBuffer
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 {
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
31 // Set a maximum size to a write for the writeTo method, to ensure that very large content is not
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
32 // written as a single write (which may fall foul to write timeouts if consumed slowly).
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
33 final static int MAX_WRITE=Integer.getInteger("org.eclipse.jetty.io.ByteArrayBuffer.MAX_WRITE",128*1024);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
34 final protected byte[] _bytes;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35
1030
80cad9086593 remove Buffer.isVolatile()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1029
diff changeset
36 protected ByteArrayBuffer(int size, int access)
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
37 {
1030
80cad9086593 remove Buffer.isVolatile()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1029
diff changeset
38 this(new byte[size],0,0,access);
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
39 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
40
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
41 public ByteArrayBuffer(byte[] bytes)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
42 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
43 this(bytes, 0, bytes.length, READWRITE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
44 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
46 public ByteArrayBuffer(byte[] bytes, int index, int length)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
47 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
48 this(bytes, index, length, READWRITE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 public ByteArrayBuffer(byte[] bytes, int index, int length, int access)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52 {
1030
80cad9086593 remove Buffer.isVolatile()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1029
diff changeset
53 super(READWRITE);
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 _bytes = bytes;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
55 setPutIndex(index + length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
56 setGetIndex(index);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
57 _access = access;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
58 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 public ByteArrayBuffer(int size)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62 this(new byte[size], 0, 0, READWRITE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 setPutIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 public ByteArrayBuffer(String value)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 {
1030
80cad9086593 remove Buffer.isVolatile()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1029
diff changeset
68 super(READWRITE);
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 _bytes = StringUtil.getBytes(value);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 setGetIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71 setPutIndex(_bytes.length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 _access=IMMUTABLE;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 _string = value;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
76 @Override
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
77 public final byte[] array()
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 return _bytes;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
82 @Override
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
83 public final int capacity()
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 return _bytes.length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
89 public final void compact()
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 int s = markIndex() >= 0 ? markIndex() : getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 if (s > 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 int length = putIndex() - s;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 if (length > 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 System.arraycopy(_bytes, s,_bytes, 0, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 if (markIndex() > 0) setMarkIndex(markIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 setGetIndex(getIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 setPutIndex(putIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
106
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
107
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
109 public final boolean equals(Object obj)
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 if (obj==this)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112 return true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 if (obj == null || !(obj instanceof Buffer))
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 Buffer b = (Buffer) obj;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 // reject different lengths
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 if (b.length() != length())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 // reject AbstractBuffer with different hash value
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 if (_hash != 0 && obj instanceof AbstractBuffer)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 AbstractBuffer ab = (AbstractBuffer) obj;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 if (ab._hash != 0 && _hash != ab._hash)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 // Nothing for it but to do the hard grind.
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 int bi=b.putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
135 for (int i = putIndex(); i-->get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 byte b2 = b.peek(--bi);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 if (b1 != b2) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
140 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
145 public final byte get()
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 return _bytes[_get++];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
151 public final int hashCode()
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 if (_hash == 0 || _hashGet!=_get || _hashPut!=_put)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 for (int i = putIndex(); i-- >get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 byte b = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 if ('a' <= b && b <= 'z')
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160 b = (byte) (b - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 _hash = 31 * _hash + b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
163 if (_hash == 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 _hash = -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 _hashGet=_get;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 _hashPut=_put;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 return _hash;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
169 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
172 @Override
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
173 public final byte peek(int index)
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 return _bytes[index];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
178 @Override
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
179 public final int peek(int index, byte[] b, int offset, int length)
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
180 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
181 int l = length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 if (index + l > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
183 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
184 l = capacity() - index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 if (l==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 if (l < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
191
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 System.arraycopy(_bytes, index, b, offset, l);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 return l;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
196 @Override
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
197 public final void poke(int index, byte b)
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
198 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
199 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
203 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
204 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 if (index > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 _bytes[index] = b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
209 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
210
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
211 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
212 public final int poke(int index, Buffer src)
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
213 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
214 _hash=0;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
215
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
216 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
217 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
218 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 int length=src.length();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
224 if (index + length > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
225 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
226 length=capacity()-index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
227 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
229 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
230 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
231 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
232
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
233 byte[] src_array = src.array();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
234 if (src_array != null)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
235 System.arraycopy(src_array, src.getIndex(), _bytes, index, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
236 else
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 int s=src.getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 for (int i=0;i<length;i++)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 _bytes[index++]=src.peek(s++);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
241 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
242
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
243 return length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
246
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
248 public final int poke(int index, byte[] b, int offset, int length)
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 _hash=0;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
251 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
252 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
256 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
257
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
258 if (index + length > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
259 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
260 length=capacity()-index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261 /* if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
262 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
263 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
264 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
265
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266 System.arraycopy(b, offset, _bytes, index, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
267
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
268 return length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
269 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
272 public final int readFrom(InputStream in,int max) throws IOException
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 if (max<0||max>space())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275 max=space();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
276 int p = putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
278 int len=0, total=0, available=max;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
279 while (total<max)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 len=in.read(_bytes,p,available);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
282 if (len<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283 break;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
284 else if (len>0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
285 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
286 p += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
287 total += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 available -= len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 setPutIndex(p);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
290 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
291 if (in.available()<=0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
292 break;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
293 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
294 if (len<0 && total==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
295 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
296 return total;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
297 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
298
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 @Override
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1026
diff changeset
300 public final int space()
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
301 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
302 return _bytes.length - _put;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
303 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
304
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
305 }