Is there any function equivalent to Python\'s struct.pack in Java that allows me to pack and unpack values like this?
pump_on = struct.pack(\"II
Something like this:
final ByteArrayOutputStream data = new ByteArrayOutputStream();
final DataOutputStream stream = new DataOutputStream(data);
stream.writeUTF(name);
stream.writeUTF(password);
final byte[] bytes = stream.toByteArray(); // there you go
Later, you can read that data:
final DataInputStream stream = new DataInputStream(
new ByteArrayInputStream(bytes)
);
final String user = stream.readUTF();
final String password = stream.readUTF();