Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Created June 7, 2014 10:32
Show Gist options
  • Save dsaiztc/3137780cdd49a97591b2 to your computer and use it in GitHub Desktop.
Save dsaiztc/3137780cdd49a97591b2 to your computer and use it in GitHub Desktop.
Converts byte[] to object.
/**
* Converts an object in byte[] to Object
*
* @param object Object in byte[]
* @return The original Object
*/
public static Object byteToObject(byte[] object)
{
Object result = null;
ByteArrayInputStream bis = new ByteArrayInputStream(object);
ObjectInput in = null;
try
{
in = new ObjectInputStream(bis);
result = in.readObject();
}
catch (Exception ioe)
{
Log.e(TAG, ioe.toString());
}
finally
{
try
{
bis.close();
}
catch (IOException ex)
{
Log.e(TAG, ex.toString());
}
try
{
if (in != null)
{
in.close();
}
}
catch (IOException ex)
{
Log.e(TAG, ex.toString());
}
}
return object;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment