annotate src/org/eclipse/jetty/io/ByteArrayBuffer.java @ 1018:4dc1e1a18661

remove HttpSchemes
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 24 Oct 2016 05:37:24 -0600
parents 2712133d5bce
children 6647dbc8be71
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
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
36 protected ByteArrayBuffer(int size, int access, boolean isVolatile)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
37 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
38 this(new byte[size],0,0,access, isVolatile);
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 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
53 super(READWRITE, NON_VOLATILE);
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(byte[] bytes, int index, int length, int access, boolean isVolatile)
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 super(READWRITE, isVolatile);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 _bytes = bytes;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 setPutIndex(index + length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 setGetIndex(index);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 _access = access;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 public ByteArrayBuffer(int size)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71 this(new byte[size], 0, 0, READWRITE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 setPutIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 public ByteArrayBuffer(String value)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 super(READWRITE,NON_VOLATILE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 _bytes = StringUtil.getBytes(value);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 setGetIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 setPutIndex(_bytes.length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 _access=IMMUTABLE;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 _string = value;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 }
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 public ByteArrayBuffer(String value,boolean immutable)
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 super(READWRITE,NON_VOLATILE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 _bytes = StringUtil.getBytes(value);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 setGetIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 setPutIndex(_bytes.length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 if (immutable)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 _access=IMMUTABLE;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 _string = value;
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 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 public ByteArrayBuffer(String value,String encoding) throws UnsupportedEncodingException
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 super(READWRITE,NON_VOLATILE);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 _bytes = value.getBytes(encoding);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 setGetIndex(0);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 setPutIndex(_bytes.length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 _access=IMMUTABLE;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 _string = value;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 }
802
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 public byte[] array()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 return _bytes;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 public int capacity()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 return _bytes.length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 }
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 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 public void compact()
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 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 int s = markIndex() >= 0 ? markIndex() : getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 if (s > 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 int length = putIndex() - s;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 if (length > 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 System.arraycopy(_bytes, s,_bytes, 0, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 if (markIndex() > 0) setMarkIndex(markIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 setGetIndex(getIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 setPutIndex(putIndex() - s);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
135 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 public boolean equals(Object obj)
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 if (obj==this)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 return true;
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 if (obj == null || !(obj instanceof Buffer))
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 return false;
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 if (obj instanceof Buffer.CaseInsensitve)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 return equalsIgnoreCase((Buffer)obj);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
149
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 Buffer b = (Buffer) obj;
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 // reject different lengths
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 if (b.length() != length())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 // reject AbstractBuffer with different hash value
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 if (_hash != 0 && obj instanceof AbstractBuffer)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160 AbstractBuffer ab = (AbstractBuffer) obj;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 if (ab._hash != 0 && _hash != ab._hash)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
163 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 // Nothing for it but to do the hard grind.
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 int bi=b.putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 for (int i = putIndex(); i-->get;)
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 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 byte b2 = b.peek(--bi);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
172 if (b1 != b2) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
173 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
179 public boolean equalsIgnoreCase(Buffer b)
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 if (b==this)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 return true;
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 // reject different lengths
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 if (b==null || b.length() != length())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188 // reject AbstractBuffer with different hash value
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 if (_hash != 0 && b instanceof AbstractBuffer)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
191 AbstractBuffer ab = (AbstractBuffer) b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 if (ab._hash != 0 && _hash != ab._hash) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
195 // Nothing for it but to do the hard grind.
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
196 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
197 int bi=b.putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
198 byte[] barray=b.array();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
199 if (barray==null)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 for (int i = putIndex(); i-->get;)
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 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
204 byte b2 = b.peek(--bi);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 if (b1 != b2)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
209 if (b1 != b2) return false;
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 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
212 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
213 else
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 for (int i = putIndex(); i-->get;)
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 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
218 byte b2 = barray[--bi];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 if (b1 != b2)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 if (b1 != b2) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
224 }
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 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
227 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
230 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
231 public byte get()
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 return _bytes[_get++];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
234 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
235
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
236 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 public int hashCode()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 if (_hash == 0 || _hashGet!=_get || _hashPut!=_put)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
240 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
241 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
242 for (int i = putIndex(); i-- >get;)
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 byte b = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245 if ('a' <= b && b <= 'z')
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
246 b = (byte) (b - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 _hash = 31 * _hash + b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
248 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 if (_hash == 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 _hash = -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
251 _hashGet=_get;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
252 _hashPut=_put;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
253 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
254 return _hash;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 }
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 public byte peek(int index)
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 return _bytes[index];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
261 }
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 public int peek(int index, byte[] b, int offset, int length)
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 int l = length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266 if (index + l > capacity())
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 l = capacity() - index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
269 if (l==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
272
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
273 if (l < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 return -1;
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 System.arraycopy(_bytes, index, b, offset, l);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 return l;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
278 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
279
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 public void poke(int index, byte b)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
282 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
283 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
284 throw new IllegalStateException(__READONLY);
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 (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
287 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 if (index > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
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 _bytes[index] = b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
292 }
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 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
295 public int poke(int index, Buffer src)
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 _hash=0;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298
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 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
301 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
302 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
303 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
305
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
306 int length=src.length();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
307 if (index + length > capacity())
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 length=capacity()-index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
310 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
311 if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
312 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
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 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
315
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
316 byte[] src_array = src.array();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
317 if (src_array != null)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
318 System.arraycopy(src_array, src.getIndex(), _bytes, index, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
319 else
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
320 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
321 int s=src.getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
322 for (int i=0;i<length;i++)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
323 _bytes[index++]=src.peek(s++);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
324 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
325
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
326 return length;
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
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
329
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
330 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
331 public int poke(int index, byte[] b, int offset, int length)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
332 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
333 _hash=0;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
334 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
335 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
336 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
337 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
338 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
339 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
340
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
341 if (index + length > capacity())
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 length=capacity()-index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
344 /* if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
345 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
346 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
347 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
348
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
349 System.arraycopy(b, offset, _bytes, index, length);
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 return length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
352 }
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 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
355 public int readFrom(InputStream in,int max) throws IOException
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 if (max<0||max>space())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
358 max=space();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
359 int p = putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
360
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
361 int len=0, total=0, available=max;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
362 while (total<max)
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 len=in.read(_bytes,p,available);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
365 if (len<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
366 break;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
367 else if (len>0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
368 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
369 p += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
370 total += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
371 available -= len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
372 setPutIndex(p);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
373 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
374 if (in.available()<=0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
375 break;
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 (len<0 && total==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
378 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
379 return total;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
380 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
381
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
382 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
383 public int space()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
384 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
385 return _bytes.length - _put;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
386 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
387
1010
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 public static class CaseInsensitive extends ByteArrayBuffer implements Buffer.CaseInsensitve
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
390 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
391 public CaseInsensitive(String s)
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 super(s);
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 CaseInsensitive(byte[] b, int o, int l, int rw)
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 super(b,o,l,rw);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
399 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
400
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
401 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
402 public boolean equals(Object obj)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
403 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
404 return obj instanceof Buffer && equalsIgnoreCase((Buffer)obj);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
405 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
406
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
407 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
408 }