Skip to content

Commit 4cec5db

Browse files
committed
Rename the instance variable from "ENCODING" to "encoding".
Add getEncoding() accessor and replace instance variable references with accessor method call. Remove throws EncoderException from methods that in fact NEVER throw such an Exception. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130215 13f79535-47bb-0310-9956-ffa450edef68
1 parent 124b73f commit 4cec5db

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
*
8787
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
8888
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
89-
* @version $Id: URLCodec.java,v 1.8 2003/10/12 02:17:11 tobrien Exp $
89+
* @version $Id: URLCodec.java,v 1.9 2003/10/13 16:49:24 ggregory Exp $
9090
*/
9191

9292
public class URLCodec
@@ -97,7 +97,7 @@ public class URLCodec
9797
/**
9898
* The <code>String</code> encoding used for decoding and encoding.
9999
*/
100-
protected String ENCODING = "US-ASCII";
100+
protected String encoding = "US-ASCII";
101101

102102
/**
103103
* BitSet of www-form-url safe characters.
@@ -139,7 +139,7 @@ public URLCodec() {
139139
*/
140140
public URLCodec(String encoding) {
141141
super();
142-
ENCODING = encoding;
142+
this.encoding = encoding;
143143
}
144144

145145
/**
@@ -149,10 +149,8 @@ public URLCodec(String encoding) {
149149
* @param urlsafe bitset of characters deemed URL safe
150150
* @param pArray array of bytes to convert to URL safe characters
151151
* @return array of bytes containing URL safe characters
152-
* @throws EncoderException Thrown if URL encoding is unsuccessful
153152
*/
154153
public static final byte[] encodeUrl(BitSet urlsafe, byte[] pArray)
155-
throws EncoderException
156154
{
157155
if (pArray == null) {
158156
return null;
@@ -228,9 +226,8 @@ public static final byte[] decodeUrl(byte[] pArray)
228226
*
229227
* @param pArray array of bytes to convert to URL safe characters
230228
* @return array of bytes containing URL safe characters
231-
* @throws EncoderException Thrown if URL encoding is unsuccessful
232229
*/
233-
public byte[] encode(byte[] pArray) throws EncoderException {
230+
public byte[] encode(byte[] pArray) {
234231
return encodeUrl(WWW_FORM_URL, pArray);
235232
}
236233

@@ -255,17 +252,16 @@ public byte[] decode(byte[] pArray) throws DecoderException {
255252
*
256253
* @param pString string to convert to a URL safe form
257254
* @return URL safe string
258-
* @throws EncoderException Thrown if URL encoding is unsuccessful
259255
* @throws UnsupportedEncodingException Thrown if charset is not
260256
* supported
261257
*/
262258
public String encode(String pString, String charset)
263-
throws EncoderException, UnsupportedEncodingException
259+
throws UnsupportedEncodingException
264260
{
265261
if (pString == null) {
266262
return null;
267263
}
268-
return new String(encode(pString.getBytes(charset)), ENCODING);
264+
return new String(encode(pString.getBytes(charset)), this.getEncoding());
269265
}
270266

271267

@@ -282,7 +278,7 @@ public String encode(String pString) throws EncoderException {
282278
return null;
283279
}
284280
try {
285-
return new String(encode(pString.getBytes()), ENCODING);
281+
return new String(encode(pString.getBytes()), this.getEncoding());
286282
} catch(UnsupportedEncodingException e) {
287283
throw new EncoderException(e.getMessage());
288284
}
@@ -306,7 +302,7 @@ public String decode(String pString, String charset)
306302
if (pString == null) {
307303
return null;
308304
}
309-
return new String(decode(pString.getBytes(ENCODING)), charset);
305+
return new String(decode(pString.getBytes(this.getEncoding())), charset);
310306
}
311307

312308

@@ -323,7 +319,7 @@ public String decode(String pString) throws DecoderException {
323319
return null;
324320
}
325321
try {
326-
return new String(decode(pString.getBytes(ENCODING)));
322+
return new String(decode(pString.getBytes(this.getEncoding())));
327323
} catch(UnsupportedEncodingException e) {
328324
throw new DecoderException(e.getMessage());
329325
}
@@ -377,4 +373,14 @@ public Object decode(Object pObject) throws DecoderException {
377373

378374
}
379375
}
376+
377+
/**
378+
* The <code>String</code> encoding used for decoding and encoding.
379+
*
380+
* @return Returns the encoding.
381+
*/
382+
public String getEncoding() {
383+
return this.encoding;
384+
}
385+
380386
}

0 commit comments

Comments
 (0)