annotate src/org/eclipse/jetty/io/ByteArrayBuffer.java @ 1026:6647dbc8be71

remove Buffer.CaseInsensitve
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 02 Nov 2016 23:52:33 -0600
parents 4dc1e1a18661
children 4e5e9e3c25b3
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
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 Buffer b = (Buffer) obj;
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 // reject different lengths
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 if (b.length() != length())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 return false;
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 // reject AbstractBuffer with different hash value
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
155 if (_hash != 0 && obj instanceof AbstractBuffer)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 AbstractBuffer ab = (AbstractBuffer) obj;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 if (ab._hash != 0 && _hash != ab._hash)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 // Nothing for it but to do the hard grind.
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
163 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 int bi=b.putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 for (int i = putIndex(); i-->get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 byte b2 = b.peek(--bi);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
169 if (b1 != b2) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
172 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 public boolean equalsIgnoreCase(Buffer b)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 if (b==this)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
179 return true;
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 // reject different lengths
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 if (b==null || b.length() != length())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
183 return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 // reject AbstractBuffer with different hash value
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 if (_hash != 0 && b instanceof AbstractBuffer)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188 AbstractBuffer ab = (AbstractBuffer) b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 if (ab._hash != 0 && _hash != ab._hash) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 // Nothing for it but to do the hard grind.
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 int bi=b.putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
195 byte[] barray=b.array();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
196 if (barray==null)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
197 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
198 for (int i = putIndex(); i-->get;)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
199 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
200 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
201 byte b2 = b.peek(--bi);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
202 if (b1 != b2)
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 if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
205 if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
206 if (b1 != b2) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
207 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
208 }
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 else
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 for (int i = putIndex(); i-->get;)
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 byte b1 = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
215 byte b2 = barray[--bi];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
216 if (b1 != b2)
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 if ('a' <= b1 && b1 <= 'z') b1 = (byte) (b1 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
219 if ('a' <= b2 && b2 <= 'z') b2 = (byte) (b2 - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
220 if (b1 != b2) return false;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
221 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
222 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
223 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
224 return true;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
225 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
226
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
227 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
228 public byte get()
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 _bytes[_get++];
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 int hashCode()
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 if (_hash == 0 || _hashGet!=_get || _hashPut!=_put)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
237 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
238 int get=getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
239 for (int i = putIndex(); i-- >get;)
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 byte b = _bytes[i];
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
242 if ('a' <= b && b <= 'z')
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
243 b = (byte) (b - 'a' + 'A');
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
244 _hash = 31 * _hash + b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
245 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
246 if (_hash == 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
247 _hash = -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
248 _hashGet=_get;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
249 _hashPut=_put;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
250 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
251 return _hash;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
252 }
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
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
255 public byte peek(int index)
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 _bytes[index];
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 public int peek(int index, byte[] b, int offset, int length)
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 int l = length;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
263 if (index + l > capacity())
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 l = capacity() - index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
266 if (l==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
267 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
268 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
269
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
270 if (l < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
271 return -1;
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 System.arraycopy(_bytes, index, b, offset, l);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
274 return l;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
275 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
276
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
277 public void poke(int index, byte b)
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 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
280 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
281 throw new IllegalStateException(__READONLY);
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 (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
284 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
285 if (index > capacity())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
286 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
287 */
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
288 _bytes[index] = b;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
289 }
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 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
292 public int poke(int index, Buffer src)
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 _hash=0;
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 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
298 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
299 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
300 throw new IllegalArgumentException("index<0: " + index + "<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 int length=src.length();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
304 if (index + length > capacity())
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 length=capacity()-index;
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 if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
309 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
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 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
312
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
313 byte[] src_array = src.array();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
314 if (src_array != null)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
315 System.arraycopy(src_array, src.getIndex(), _bytes, index, length);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
316 else
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 int s=src.getIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
319 for (int i=0;i<length;i++)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
320 _bytes[index++]=src.peek(s++);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
321 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
322
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
323 return length;
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
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
326
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
327 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
328 public int poke(int index, byte[] b, int offset, int length)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
329 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
330 _hash=0;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
331 /*
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
332 if (isReadOnly())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
333 throw new IllegalStateException(__READONLY);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
334 if (index < 0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
335 throw new IllegalArgumentException("index<0: " + index + "<0");
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
336 */
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 (index + length > capacity())
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 length=capacity()-index;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
341 /* if (length<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
342 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
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 }
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 System.arraycopy(b, offset, _bytes, index, length);
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 return length;
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 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
352 public int readFrom(InputStream in,int max) throws IOException
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 if (max<0||max>space())
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
355 max=space();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
356 int p = putIndex();
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
357
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
358 int len=0, total=0, available=max;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
359 while (total<max)
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 len=in.read(_bytes,p,available);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
362 if (len<0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
363 break;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
364 else if (len>0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
365 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
366 p += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
367 total += len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
368 available -= len;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
369 setPutIndex(p);
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
370 }
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
371 if (in.available()<=0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
372 break;
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 (len<0 && total==0)
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
375 return -1;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
376 return total;
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
377 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
378
1010
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
379 @Override
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
380 public int space()
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
381 {
2712133d5bce simplify Buffer code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
382 return _bytes.length - _put;
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
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
385 }