package Common;
import java.io.*;
public interface ByteObject
{
byte[] toBytes();
void fromBytes(byte[] bytes);
static T readEnum(InputStream in, Class c) throws IOException {
return (T)Enum.valueOf(c, readString(in));
}
static String readString(InputStream in) throws IOException {
return readString(new DataInputStream(in));
}
static String readString(DataInputStream dis) throws IOException {
byte[] bytes = new byte[dis.readInt()];
dis.read(bytes);
return new String(bytes, Utils.getDefaultCharset());
}
static void writeString(OutputStream out, String s) throws IOException {
writeString(new DataOutputStream(out), s);
}
static void writeString(DataOutputStream dos, String s) throws IOException {
byte[] bytes = s.getBytes(Utils.getDefaultCharset());
dos.writeInt(bytes.length);
dos.write(bytes);
}
}