Skip to content

Commit c00b6e2

Browse files
committed
Renamed urlencode to encodeUrl.
Renamed urldecode to decodeUrl. Updates Javadocs to start method comments to use the verb form "Decodes" or "Encodes" instead of "Converts" to match method names. Refactored "US-ASCII" references to a static var. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130179 13f79535-47bb-0310-9956-ffa450edef68
1 parent e727c99 commit c00b6e2

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

src/java/org/apache/commons/codec/net/URLCodec.java

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//codec/src/java/org/apache/commons/codec/net/URLCodec.java,v 1.3 2003/07/31 20:09:21 tobrien Exp $
3-
* $Revision: 1.3 $
4-
* $Date: 2003/07/31 20:09:21 $
2+
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//codec/src/java/org/apache/commons/codec/net/URLCodec.java,v 1.4 2003/08/14 06:59:31 ggregory Exp $
3+
* $Revision: 1.4 $
4+
* $Date: 2003/08/14 06:59:31 $
55
*
66
* ====================================================================
77
*
@@ -72,12 +72,13 @@
7272
import org.apache.commons.codec.StringEncoder;
7373

7474
/**
75-
* URLCodec implements 'www-form-urlencoded' encoding scheme,
76-
* also misleadingly known as URL encoding.
77-
* For more detailed information please refer to
75+
* <p>Implements the 'www-form-urlencoded' encoding scheme,
76+
* also misleadingly known as URL encoding.</p>
77+
*
78+
* <p>For more detailed information please refer to
7879
* <a href="http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1">
7980
* Chapter 17.13.4 'Form content types'</a> of the
80-
* <a href="http://www.w3.org/TR/html4/">HTML 4.01 Specification<a>
81+
* <a href="http://www.w3.org/TR/html4/">HTML 4.01 Specification<a></p>
8182
*
8283
* <p>
8384
* This codec is meant to be a replacement for standard Java classes
@@ -87,14 +88,20 @@
8788
* </p>
8889
*
8990
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
90-
* @version $Id: URLCodec.java,v 1.3 2003/07/31 20:09:21 tobrien Exp $
91+
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
92+
* @version $Id: URLCodec.java,v 1.4 2003/08/14 06:59:31 ggregory Exp $
9193
*/
9294

