diff --git a/briar-api/src/org/briarproject/api/Author.java b/briar-api/src/org/briarproject/api/Author.java index 5c77dad6082d967409ee60a6b054f5440b8186ee..2f1cae443aa2c3fb38b64513d31095d05194d8a7 100644 --- a/briar-api/src/org/briarproject/api/Author.java +++ b/briar-api/src/org/briarproject/api/Author.java @@ -2,7 +2,7 @@ package org.briarproject.api; import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; -import java.nio.charset.Charset; +import java.io.UnsupportedEncodingException; /** A pseudonym for a user. */ public class Author { @@ -14,7 +14,12 @@ public class Author { private final byte[] publicKey; public Author(AuthorId id, String name, byte[] publicKey) { - int length = name.getBytes(Charset.forName("UTF-8")).length; + int length; + try { + length = name.getBytes("UTF-8").length; + } catch(UnsupportedEncodingException e) { + throw new RuntimeException(e); + } if(length == 0 || length > MAX_AUTHOR_NAME_LENGTH) throw new IllegalArgumentException(); this.id = id; diff --git a/briar-api/src/org/briarproject/api/messaging/Group.java b/briar-api/src/org/briarproject/api/messaging/Group.java index 20488c021dac3bc782e5a50cc4ebeaf9e15d4c29..2a6a083b1456cce10c51796cf74ceeec39a2c0e8 100644 --- a/briar-api/src/org/briarproject/api/messaging/Group.java +++ b/briar-api/src/org/briarproject/api/messaging/Group.java @@ -3,7 +3,7 @@ package org.briarproject.api.messaging; import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH; import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH; -import java.nio.charset.Charset; +import java.io.UnsupportedEncodingException; /** A group to which users may subscribe. */ public class Group { @@ -13,7 +13,12 @@ public class Group { private final byte[] salt; public Group(GroupId id, String name, byte[] salt) { - int length = name.getBytes(Charset.forName("UTF-8")).length; + int length; + try { + length = name.getBytes("UTF-8").length; + } catch(UnsupportedEncodingException e) { + throw new RuntimeException(e); + } if(length == 0 || length > MAX_GROUP_NAME_LENGTH) throw new IllegalArgumentException(); if(salt.length != GROUP_SALT_LENGTH) diff --git a/briar-core/src/org/briarproject/serial/ReaderImpl.java b/briar-core/src/org/briarproject/serial/ReaderImpl.java index 4398485dc98ad04f3dd865752fbdbee0563e1b12..b8710776f6c712bf77a0211156670d620e9f8fae 100644 --- a/briar-core/src/org/briarproject/serial/ReaderImpl.java +++ b/briar-core/src/org/briarproject/serial/ReaderImpl.java @@ -21,7 +21,6 @@ import static org.briarproject.serial.Tag.TRUE; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; @@ -235,7 +234,7 @@ class ReaderImpl implements Reader { if(length < 0 || length > maxLength) throw new FormatException(); if(length == 0) return ""; readIntoBuffer(length, true); - return new String(buf, 0, length, Charset.forName("UTF-8")); + return new String(buf, 0, length, "UTF-8"); } private int readStringLength(boolean consume) throws IOException { diff --git a/briar-core/src/org/briarproject/serial/WriterImpl.java b/briar-core/src/org/briarproject/serial/WriterImpl.java index 5555573a8d22d324a6ce96aff07afe6ade02b29e..45995cdb0ef07697806671c69434b6debc5d084b 100644 --- a/briar-core/src/org/briarproject/serial/WriterImpl.java +++ b/briar-core/src/org/briarproject/serial/WriterImpl.java @@ -16,7 +16,6 @@ import static org.briarproject.serial.Tag.TRUE; import java.io.IOException; import java.io.OutputStream; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -103,7 +102,7 @@ class WriterImpl implements Writer { } public void writeString(String s) throws IOException { - byte[] b = s.getBytes(Charset.forName("UTF-8")); + byte[] b = s.getBytes("UTF-8"); if(b.length <= Byte.MAX_VALUE) { write(STRING_8); write((byte) b.length); diff --git a/briar-core/src/org/briarproject/util/StringUtils.java b/briar-core/src/org/briarproject/util/StringUtils.java index 5159b2c3cb4cee4760845430c652c4dcc47aa805..2da9fa7f895e7e47356b9564f5bde030cd6ddd35 100644 --- a/briar-core/src/org/briarproject/util/StringUtils.java +++ b/briar-core/src/org/briarproject/util/StringUtils.java @@ -1,6 +1,6 @@ package org.briarproject.util; -import java.nio.charset.Charset; +import java.io.UnsupportedEncodingException; public class StringUtils { @@ -14,11 +14,19 @@ public class StringUtils { } public static byte[] toUtf8(String s) { - return s.getBytes(Charset.forName("UTF-8")); + try { + return s.getBytes("UTF-8"); + } catch(UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } public static String fromUtf8(byte[] bytes) { - return new String(bytes, Charset.forName("UTF-8")); + try { + return new String(bytes, "UTF-8"); + } catch(UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } /** Converts the given byte array to a hex character array. */