This is serialization in a crude way. I would suggest the following:
- Create a class encapsulating the three elements.
- Make sure that class
implements
serializable
interface. - Use the following code [taken from this post] to create a byte array as you wished, and read the object back from byte array (which, although you have not specified as requirement, but it needs mention for the sake of completeness)
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { //Assuming that bos is the object to be seriaized out = new ObjectOutputStream(bos); out.writeObject(yourObject); byte[] yourBytes = bos.toByteArray(); ... } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { // ignore close exception } try { bos.close(); } catch (IOException ex) { // ignore close exception } } //Create object from bytes: ByteArrayInputStream bis = new ByteArrayInputStream(yourBytes); ObjectInput in = null; try { in = new ObjectInputStream(bis); Object o = in.readObject(); ... } finally { try { bis.close(); } catch (IOException ex) { // ignore close exception } try { if (in != null) { in.close(); } } catch (IOException ex) { // ignore close exception } }