9395
public class URLCodec
9496
implements BinaryEncoder, BinaryDecoder,
9597
StringEncoder, StringDecoder
9698
{
9799

100+
/**
101+
* The <code>String</code> encoding used for decoding and encoding.
102+
*/
103+
protected static final String ENCODING = "US-ASCII";
104+
98105
/**
99106
* BitSet of www-form-url safe characters.
100107
*/
@@ -124,22 +131,22 @@ public class URLCodec
124131

125132

126133
/**
127-
* Default constructor
134+
* Default constructor.
128135
*/
129136
public URLCodec() {
130137
super();
131138
}
132139

133140
/**
134-
* Converts an array of bytes into an array of URL safe 7-bit
141+
* Encodes an array of bytes into an array of URL safe 7-bit
135142
* characters. Unsafe characters are escaped.
136143
*
137144
* @param urlsafe bitset of characters deemed URL safe
138145
* @param pArray array of bytes to convert to URL safe characters
139146
* @return array of bytes containing URL safe characters
140147
* @throws EncoderException Thrown if URL encoding is unsuccessful
141148
*/
142-
public static final byte[] urlencode(BitSet urlsafe, byte[] pArray)
149+
public static final byte[] encodeUrl(BitSet urlsafe, byte[] pArray)
143150
throws EncoderException
144151
{
145152
if (pArray == null) {
@@ -172,15 +179,15 @@ public static final byte[] urlencode(BitSet urlsafe, byte[] pArray)
172179

173180

174181
/**
175-
* Converts an array of URL safe 7-bit characters into an array of
182+
* Decodes an array of URL safe 7-bit characters into an array of
176183
* original bytes. Escaped characters are converted back to their
177184
* original representation.
178185
*
179186
* @param pArray array of URL safe characters
180187
* @return array of original bytes
181188
* @throws DecoderException Thrown if URL decoding is unsuccessful
182189
*/
183-
public static final byte[] urldecode(byte[] pArray)
190+
public static final byte[] decodeUrl(byte[] pArray)
184191
throws DecoderException
185192
{
186193
if (pArray == null) {
@@ -211,20 +218,20 @@ public static final byte[] urldecode(byte[] pArray)
211218

212219

213220
/**
214-
* Converts an array of bytes into an array of URL safe 7-bit
221+
* Encodes an array of bytes into an array of URL safe 7-bit
215222
* characters. Unsafe characters are escaped.
216223
*
217224
* @param pArray array of bytes to convert to URL safe characters
218225
* @return array of bytes containing URL safe characters
219226
* @throws EncoderException Thrown if URL encoding is unsuccessful
220227
*/
221228
public byte[] encode(byte[] pArray) throws EncoderException {
222-
return urlencode(WWW_FORM_URL, pArray);
229+
return encodeUrl(WWW_FORM_URL, pArray);
223230
}
224231

225232

226233
/**
227-
* Converts an array of URL safe 7-bit characters into an array of
234+
* Decodes an array of URL safe 7-bit characters into an array of
228235
* original bytes. Escaped characters are converted back to their
229236
* original representation.
230237
*
@@ -233,12 +240,12 @@ public byte[] encode(byte[] pArray) throws EncoderException {
233240
* @throws DecoderException Thrown if URL decoding is unsuccessful
234241
*/
235242
public byte[] decode(byte[] pArray) throws DecoderException {
236-
return urldecode(pArray);
243+
return decodeUrl(pArray);
237244
}
238245

239246

240247
/**
241-
* Converts a string into its URL safe form using the specified
248+
* Encodes a string into its URL safe form using the specified
242249
* character set. Unsafe characters are escaped.
243250
*
244251
* @param pString string to convert to a URL safe form
@@ -253,12 +260,12 @@ public String encode(String pString, String charset)
253260
if (pString == null) {
254261
return null;
255262
}
256-
return new String(encode(pString.getBytes(charset)), "US-ASCII");
263+
return new String(encode(pString.getBytes(charset)), ENCODING);
257264
}
258265

259266

260267
/**
261-
* Converts a string into its URL safe form. Unsafe characters are
268+
* Encodes a string into its URL safe form. Unsafe characters are
262269
* escaped.
263270
*
264271
* @param pString string to convert to a URL safe form
@@ -270,15 +277,15 @@ public String encode(String pString) throws EncoderException {
270277
return null;
271278
}
272279
try {
273-
return new String(encode(pString.getBytes()), "US-ASCII");
280+
return new String(encode(pString.getBytes()), ENCODING);
274281
} catch(UnsupportedEncodingException e) {
275282
throw new EncoderException(e.getMessage());
276283
}
277284
}
278285

279286

280287
/**
281-
* Converts a URL safe string into its original form using the
288+
* Decodes a URL safe string into its original form using the
282289
* specified character set. Escaped characters are converted back
283290
* to their original representation.
284291
*
@@ -294,12 +301,12 @@ public String decode(String pString, String charset)
294301
if (pString == null) {
295302
return null;
296303
}
297-
return new String(decode(pString.getBytes("US-ASCII")), charset);
304+
return new String(decode(pString.getBytes(ENCODING)), charset);
298305
}
299306

300307

301308
/**
302-
* Converts a URL safe string into its original form. Escaped
309+
* Decodes a URL safe string into its original form. Escaped
303310
* characters are converted back to their original representation.
304311
*
305312
* @param pString URL safe string to convert into its original form
@@ -311,15 +318,15 @@ public String decode(String pString) throws DecoderException {
311318
return null;
312319
}
313320
try {
314-
return new String(decode(pString.getBytes("US-ASCII")));
321+
return new String(decode(pString.getBytes(ENCODING)));
315322
} catch(UnsupportedEncodingException e) {
316323
throw new DecoderException(e.getMessage());
317324
}
318325
}
319326

320327

321328
/**
322-
* Converts an object into its URL safe form. Unsafe characters are
329+
* Encodes an object into its URL safe form. Unsafe characters are
323330
* escaped.
324331
*
325332
* @param pObject string to convert to a URL safe form
@@ -343,7 +350,7 @@ public Object encode(Object pObject) throws EncoderException {
343350
}
344351

345352
/**
346-
* Converts a URL safe object into its original form. Escaped
353+
* Decodes a URL safe object into its original form. Escaped
347354
* characters are converted back to their original representation.
348355
*
349356
* @param pObject URL safe object to convert into its original form

0 commit comments

Comments
 (0)