Convert to and from UTF-8 without catching impossible exceptions.

All JVMs must support UTF-8 encoding.
This commit is contained in:
akwizgran
2014-02-07 22:02:02 +00:00
parent f6360c09d4
commit 4154119ea5
6 changed files with 15 additions and 19 deletions

View File

@@ -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.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
/** A group to which users may subscribe. */
public class Group {
@@ -13,13 +13,9 @@ public class Group {
private final byte[] salt;
public Group(GroupId id, String name, byte[] salt) {
if(name.length() == 0) throw new IllegalArgumentException();
try {
if(name.getBytes("UTF-8").length > MAX_GROUP_NAME_LENGTH)
throw new IllegalArgumentException();
} catch(UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
int length = name.getBytes(Charset.forName("UTF-8")).length;
if(length == 0 || length > MAX_GROUP_NAME_LENGTH)
throw new IllegalArgumentException();
if(salt.length != GROUP_SALT_LENGTH)
throw new IllegalArgumentException();
this.id = id;