annotate src/org/eclipse/jetty/io/AbstractBuffers.java @ 1007:945568ee77ac

remove HttpBuffersImpl
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 23 Oct 2016 17:40:20 -0600
parents 58a9c4a42292
children
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 org.eclipse.jetty.io.nio.DirectNIOBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 public abstract class AbstractBuffers implements Buffers
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 {
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
26 protected final Buffers.Type _headerType;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
27 protected final int _headerSize;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
28 protected final Buffers.Type _bufferType;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
29 protected final int _bufferSize;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
31 public AbstractBuffers(Buffers.Type headerType, int headerSize, Buffers.Type bufferType, int bufferSize)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
32 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
33 _headerType=headerType;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
34 _headerSize=headerSize;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
35 _bufferType=bufferType;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
36 _bufferSize=bufferSize;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
37 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
39 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
40 /**
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
41 * @return Returns the buffer size in bytes.
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
42 */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
43 public int getBufferSize()
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
44 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
45 return _bufferSize;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
46 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
48 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
49 /**
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
50 * @return Returns the header size in bytes.
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52 public int getHeaderSize()
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
53 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 return _headerSize;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
55 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
58 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
59 /**
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
60 * Create a new header Buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 * @return new Buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62 */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 final protected Buffer newHeader()
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 switch(_headerType)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
67 case DIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 return new DirectNIOBuffer(_headerSize);
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 case INDIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
70 return new IndirectNIOBuffer(_headerSize);
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
71 }
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
72 throw new IllegalStateException();
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
73 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 /**
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 * Create a new content Buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
78 * @return new Buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
79 */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 final protected Buffer newBuffer()
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
82 switch(_bufferType)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
83 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
84 case DIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
85 return new DirectNIOBuffer(_bufferSize);
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
86 case INDIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
87 return new IndirectNIOBuffer(_bufferSize);
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
88 }
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
89 throw new IllegalStateException();
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 /**
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 * Create a new content Buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
95 * @param size
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 * @return new Buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
98 final protected Buffer newBuffer(int size)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 switch(_bufferType)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 case DIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 return new DirectNIOBuffer(size);
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 case INDIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 return new IndirectNIOBuffer(size);
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 }
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 throw new IllegalStateException();
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 /**
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
112 * @param buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 * @return True if the buffer is the correct type to be a Header buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
114 */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
115 public final boolean isHeader(Buffer buffer)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 if (buffer.capacity()==_headerSize)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 switch(_headerType)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
120 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
121 case DIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 return buffer instanceof DirectNIOBuffer;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 case INDIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 return buffer instanceof IndirectNIOBuffer;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
125 }
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126 }
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 return false;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
130 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 /**
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 * @param buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
133 * @return True if the buffer is the correct type to be a Header buffer
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
135 public final boolean isBuffer(Buffer buffer)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 if (buffer.capacity()==_bufferSize)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
138 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 switch(_bufferType)
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
140 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 case DIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 return buffer instanceof DirectNIOBuffer;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 case INDIRECT:
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 return buffer instanceof IndirectNIOBuffer;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 }
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146 }
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 return false;
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149
1006
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 /* ------------------------------------------------------------ */
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 public String toString()
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
152 {
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 return String.format("%s [%d,%d]", getClass().getSimpleName(), _headerSize, _bufferSize);
58a9c4a42292 simplify Buffers code
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 }