Java Object Deserialize deserializeObject(final byte[] b)

Here you can find the source of deserializeObject(final byte[] b)

Description

Serializes an object in memory.

License

Apache License

Parameter

Parameter Description
b the byte array representation of object to serialize
T the Object type

Return

The Object

Declaration

@SuppressWarnings("unchecked")
public static <T extends Serializable> T deserializeObject(final byte[] b) 

Method Source Code

//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;
    }
}

Related

  1. deserializeObject(byte[] data, Class clazz)
  2. deserializeObject(byte[] obj)
  3. deserializeObject(byte[] serializedObj)
  4. deserializeObject(File file)
  5. deserializeObject(File inFile)
  6. deserializeObject(final byte[] bytes)
  7. deserializeToObject(byte[] bytes)