annotate src/org/eclipse/jetty/io/ByteArrayBuffer.java @ 1010:2712133d5bce

simplify Buffer code
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Oct 2016 22:23:50 -0600
parents 3428c60d7cfc
children 4dc1e1a18661
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
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 /* ------------------------------------------------------------------------------- */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 public class ByteArrayBuffer extends AbstractBuffer
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 {
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
34 // 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
35 // 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
36 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
37 final protected byte[] _bytes;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
39 protected ByteArrayBuffer(int size, int access, boolean isVolatile)
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 this(new byte[size],0,0,access, isVolatile);
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
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
44 public ByteArrayBuffer(byte[] bytes)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
45 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
46 this(bytes, 0, bytes.length, READWRITE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
47 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 public ByteArrayBuffer(byte[] bytes, int index, int length)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
50 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 this(bytes, index, length, READWRITE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 public ByteArrayBuffer(byte[] bytes, int index, int length, int access)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
55 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
56 super(READWRITE, NON_VOLATILE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
57 _bytes = bytes;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
58 setPutIndex(index + length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
59 setGetIndex(index);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 _access = access;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 public ByteArrayBuffer(byte[] bytes, int index, int length, int access, boolean isVolatile)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 super(READWRITE, isVolatile);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 _bytes = bytes;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 setPutIndex(index + length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 setGetIndex(index);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 _access = access;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 public ByteArrayBuffer(int size)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 this(new byte[size], 0, 0, READWRITE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 setPutIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 public ByteArrayBuffer(String value)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 super(READWRITE,NON_VOLATILE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 _bytes = StringUtil.getBytes(value);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 setGetIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 setPutIndex(_bytes.length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84 _access=IMMUTABLE;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 _string = value;
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 public ByteArrayBuffer(String value,boolean immutable)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 super(READWRITE,NON_VOLATILE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 _bytes = StringUtil.getBytes(value);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 setGetIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 setPutIndex(_bytes.length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 if (immutable)
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 _access=IMMUTABLE;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 _string = value;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
100
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 public ByteArrayBuffer(String value,String encoding) throws UnsupportedEncodingException
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 super(READWRITE,NON_VOLATILE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 _bytes = value.getBytes(encoding);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 setGetIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 setPutIndex(_bytes.length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 _access=IMMUTABLE;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 _string = value;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 public byte[] array()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 return _bytes;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 public int capacity()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 return _bytes.length;
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
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 public void compact()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 int s = markIndex() >= 0 ? markIndex() : getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 if (s > 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 int length = putIndex() - s;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 if (length > 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 System.arraycopy(_bytes, s,_bytes, 0, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 if (markIndex() > 0) setMarkIndex(markIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
135 setGetIndex(getIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 setPutIndex(putIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 public boolean equals(Object obj)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 if (obj==this)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 return true;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 if (obj == null || !(obj instanceof Buffer))
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
149
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 if (obj instanceof Buffer.CaseInsensitve)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 return equalsIgnoreCase((Buffer)obj);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 Buffer b = (Buffer) obj;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 // reject different lengths
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 if (b.length() != length())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160 // reject AbstractBuffer with different hash value
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 if (_hash != 0 && obj instanceof AbstractBuffer)
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 AbstractBuffer ab = (AbstractBuffer) obj;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 if (ab._hash != 0 && _hash != ab._hash)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 // Nothing for it but to do the hard grind.
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
169 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170 int bi=b.putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 for (int i = putIndex(); i-->get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
172 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
173 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 byte b2 = b.peek(--bi);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 if (b1 != b2) return false;
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 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
181 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 public boolean equalsIgnoreCase(Buffer b)
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 if (b==this)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 // reject different lengths
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188 if (b==null || b.length() != length())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
191 // reject AbstractBuffer with different hash value
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 if (_hash != 0 && b instanceof AbstractBuffer)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 AbstractBuffer ab = (AbstractBuffer) b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
195 if (ab._hash != 0 && _hash != ab._hash) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
196 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
198 // Nothing for it but to do the hard grind.
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
199 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 int bi=b.putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 byte[] barray=b.array();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202 if (barray==null)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
203 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
204 for (int i = putIndex(); i-->get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 byte b2 = b.peek(--bi);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 if (b1 != b2)
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 if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
211 if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
212 if (b1 != b2) return false;
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 }
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 else
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
217 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
218 for (int i = putIndex(); i-->get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 byte b2 = barray[--bi];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 if (b1 != b2)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
224 if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
225 if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
226 if (b1 != b2) return false;
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 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
229 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
230 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
231 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
233 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
234 public byte get()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
235 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
236 return _bytes[_get++];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
238
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 public int hashCode()
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 if (_hash == 0 || _hashGet!=_get || _hashPut!=_put)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
243 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245 for (int i = putIndex(); i-- >get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
246 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 byte b = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
248 if ('a' <= b && b <= 'z')
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 b = (byte) (b - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 _hash = 31 * _hash + b;
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 (_hash == 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253 _hash = -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 _hashGet=_get;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 _hashPut=_put;
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 return _hash;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
258 }
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
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261 public byte peek(int index)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
262 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
263 return _bytes[index];
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 public int peek(int index, byte[] b, int offset, int 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 int l = length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
269 if (index + l > capacity())
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 l = capacity() - index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
272 if (l==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
276 if (l < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
278
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
279 System.arraycopy(_bytes, index, b, offset, l);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 return l;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283 public void poke(int index, byte b)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
284 {
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 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
287 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
290 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
291 if (index > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
292 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
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 _bytes[index] = b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
295 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
296
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
297 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298 public int poke(int index, Buffer src)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
300 _hash=0;
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 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
303 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
305 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
306 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
307 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
308
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
309 int length=src.length();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
310 if (index + length > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
311 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
312 length=capacity()-index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
313 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
314 if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
315 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
316 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
317 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
318
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
319 byte[] src_array = src.array();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
320 if (src_array != null)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
321 System.arraycopy(src_array, src.getIndex(), _bytes, index, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
322 else
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
323 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
324 int s=src.getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
325 for (int i=0;i<length;i++)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
326 _bytes[index++]=src.peek(s++);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
327 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
328
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
329 return length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
330 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
331
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
333 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
334 public int poke(int index, byte[] b, int offset, int length)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
335 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
336 _hash=0;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
337 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
338 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
339 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
340 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
341 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
342 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
343
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
344 if (index + length > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
345 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
346 length=capacity()-index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
347 /* if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
348 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
349 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
350 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
351
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
352 System.arraycopy(b, offset, _bytes, index, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
353
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
354 return length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
355 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
356
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
357 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
358 public int readFrom(InputStream in,int max) throws IOException
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
359 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
360 if (max<0||max>space())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
361 max=space();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
362 int p = putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
363
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
364 int len=0, total=0, available=max;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
365 while (total<max)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
366 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
367 len=in.read(_bytes,p,available);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
368 if (len<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
369 break;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
370 else if (len>0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
371 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
372 p += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
373 total += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
374 available -= len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
375 setPutIndex(p);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
376 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
377 if (in.available()<=0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
378 break;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
379 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
380 if (len<0 && total==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
381 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
382 return total;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
383 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
384
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
385 /* ------------------------------------------------------------ */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
386 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
387 public int space()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
388 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
389 return _bytes.length - _put;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
390 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
391
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
392
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
393 /* ------------------------------------------------------------ */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
394 /* ------------------------------------------------------------ */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
395 /* ------------------------------------------------------------ */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
396 public static class CaseInsensitive extends ByteArrayBuffer implements Buffer.CaseInsensitve
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
397 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
398 public CaseInsensitive(String s)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
399 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
400 super(s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
401 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
402
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
403 public CaseInsensitive(byte[] b, int o, int l, int rw)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
404 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
405 super(b,o,l,rw);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
406 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
407
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
408 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
409 public boolean equals(Object obj)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
410 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
411 return obj instanceof Buffer && equalsIgnoreCase((Buffer)obj);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
412 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
413
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
414 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
415 }