annotate src/org/eclipse/jetty/io/AbstractBuffer.java @ 1044:dd71a59fcf72

remove buffer marking
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Nov 2016 02:26:54 -0600
parents ae1c92957739
children a8c92b0a08ed
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.nio.charset.Charset;
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.TypeUtil;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
27 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
28 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 /**
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 public abstract class AbstractBuffer implements Buffer
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 {
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
36 private static final Logger LOG = LoggerFactory.getLogger(AbstractBuffer.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
38 private final static boolean __boundsChecking = Boolean.getBoolean("org.eclipse.jetty.io.AbstractBuffer.boundsChecking");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
39
1031
921c25a05eaa remove Buffer.asReadOnlyBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1030
diff changeset
40 protected final static String __READONLY = "READONLY";
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
41
1039
a7319f14ba1e remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1038
diff changeset
42 int _access;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
44 protected int _get;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
45 protected int _put;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
46 protected int _hash;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
47 protected int _hashGet;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
48 protected int _hashPut;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 /**
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51 * Constructor for BufferView
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
52 *
1039
a7319f14ba1e remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1038
diff changeset
53 * @param access 1==READONLY, 2==READWRITE
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 */
1030
80cad9086593 remove Buffer.isVolatile()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1029
diff changeset
55 protected AbstractBuffer(int access)
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 _access = access;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59
1040
3e4949834f3e remove Buffer.asArray()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1039
diff changeset
60 private byte[] asArray()
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 {
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
62 byte[] bytes = new byte[remaining()];
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 byte[] array = array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 if (array != null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 System.arraycopy(array, getIndex(), bytes, 0, bytes.length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 else
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
67 peek(getIndex(), bytes, 0, remaining());
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 return bytes;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 public Buffer buffer()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 return this;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 public void clear()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 setGetIndex(0);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 setPutIndex(0);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 public void compact()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 if (isReadOnly()) throw new IllegalStateException(__READONLY);
1044
dd71a59fcf72 remove buffer marking
Franklin Schmidt <fschmidt@gmail.com>
parents: 1043
diff changeset
85 int s = getIndex();
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 if (s > 0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 byte array[] = array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 int length = putIndex() - s;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 if (length > 0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 if (array != null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 System.arraycopy(array(), s, array(), 0, length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 else
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 poke(0, peek(s, length));
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 setGetIndex(getIndex() - s);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 setPutIndex(putIndex() - s);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
101
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 public boolean equals(Object obj)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 if (obj==this)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 return true;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 // reject non buffers;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 if (obj == null || !(obj instanceof Buffer)) return false;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 Buffer b = (Buffer) obj;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 // reject different lengths
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
113 if (b.remaining() != remaining()) return false;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 // reject AbstractBuffer with different hash value
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 if (_hash != 0 && obj instanceof AbstractBuffer)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 AbstractBuffer ab = (AbstractBuffer) obj;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 if (ab._hash != 0 && _hash != ab._hash) return false;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 // Nothing for it but to do the hard grind.
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 int get=getIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 int bi=b.putIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 for (int i = putIndex(); i-->get;)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 byte b1 = peek(i);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 byte b2 = b.peek(--bi);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 if (b1 != b2) return false;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 return true;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 public byte get()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 return peek(_get++);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 public int get(byte[] b, int offset, int length)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 int gi = getIndex();
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
142 int l=remaining();
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 if (l==0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 return -1;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 if (length>l)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 length=l;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 length = peek(gi, b, offset, length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 if (length>0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 setGetIndex(gi + length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 return length;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 public Buffer get(int length)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 int gi = getIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 Buffer view = peek(gi, length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 setGetIndex(gi + length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 return view;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 public final int getIndex()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 return _get;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167
1037
3c4c7cc7904f rename Buffer.hasContent() to hasRemaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1032
diff changeset
168 public boolean hasRemaining()
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 return _put > _get;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 public int hashCode()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 if (_hash == 0 || _hashGet!=_get || _hashPut!=_put)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 int get=getIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 byte[] array = array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 if (array==null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 for (int i = putIndex(); i-- >get;)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 byte b = peek(i);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 if ('a' <= b && b <= 'z')
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 b = (byte) (b - 'a' + 'A');
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 _hash = 31 * _hash + b;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 else
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 for (int i = putIndex(); i-- >get;)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 byte b = array[i];
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 if ('a' <= b && b <= 'z')
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 b = (byte) (b - 'a' + 'A');
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 _hash = 31 * _hash + b;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 if (_hash == 0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 _hash = -1;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 _hashGet=_get;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 _hashPut=_put;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 return _hash;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 public boolean isReadOnly()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 return _access <= READONLY;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
214 public int remaining()
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 return _put - _get;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 public byte peek()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 return peek(_get);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223
1032
Franklin Schmidt <fschmidt@gmail.com>
parents: 1031
diff changeset
224 private Buffer peek(int index, int length)
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 {
1041
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
226 Buffer view = duplicate();
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
227 view.setPutIndex(index + length);
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
228 view.setGetIndex(index);
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
229 return view;
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1010
diff changeset
232 @Override
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 public int poke(int index, Buffer src)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 _hash=0;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
237 int length=src.remaining();
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 if (index + length > capacity())
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 length=capacity()-index;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 /*
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 if (length<0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 */
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 byte[] src_array = src.array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 byte[] dst_array = array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 if (src_array != null && dst_array != null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 System.arraycopy(src_array, src.getIndex(), dst_array, index, length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 else if (src_array != null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 int s=src.getIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 for (int i=0;i<length;i++)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 poke(index++,src_array[s++]);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 else if (dst_array != null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 int s=src.getIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 for (int i=0;i<length;i++)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 dst_array[index++]=src.peek(s++);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 else
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 int s=src.getIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 for (int i=0;i<length;i++)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 poke(index++,src.peek(s++));
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 return length;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
273
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 public int poke(int index, byte[] b, int offset, int length)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 _hash=0;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 if (index + length > capacity())
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 length=capacity()-index;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 /* if (length<0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 throw new IllegalArgumentException("index>capacity(): " + index + ">" + capacity());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 */
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 byte[] dst_array = array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 if (dst_array != null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 System.arraycopy(b, offset, dst_array, index, length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 else
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 int s=offset;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 for (int i=0;i<length;i++)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 poke(index++,b[s++]);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 return length;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
296
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 public int put(Buffer src)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 int pi = putIndex();
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1010
diff changeset
300 int l = poke(pi, src);
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 setPutIndex(pi + l);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 return l;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
304
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 public void put(byte b)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 int pi = putIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 poke(pi, b);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 setPutIndex(pi + 1);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
311
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 public int put(byte[] b, int offset, int length)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 int pi = putIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 int l = poke(pi, b, offset, length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 setPutIndex(pi + l);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 return l;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 public int put(byte[] b)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 int pi = putIndex();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 int l = poke(pi, b, 0, b.length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 setPutIndex(pi + l);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 return l;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
327
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 public final int putIndex()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 return _put;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
332
1044
dd71a59fcf72 remove buffer marking
Franklin Schmidt <fschmidt@gmail.com>
parents: 1043
diff changeset
333 public final void rewind()
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 setGetIndex(0);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
337
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 public void setGetIndex(int getIndex)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 _get = getIndex;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 _hash=0;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
343
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 public void setPutIndex(int putIndex)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 _put = putIndex;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 _hash=0;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
349
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 public int skip(int n)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 {
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
352 if (remaining() < n) n = remaining();
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 setGetIndex(getIndex() + n);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354 return n;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
356
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 public Buffer slice()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 {
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
359 return peek(getIndex(), remaining());
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
361
1044
dd71a59fcf72 remove buffer marking
Franklin Schmidt <fschmidt@gmail.com>
parents: 1043
diff changeset
362 public final Buffer sliceFrom(int index) {
dd71a59fcf72 remove buffer marking
Franklin Schmidt <fschmidt@gmail.com>
parents: 1043
diff changeset
363 return peek(index, getIndex()-index-1);
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
365
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366 public int space()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 return capacity() - _put;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
370
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 public String toDetailString()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 StringBuilder buf = new StringBuilder();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 buf.append("[");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 buf.append(super.hashCode());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 buf.append(",");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 buf.append(this.buffer().hashCode());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 buf.append(",g=");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 buf.append(getIndex());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 buf.append(",p=");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 buf.append(putIndex());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 buf.append(",c=");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 buf.append(capacity());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 buf.append("]={");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 int count = 0;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 for (int i = getIndex(); i < putIndex(); i++)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 byte b = peek(i);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 TypeUtil.toHex(b,buf);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 if (count++ == 50)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 if (putIndex() - i > 20)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 buf.append(" ... ");
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 i = putIndex() - 20;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
396 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 buf.append('}');
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 return buf.toString();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
402
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 public String toString()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
406 return toString("ISO-8859-1");
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
408
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1010
diff changeset
409 @Override
1032
Franklin Schmidt <fschmidt@gmail.com>
parents: 1031
diff changeset
410 public final String toString(int index, int length) {
Franklin Schmidt <fschmidt@gmail.com>
parents: 1031
diff changeset
411 return peek(index,length).toString();
Franklin Schmidt <fschmidt@gmail.com>
parents: 1031
diff changeset
412 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 1031
diff changeset
413
Franklin Schmidt <fschmidt@gmail.com>
parents: 1031
diff changeset
414 @Override
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1010
diff changeset
415 public final String toString(String charset)
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 try
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419 byte[] bytes=array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 if (bytes!=null)
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
421 return new String(bytes,getIndex(),remaining(),charset);
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
422 return new String(asArray(), 0, remaining(),charset);
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 catch(Exception e)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 LOG.warn("",e);
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
428 return new String(asArray(), 0, remaining());
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
431
1019
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1010
diff changeset
432 @Override
f126d30e04a4 start replacing BufferCache with StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1010
diff changeset
433 public final String toString(Charset charset)
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 try
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 byte[] bytes=array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 if (bytes!=null)
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
439 return new String(bytes,getIndex(),remaining(),charset);
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
440 return new String(asArray(), 0, remaining(),charset);
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 catch(Exception e)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 LOG.warn("",e);
1038
b71ad168fe34 rename Buffer.length() to remaining()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1037
diff changeset
445 return new String(asArray(), 0, remaining());
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
448
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 /* ------------------------------------------------------------ */
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 public String toDebugString()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 return getClass()+"@"+super.hashCode();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
454
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 /* ------------------------------------------------------------ */
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 public int readFrom(InputStream in,int max) throws IOException
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 byte[] array = array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 int s=space();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 if (s>max)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 s=max;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
462
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 if (array!=null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465 int l=in.read(array,_put,s);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 if (l>0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 _put+=l;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 return l;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 else
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 byte[] buf=new byte[s>1024?1024:s];
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 int total=0;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 while (s>0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 int l=in.read(buf,0,buf.length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 if (l<0)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478 return total>0?total:-1;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 int p=put(buf,0,l);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 assert l==p;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 s-=l;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 return total;
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 }
1041
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
486
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
487 public final Buffer duplicate() {
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
488 return new View(this);
35e3c864d7a7 make View package local
Franklin Schmidt <fschmidt@gmail.com>
parents: 1040
diff changeset
489 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
490 }