mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Convert to and from UTF-8 without catching impossible exceptions.
All JVMs must support UTF-8 encoding.
This commit is contained in:
@@ -31,6 +31,7 @@ import org.briarproject.api.serial.DigestingConsumer;
|
||||
import org.briarproject.api.serial.SigningConsumer;
|
||||
import org.briarproject.api.serial.Writer;
|
||||
import org.briarproject.api.serial.WriterFactory;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
class MessageFactoryImpl implements MessageFactory {
|
||||
|
||||
@@ -68,7 +69,7 @@ class MessageFactoryImpl implements MessageFactory {
|
||||
// Validate the arguments
|
||||
if((author == null) != (privateKey == null))
|
||||
throw new IllegalArgumentException();
|
||||
if(contentType.getBytes("UTF-8").length > MAX_CONTENT_TYPE_LENGTH)
|
||||
if(StringUtils.toUtf8(contentType).length > MAX_CONTENT_TYPE_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
if(body.length > MAX_BODY_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
@@ -21,6 +21,7 @@ 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;
|
||||
|
||||
@@ -234,7 +235,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, "UTF-8");
|
||||
return new String(buf, 0, length, Charset.forName("UTF-8"));
|
||||
}
|
||||
|
||||
private int readStringLength(boolean consume) throws IOException {
|
||||
|
||||
@@ -16,6 +16,7 @@ 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;
|
||||
@@ -102,7 +103,7 @@ class WriterImpl implements Writer {
|
||||
}
|
||||
|
||||
public void writeString(String s) throws IOException {
|
||||
byte[] b = s.getBytes("UTF-8");
|
||||
byte[] b = s.getBytes(Charset.forName("UTF-8"));
|
||||
if(b.length <= Byte.MAX_VALUE) {
|
||||
write(STRING_8);
|
||||
write((byte) b.length);
|
||||
|
||||
Reference in New Issue
Block a user