Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/View.java @ 1020:6be43ef1eb96
HttpHeaderValues uses StringCache
| author | Franklin Schmidt <fschmidt@gmail.com> | 
|---|---|
| date | Mon, 31 Oct 2016 22:24:41 -0600 | 
| parents | 0e96ce3db20a | 
| children | cf0367978d8b | 
| 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 /** | 
| 
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
22 * A View on another buffer. Allows operations that do not change the _content or | 
| 
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
23 * indexes of the backing buffer. | 
| 
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
24 * | 
| 
 
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 * | 
| 
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
27 */ | 
| 
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
28 public class View extends AbstractBuffer | 
| 
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
29 { | 
| 1005 | 30 Buffer _buffer; | 
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
31 | 
| 1005 | 32 /** | 
| 33 * @param buffer The <code>Buffer</code> on which we are presenting a <code>View</code>. | |
| 34 * @param mark The initial value of the {@link Buffer#markIndex mark index} | |
| 35 * @param get The initial value of the {@link Buffer#getIndex get index} | |
| 36 * @param put The initial value of the {@link Buffer#putIndex put index} | |
| 37 * @param access The access level - one of the constants from {@link Buffer}. | |
| 38 */ | |
| 39 public View(Buffer buffer, int mark, int get, int put,int access) | |
| 40 { | |
| 41 super(READWRITE,!buffer.isImmutable()); | |
| 42 _buffer=buffer.buffer(); | |
| 43 setPutIndex(put); | |
| 44 setGetIndex(get); | |
| 45 setMarkIndex(mark); | |
| 46 _access=access; | |
| 47 } | |
| 48 | |
| 49 public View(Buffer buffer) | |
| 50 { | |
| 51 super(READWRITE,!buffer.isImmutable()); | |
| 52 _buffer=buffer.buffer(); | |
| 53 setPutIndex(buffer.putIndex()); | |
| 54 setGetIndex(buffer.getIndex()); | |
| 55 setMarkIndex(buffer.markIndex()); | |
| 56 _access=buffer.isReadOnly()?READONLY:READWRITE; | |
| 57 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
58 | 
| 1005 | 59 public View() | 
| 60 { | |
| 61 super(READWRITE,true); | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * Update view to buffer | |
| 66 */ | |
| 67 public void update(Buffer buffer) | |
| 68 { | |
| 69 _access=READWRITE; | |
| 70 _buffer=buffer.buffer(); | |
| 71 setGetIndex(0); | |
| 72 setPutIndex(buffer.putIndex()); | |
| 73 setGetIndex(buffer.getIndex()); | |
| 74 setMarkIndex(buffer.markIndex()); | |
| 75 _access=buffer.isReadOnly()?READONLY:READWRITE; | |
| 76 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
77 | 
| 1005 | 78 public void update(int get, int put) | 
| 79 { | |
| 80 int a=_access; | |
| 81 _access=READWRITE; | |
| 82 setGetIndex(0); | |
| 83 setPutIndex(put); | |
| 84 setGetIndex(get); | |
| 85 setMarkIndex(-1); | |
| 86 _access=a; | |
| 87 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
88 | 
| 1005 | 89 /** | 
| 90 * @return The {@link Buffer#array()} from the underlying buffer. | |
| 91 */ | |
| 92 public byte[] array() | |
| 93 { | |
| 94 return _buffer.array(); | |
| 95 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
96 | 
| 1005 | 97 /** | 
| 98 * @return The {@link Buffer#buffer()} from the underlying buffer. | |
| 99 */ | |
| 100 @Override | |
| 101 public Buffer buffer() | |
| 102 { | |
| 103 return _buffer.buffer(); | |
| 104 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
105 | 
| 1005 | 106 /** | 
| 107 * @return The {@link Buffer#capacity} of the underlying buffer. | |
| 108 */ | |
| 109 public int capacity() | |
| 110 { | |
| 111 return _buffer.capacity(); | |
| 112 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
113 | 
| 1005 | 114 /** | 
| 115 * | |
| 116 */ | |
| 117 @Override | |
| 118 public void clear() | |
| 119 { | |
| 120 setMarkIndex(-1); | |
| 121 setGetIndex(0); | |
| 122 setPutIndex(_buffer.getIndex()); | |
| 123 setGetIndex(_buffer.getIndex()); | |
| 124 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
125 | 
| 1005 | 126 /** | 
| 127 * | |
| 128 */ | |
| 129 @Override | |
| 130 public void compact() | |
| 131 { | |
| 132 // TODO | |
| 133 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
134 | 
| 1005 | 135 /* | 
| 136 * (non-Javadoc) | |
| 137 * | |
| 138 * @see java.lang.Object#equals(java.lang.Object) | |
| 139 */ | |
| 140 @Override | |
| 141 public boolean equals(Object obj) | |
| 142 { | |
| 143 return this==obj ||((obj instanceof Buffer)&& obj.equals(this)) || super.equals(obj); | |
| 144 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
145 | 
| 1005 | 146 /** | 
| 147 * @return Whether the underlying buffer is {@link Buffer#isReadOnly read only} | |
| 148 */ | |
| 149 @Override | |
| 150 public boolean isReadOnly() | |
| 151 { | |
| 152 return _buffer.isReadOnly(); | |
| 153 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
154 | 
| 1005 | 155 /** | 
| 156 * @return Whether the underlying buffer is {@link Buffer#isVolatile volatile} | |
| 157 */ | |
| 158 @Override | |
| 159 public boolean isVolatile() | |
| 160 { | |
| 161 return true; | |
| 162 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
163 | 
| 1005 | 164 /** | 
| 165 * @return The result of calling {@link Buffer#peek(int)} on the underlying buffer | |
| 166 */ | |
| 167 public byte peek(int index) | |
| 168 { | |
| 169 return _buffer.peek(index); | |
| 170 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
171 | 
| 1005 | 172 /** | 
| 173 * @return The result of calling {@link Buffer#peek(int, byte[], int, int)} on the underlying buffer | |
| 174 */ | |
| 175 public int peek(int index, byte[] b, int offset, int length) | |
| 176 { | |
| 177 return _buffer.peek(index,b,offset,length); | |
| 178 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
179 | 
| 1005 | 180 /** | 
| 181 * @return The result of calling {@link Buffer#peek(int, int)} on the underlying buffer | |
| 182 */ | |
| 183 @Override | |
| 184 public Buffer peek(int index, int length) | |
| 185 { | |
| 186 return _buffer.peek(index, length); | |
| 187 } | |
| 188 | |
| 189 /** | |
| 190 * @param index | |
| 191 * @param src | |
| 192 */ | |
| 193 @Override | |
| 194 public int poke(int index, Buffer src) | |
| 195 { | |
| 196 return _buffer.poke(index,src); | |
| 197 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
198 | 
| 1005 | 199 /** | 
| 200 * @param index | |
| 201 * @param b | |
| 202 */ | |
| 203 public void poke(int index, byte b) | |
| 204 { | |
| 205 _buffer.poke(index,b); | |
| 206 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
207 | 
| 1005 | 208 /** | 
| 209 * @param index | |
| 210 * @param b | |
| 211 * @param offset | |
| 212 * @param length | |
| 213 */ | |
| 214 @Override | |
| 215 public int poke(int index, byte[] b, int offset, int length) | |
| 216 { | |
| 217 return _buffer.poke(index,b,offset,length); | |
| 218 } | |
| 219 | |
| 220 @Override | |
| 221 public String toString() | |
| 222 { | |
| 223 if (_buffer==null) | |
| 224 return "INVALID"; | |
| 225 return super.toString(); | |
| 226 } | |
| 227 | |
| 228 public static class CaseInsensitive extends View implements Buffer.CaseInsensitve | |
| 229 { | |
| 230 public CaseInsensitive() | |
| 231 { | |
| 232 super(); | |
| 233 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
234 | 
| 1005 | 235 public CaseInsensitive(Buffer buffer, int mark, int get, int put, int access) | 
| 236 { | |
| 237 super(buffer,mark,get,put,access); | |
| 238 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
239 | 
| 1005 | 240 public CaseInsensitive(Buffer buffer) | 
| 241 { | |
| 242 super(buffer); | |
| 243 } | |
| 244 | |
| 245 @Override | |
| 246 public boolean equals(Object obj) | |
| 247 { | |
| 248 return this==obj ||((obj instanceof Buffer)&&((Buffer)obj).equalsIgnoreCase(this)) || super.equals(obj); | |
| 249 } | |
| 250 } | |
| 
802
 
3428c60d7cfc
replace jetty jars with source
 
Franklin Schmidt <fschmidt@gmail.com> 
parents:  
diff
changeset
 | 
251 } | 
