annotate src/org/eclipse/jetty/util/StringUtil.java @ 1048:2b769da7f67d

remove Buffer
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 07 Nov 2016 23:15:42 -0700
parents 6939226e0ac4
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.util;
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.UnsupportedEncodingException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.nio.charset.Charset;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
24 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
25 import org.slf4j.LoggerFactory;
802
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 /** Fast String Utilities.
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 * These string utilities provide both conveniance methods and
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 * performance improvements over most standard library versions. The
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 * main aim of the optimizations is to avoid object creation unless
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 * absolutely required.
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 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 */
1012
8d0bdd357e6e simplify StringUtil
Franklin Schmidt <fschmidt@gmail.com>
parents: 853
diff changeset
36 public final class StringUtil
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 {
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
38 private static final Logger LOG = LoggerFactory.getLogger(StringUtil.class);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
39
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
40 public static final String ALL_INTERFACES="0.0.0.0";
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
41
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
42 public static final String __ISO_8859_1="ISO-8859-1";
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
43 public final static String __UTF8="UTF-8";
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
44 public final static String __UTF16="UTF-16";
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
45
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
46 public final static Charset __UTF8_CHARSET;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
47 public final static Charset __ISO_8859_1_CHARSET;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
48
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
49 static
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51 __UTF8_CHARSET=Charset.forName(__UTF8);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
52 __ISO_8859_1_CHARSET=Charset.forName(__ISO_8859_1);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
53 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55 private static char[] lowercases = {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 '\000','\001','\002','\003','\004','\005','\006','\007',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 '\010','\011','\012','\013','\014','\015','\016','\017',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 '\020','\021','\022','\023','\024','\025','\026','\027',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 '\030','\031','\032','\033','\034','\035','\036','\037',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 '\040','\041','\042','\043','\044','\045','\046','\047',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 '\050','\051','\052','\053','\054','\055','\056','\057',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 '\060','\061','\062','\063','\064','\065','\066','\067',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 '\070','\071','\072','\073','\074','\075','\076','\077',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 '\100','\141','\142','\143','\144','\145','\146','\147',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 '\150','\151','\152','\153','\154','\155','\156','\157',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 '\160','\161','\162','\163','\164','\165','\166','\167',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 '\170','\171','\172','\133','\134','\135','\136','\137',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 '\140','\141','\142','\143','\144','\145','\146','\147',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 '\150','\151','\152','\153','\154','\155','\156','\157',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 '\160','\161','\162','\163','\164','\165','\166','\167',
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 '\170','\171','\172','\173','\174','\175','\176','\177' };
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 /* ------------------------------------------------------------ */
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 /**
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 * fast lower case conversion. Only works on ascii (not unicode)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 * @param s the string to convert
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 * @return a lower case version of s
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 */
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 public static String asciiToLowerCase(String s)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 char[] c = null;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 int i=s.length();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 // look for first conversion
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 while (i-->0)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 char c1=s.charAt(i);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 if (c1<=127)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 char c2=lowercases[c1];
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 if (c1!=c2)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 c=s.toCharArray();
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 c[i]=c2;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 break;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 while (i-->0)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 if(c[i]<=127)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 c[i] = lowercases[c[i]];
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 return c==null?s:new String(c);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 /* ------------------------------------------------------------ */
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 /**
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 * replace substrings within string.
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 */
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 public static String replace(String s, String sub, String with)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 int c=0;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 int i=s.indexOf(sub,c);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 if (i == -1)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 return s;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 StringBuilder buf = new StringBuilder(s.length()+with.length());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 do
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 buf.append(s.substring(c,i));
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 buf.append(with);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 c=i+sub.length();
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 } while ((i=s.indexOf(sub,c))!=-1);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 if (c<s.length())
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 buf.append(s.substring(c,s.length()));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 return buf.toString();
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 /* ------------------------------------------------------------ */
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 /**
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 * append hex digit
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 *
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 */
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 public static void append(StringBuilder buf,byte b,int base)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 int bi=0xff&b;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 int c='0'+(bi/base)%base;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 if (c>'9')
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 c= 'a'+(c-'0'-10);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 buf.append((char)c);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 c='0'+bi%base;
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 if (c>'9')
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 c= 'a'+(c-'0'-10);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 buf.append((char)c);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 public static void append2digits(StringBuilder buf,int i)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 if (i<100)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 buf.append((char)(i/10+'0'));
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 buf.append((char)(i%10+'0'));
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 public static String toString(byte[] b,int offset,int length,String charset)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 try
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 return new String(b,offset,length,charset);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 catch (UnsupportedEncodingException e)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 throw new IllegalArgumentException(e);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 public static boolean isUTF8(String charset)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 {
1013
6939226e0ac4 simplify URIUtil
Franklin Schmidt <fschmidt@gmail.com>
parents: 1012
diff changeset
178 return __UTF8.equalsIgnoreCase(charset)||"UTF8".equalsIgnoreCase(charset);
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
853
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 public static byte[] getBytes(String s)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 try
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 return s.getBytes(__ISO_8859_1);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 catch(Exception e)
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 {
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 LOG.warn("",e);
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 return s.getBytes();
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 }
3242aff51053 remove RolloverFileOutputStream and cleanup NCSARequestLog
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 }