You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/08/16 18:06:26 UTC
cvs commit: jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient URLUtil.java
juergen 2002/08/16 09:06:26
Modified: src/webdav/client/src/org/apache/commons/httpclient
URLUtil.java
Log:
use getBytes to translate a character to a byteArray instead of a Stream.
Revision Changes Path
1.5 +14 -32 jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/URLUtil.java
Index: URLUtil.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/commons/httpclient/URLUtil.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- URLUtil.java 25 Apr 2002 21:15:13 -0000 1.4
+++ URLUtil.java 16 Aug 2002 16:06:26 -0000 1.5
@@ -65,13 +65,7 @@
package org.apache.commons.httpclient;
import java.io.UnsupportedEncodingException;
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStreamWriter;
-import java.io.IOException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Map;
import java.util.TimeZone;
import java.util.BitSet;
@@ -104,8 +98,8 @@
protected static BitSet safeCharacters;
- protected static final char[] hexadecimal =
- {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ protected static final char[] hexadecimal =
+ {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
@@ -253,7 +247,7 @@
/**
* URL rewriter.
- *
+ *
* @param path Path which has to be rewiten
*/
public static String URLEncode(String path, String enc) {
@@ -265,18 +259,7 @@
* and '/' shouldn't be encoded.
*/
- int maxBytesPerChar = 10;
- int caseDiff = ('a' - 'A');
StringBuffer rewrittenPath = new StringBuffer(path.length());
- ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
- OutputStreamWriter writer = null;
- try {
- // FIXME: Use the same encoding as the one specified above
- writer = new OutputStreamWriter(buf, enc);
- } catch (Exception e) {
- e.printStackTrace();
- writer = new OutputStreamWriter(buf);
- }
for (int i = 0; i < path.length(); i++) {
int c = (int) path.charAt(i);
@@ -284,14 +267,14 @@
rewrittenPath.append((char)c);
} else {
// convert to external encoding before hex conversion
- try {
- writer.write(c);
- writer.flush();
- } catch(IOException e) {
- buf.reset();
- continue;
+ byte[] ba;
+ try
+ {
+ ba = new Character((char)c).toString().getBytes(enc);
+ }
+ catch (UnsupportedEncodingException e) {
+ ba = new Character((char)c).toString().getBytes();
}
- byte[] ba = buf.toByteArray();
for (int j = 0; j < ba.length; j++) {
// Converting each byte in the buffer
byte toEncode = ba[j];
@@ -301,7 +284,6 @@
rewrittenPath.append(hexadecimal[high]);
rewrittenPath.append(hexadecimal[low]);
}
- buf.reset();
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>