Here you can find the source of deserializeObject(final byte[] b)
Parameter | Description |
---|---|
b | the byte array representation of object to serialize |
T | the Object type |
@SuppressWarnings("unchecked") public static <T extends Serializable> T deserializeObject(final byte[] b)
//package com.java2s; /******************************************************************************* * Copyright (C) 2009, 2015, Danilo Pianini and contributors * listed in the project's build.gradle or pom.xml file. * * This file is distributed under the terms of the Apache License, version 2.0 *******************************************************************************/ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; public class Main { /**//from w w w. j a v a 2 s . c o m * Serializes an object in memory. Its representation as byte[] is returned * * @param b * the byte array representation of object to serialize * @return The Object * @param <T> * the Object type */ @SuppressWarnings("unchecked") public static <T extends Serializable> T deserializeObject(final byte[] b) { try { final ByteArrayInputStream bin = new ByteArrayInputStream(b); final ObjectInputStream cin = new ObjectInputStream(bin); return (T) cin.readObject(); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); // NOPMD by danysk on 8/20/13 1:48 PM } return null; } }