Java Object Deserialize deserialize(byte[] bytes, Class clazz)

Here you can find the source of deserialize(byte[] bytes, Class clazz)

Description

deserialize

License

Open Source License

Declaration

public static <T> T deserialize(byte[] bytes, Class<T> clazz) 

Method Source Code


//package com.java2s;
/*/*from   w  ww. j  a  v  a  2  s  . c o  m*/
 * Copyright 1999-2101 Alibaba.com. All rights reserved.
 * This software is the confidential and proprietary information of Alibaba.com ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only in accordance with the terms of
 * the license agreement you entered into with Alibaba.com.
 */

import java.io.*;

public class Main {
    public static <T> T deserialize(byte[] bytes, Class<T> clazz) {
        ByteArrayInputStream bais = null;
        ObjectInputStream ois = null;
        try {
            bais = new ByteArrayInputStream(bytes);
            ois = new ObjectInputStream(bais);
            Object object = ois.readObject();
            return clazz.cast(object);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            closeQuietly(bais);
            closeQuietly(ois);
        }
    }

    private static void closeQuietly(Closeable c) {
        if (c == null)
            return;
        try {
            c.close();
        } catch (IOException e) {
        }
    }
}

Related

  1. deserialize(@Nonnull byte[] byteArray)
  2. deserialize(@Nullable final byte[] binaryInput)
  3. deserialize(byte[] bytes, boolean zipped)
  4. deserialize(byte[] bytes, Class clazz)
  5. deserialize(byte[] bytes, Class klass)
  6. deserialize(byte[] bytes, final Class asClass)
  7. deserialize(byte[] bytes, List customClassLoaders)
  8. deserialize(byte[] data)