annotate src/org/eclipse/jetty/io/BufferUtil.java @ 1068:9d357b9e4bcb

fix BufferUtil.newBuffer()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 10 Nov 2016 00:23:05 -0700
parents bbbda7c6e8ec
children 6b7ff30bb990
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
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
21 import java.nio.ByteBuffer;
1054
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
22 import java.nio.charset.Charset;
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
23 import org.eclipse.jetty.util.StringUtil;
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
24
802
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 /** Buffer utility methods.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 *
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 */
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
31 public final class BufferUtil
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 {
1056
Franklin Schmidt <fschmidt@gmail.com>
parents: 1055
diff changeset
33 private static final byte[] DIGIT=
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
34 {(byte)'0',(byte)'1',(byte)'2',(byte)'3',(byte)'4',(byte)'5',(byte)'6',(byte)'7',(byte)'8',(byte)'9',(byte)'A',(byte)'B',(byte)'C',(byte)'D',(byte)'E',(byte)'F'};
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
36
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
37 /**
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
38 * Convert string to an long.
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
39 * Parses up to the first non-numeric character. If no number is found an
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
40 * IllegalArgumentException is thrown
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
41 */
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
42 public static long toLong(String s)
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
43 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
44 long val = 0;
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
45 boolean started= false;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
46 boolean minus= false;
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
47 for (int i = 0; i < s.length(); i++)
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
48 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
49 char c = s.charAt(i);
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
50 if (c <= ' ')
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
51 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
52 if (started)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
53 break;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
54 }
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
55 else if (c >= '0' && c <= '9')
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
56 {
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
57 val= val * 10L + (c - '0');
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
58 started= true;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
59 }
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
60 else if (c == '-' && !started)
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
61 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
62 minus= true;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
63 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
64 else
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
65 break;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
66 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
68 if (started)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
69 return minus ? (-val) : val;
1020
6be43ef1eb96 HttpHeaderValues uses StringCache
Franklin Schmidt <fschmidt@gmail.com>
parents: 1019
diff changeset
70 throw new NumberFormatException(s);
1018
4dc1e1a18661 remove HttpSchemes
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
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
73 public static void putHexInt(JBuffer buffer, int n)
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
74 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
75
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
76 if (n < 0)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
77 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
78 buffer.putQ((byte)'-');
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
80 if (n == Integer.MIN_VALUE)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
81 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
82 buffer.putQ((byte)(0x7f&'8'));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
83 buffer.putQ((byte)(0x7f&'0'));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
84 buffer.putQ((byte)(0x7f&'0'));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
85 buffer.putQ((byte)(0x7f&'0'));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
86 buffer.putQ((byte)(0x7f&'0'));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
87 buffer.putQ((byte)(0x7f&'0'));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
88 buffer.putQ((byte)(0x7f&'0'));
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
89 buffer.putQ((byte)(0x7f&'0'));
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
90
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
91 return;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
92 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
93 n= -n;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
94 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
96 if (n < 0x10)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
97 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
98 buffer.putQ(DIGIT[n]);
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
99 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
100 else
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
101 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
102 boolean started= false;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
103 // This assumes constant time int arithmatic
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
104 for (int i= 0; i < hexDivisors.length; i++)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
105 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
106 if (n < hexDivisors[i])
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
107 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
108 if (started)
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
109 buffer.putQ((byte)'0');
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
110 continue;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
111 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
113 started= true;
1056
Franklin Schmidt <fschmidt@gmail.com>
parents: 1055
diff changeset
114 int d = n / hexDivisors[i];
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
115 buffer.putQ(DIGIT[d]);
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
116 n= n - d * hexDivisors[i];
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
117 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
118 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
119 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
121 public static void putDecLong(JBuffer buffer, long n)
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
122 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
123 if (n < 0)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
124 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
125 buffer.putQ((byte)'-');
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
126
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
127 if (n == Long.MIN_VALUE)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
128 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
129 buffer.putQ((byte)'9');
1056
Franklin Schmidt <fschmidt@gmail.com>
parents: 1055
diff changeset
130 n = 223372036854775808L;
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
131 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
132 else
1056
Franklin Schmidt <fschmidt@gmail.com>
parents: 1055
diff changeset
133 n = -n;
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
134 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
136 if (n < 10)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
137 {
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
138 buffer.putQ(DIGIT[(int)n]);
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
139 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
140 else
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
141 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
142 boolean started= false;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
143 // This assumes constant time int arithmatic
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
144 for (int i= 0; i < decDivisorsL.length; i++)
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
145 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
146 if (n < decDivisorsL[i])
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
147 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
148 if (started)
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
149 buffer.putQ((byte)'0');
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
150 continue;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
151 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
153 started= true;
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
154 long d= n / decDivisorsL[i];
1066
bbbda7c6e8ec fix use of HttpGenerator._header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1065
diff changeset
155 buffer.putQ(DIGIT[(int)d]);
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
156 n= n - d * decDivisorsL[i];
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
157 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
158 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
159 }
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
160
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
161 private final static int[] hexDivisors=
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
162 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
163 0x10000000,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
164 0x1000000,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
165 0x100000,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
166 0x10000,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
167 0x1000,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
168 0x100,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
169 0x10,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
170 0x1
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
171 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172
1018
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
173 private final static long[] decDivisorsL=
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
174 {
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
175 1000000000000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
176 100000000000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
177 10000000000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
178 1000000000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
179 100000000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
180 10000000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
181 1000000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
182 100000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
183 10000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
184 1000000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
185 100000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
186 10000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
187 1000000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
188 100000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
189 10000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
190 1000L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
191 100L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
192 10L,
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
193 1L
4dc1e1a18661 remove HttpSchemes
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
194 };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
197
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
198 public static final JBuffer EMPTY_BUFFER = new JBuffer(ByteBuffer.allocate(0));
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
199
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
200 public static JBuffer wrap(byte[] array,int offset,int length) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
201 return new JBuffer(ByteBuffer.wrap(array,offset,length));
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
202 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
203
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
204 public static JBuffer wrap(byte[] array) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
205 return new JBuffer(ByteBuffer.wrap(array));
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
206 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
207
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
208 public static JBuffer wrap(String s) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
209 byte[] bytes = StringUtil.getBytes(s);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
210 ByteBuffer bb = ByteBuffer.wrap(bytes).asReadOnlyBuffer();
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
211 return new JBuffer(bb);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
212 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
213
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
214 public static JBuffer newBuffer(int size) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
215 ByteBuffer bb = ByteBuffer.allocate(size);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
216 return new JBuffer(bb);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
217 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
218
1048
2b769da7f67d remove Buffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1046
diff changeset
219 public static JBuffer newDirectBuffer(int size) {
1046
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
220 ByteBuffer bb = ByteBuffer.allocateDirect(size);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
221 return new JBuffer(bb);
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
222 }
a8c92b0a08ed add JBuffer
Franklin Schmidt <fschmidt@gmail.com>
parents: 1021
diff changeset
223
1054
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
224
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
225
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
226 private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
227
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
228 public static String getString(JBuffer buffer) {
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
229 byte[] bytes = new byte[buffer.remaining()];
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
230 buffer.get(bytes);
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
231 return new String(bytes,ISO_8859_1);
87275900646e remove JBuffer.toString()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1052
diff changeset
232 }
1065
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
233
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
234 public static void compact(JBuffer buffer) {
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
235 buffer.compact();
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
236 buffer.limit(buffer.position());
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
237 buffer.position(0);
158d1e6ac17f fix JBuffer.compact()
Franklin Schmidt <fschmidt@gmail.com>
parents: 1059
diff changeset
238 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
239 }