Convert to byte array


import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MainClass {
  public static byte[] makeBytes(long t, double q) {
    try {
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
      DataOutputStream dataOut = new DataOutputStream(byteOut);
      dataOut.writeLong(t);
      dataOut.writeDouble(q);
      return byteOut.toByteArray();
    } catch (IOException e) {
      return new byte[0];
    }
  }
}
Home 
  Java Book 
    Runnable examples  

IO ByteArrayInputStream:
  1. Create ByteArrayInputStream from a String
  2. Create UTF8 InputStream
  3. Convert to byte array