int size = is.readShort();
Buffer buffer = is.readBuffer(size);
if (buffer == null || buffer.length != size) {
throw new ProtocolException("Invalid message encoding");
}
return buffer.utf8();
}
static protected void writeUTF(DataByteArrayOutputStream os, Buffer buffer) throws IOException {
os.writeShort(buffer.length);
os.write(buffer);