Skip to content

Commit

Permalink
handle UTF-8 correctly
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1324 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
(no author) committed Jan 12, 2006
1 parent 1d3249e commit 873cff2
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions source/de/anomic/http/httpTemplate.java
Expand Up @@ -52,6 +52,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Hashtable;

Expand Down Expand Up @@ -397,18 +398,26 @@ public static void writeTemplate(InputStream in, OutputStream out, Hashtable pat
}
}

public static byte[] replacePattern(String key, Hashtable pattern, byte dflt[]){
byte[] replacement;
public static byte[] replacePattern(String key, Hashtable pattern, byte dflt[]) {
byte[] replacement;
Object value;
if (pattern.containsKey(key)) {
value = pattern.get(key);
if (value instanceof byte[]) replacement = (byte[]) value;
else if (value instanceof String) replacement = ((String) value).getBytes();
else replacement = value.toString().getBytes();
if (pattern.containsKey(key)) {
value = pattern.get(key);
try {
if (value instanceof byte[]) {
replacement = (byte[]) value;
} else if (value instanceof String) {
replacement = ((String) value).getBytes("UTF-8");
} else {
replacement = value.toString().getBytes("UTF-8");
}
} catch (UnsupportedEncodingException e) {
replacement = dflt;
}
} else {
replacement = dflt;
replacement = dflt;
}
return replacement;
return replacement;
}

public static void main(String[] args) {
Expand Down

0 comments on commit 873cff2

Please sign in to comment.