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

@@ -2,7 +2,7 @@ package org.briarproject.api;
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
/** A pseudonym for a user. */
public class Author {
@@ -14,13 +14,9 @@ public class Author {
private final byte[] publicKey;
public Author(AuthorId id, String name, byte[] publicKey) {
if(name.length() == 0) throw new IllegalArgumentException();
try {
if(name.getBytes("UTF-8").length > MAX_AUTHOR_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_AUTHOR_NAME_LENGTH)
throw new IllegalArgumentException();
this.id = id;
this.name = name;
this.publicKey = publicKey;