22 lines
600 B
Java
22 lines
600 B
Java
package org.warp.commonutils.serialization;
|
|
|
|
import java.io.DataInput;
|
|
import java.io.DataOutput;
|
|
import java.io.IOException;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
public class UTFUtils {
|
|
public static final void writeUTF(DataOutput out, String utf) throws IOException {
|
|
byte[] bytes = utf.getBytes(StandardCharsets.UTF_8);
|
|
out.writeInt(bytes.length);
|
|
out.write(bytes);
|
|
}
|
|
|
|
public static final String readUTF(DataInput in) throws IOException {
|
|
int len = in.readInt();
|
|
byte[] data = new byte[len];
|
|
in.readFully(data, 0, len);
|
|
return new String(data, StandardCharsets.UTF_8);
|
|
}
|
|
}
|