annotate src/org/eclipse/jetty/io/View.java @ 1039:a7319f14ba1e

remove Buffer.isImmutable()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Nov 2016 22:55:28 -0600
parents eca26899c4bc
children 35e3c864d7a7
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 /**
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 */
1025
cf0367978d8b remove View.CaseInsensitive
Franklin Schmidt <fschmidt@gmail.com>
parents: 1005
diff changeset
28 public final class View extends AbstractBuffer
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 {
1025
cf0367978d8b remove View.CaseInsensitive
Franklin Schmidt <fschmidt@gmail.com>
parents: 1005
diff changeset
30 private Buffer _buffer;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
32 /**
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
33 * @param buffer The <code>Buffer</code> on which we are presenting a <code>View</code>.
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
34 * @param mark The initial value of the {@link Buffer#markIndex mark index}
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
35 * @param get The initial value of the {@link Buffer#getIndex get index}
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
36 * @param put The initial value of the {@link Buffer#putIndex put index}
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
37 * @param access The access level - one of the constants from {@link Buffer}.
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
38 */
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
39 public View(Buffer buffer, int mark, int get, int put,int access)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
40 {
1039
a7319f14ba1e remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1032
diff changeset
41 super(access);
a7319f14ba1e remove Buffer.isImmutable()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1032
diff changeset
42 _buffer = buffer.buffer();
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
43 setPutIndex(put);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
44 setGetIndex(get);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
45 setMarkIndex(mark);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
46 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
47
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
48 public View()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 {
1030
80cad9086593 remove Buffer.isVolatile()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1029
diff changeset
50 super(READWRITE);
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
53 /**
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 * Update view to buffer
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
55 */
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
56 public void update(Buffer buffer)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
57 {
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1025
diff changeset
58 _access = READWRITE;
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1025
diff changeset
59 _buffer = buffer.buffer();
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 setGetIndex(0);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 setPutIndex(buffer.putIndex());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62 setGetIndex(buffer.getIndex());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 setMarkIndex(buffer.markIndex());
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1025
diff changeset
64 _access = buffer.isReadOnly()?READONLY:READWRITE;
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1025
diff changeset
67 @Override
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 public byte[] array()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 return _buffer.array();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 public Buffer buffer()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 return _buffer.buffer();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1025
diff changeset
79 @Override
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 public int capacity()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 return _buffer.capacity();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86 public void clear()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 setMarkIndex(-1);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 setGetIndex(0);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 setPutIndex(_buffer.getIndex());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 setGetIndex(_buffer.getIndex());
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 public void compact()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 // TODO
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 /*
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 * (non-Javadoc)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 *
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 * @see java.lang.Object#equals(java.lang.Object)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 */
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 public boolean equals(Object obj)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 return this==obj ||((obj instanceof Buffer)&& obj.equals(this)) || super.equals(obj);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
109 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112 public boolean isReadOnly()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 return _buffer.isReadOnly();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 public byte peek(int index)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 return _buffer.peek(index);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1025
diff changeset
123 @Override
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 public int peek(int index, byte[] b, int offset, int length)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 return _buffer.peek(index,b,offset,length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
129 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 public int poke(int index, Buffer src)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 return _buffer.poke(index,src);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134
1029
4e5e9e3c25b3 remove Buffer.equalsIgnoreCase()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1025
diff changeset
135 @Override
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 public void poke(int index, byte b)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 _buffer.poke(index,b);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140
1005
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 public int poke(int index, byte[] b, int offset, int length)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 return _buffer.poke(index,b,offset,length);
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 }
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 @Override
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 public String toString()
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
149 {
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 if (_buffer==null)
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 return "INVALID";
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 return super.toString();
0e96ce3db20a remove HttpBuffers
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154 }