Here you can find the source of deserialize(@Nonnull byte[] byteArray)
Parameter | Description |
---|---|
byteArray | The byte array serialized from an object. |
Parameter | Description |
---|---|
ClassNotFoundException | On failure finding target class. |
public @Nonnull static <T> T deserialize(@Nonnull byte[] byteArray) throws IOException, ClassNotFoundException
//package com.java2s; /*/*from w w w. j a va2 s.c om*/ * This file is part of LaS-VPE Platform. * * LaS-VPE Platform is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LaS-VPE Platform is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LaS-VPE Platform. If not, see <http://www.gnu.org/licenses/>. */ import javax.annotation.Nonnull; import java.io.*; public class Main { /** * Deserialize a byte array of an object. * * @param byteArray The byte array serialized from an object. * @return An object from which the byte array is serialized. * @throws ClassNotFoundException On failure finding target class. */ public @Nonnull static <T> T deserialize(@Nonnull byte[] byteArray) throws IOException, ClassNotFoundException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); ObjectInput objectInput = null; try { objectInput = new ObjectInputStream(byteArrayInputStream); //noinspection unchecked return (T) objectInput.readObject(); } finally { try { if (objectInput != null) { objectInput.close(); } } catch (IOException e) { // ignore close exception } try { byteArrayInputStream.close(); } catch (IOException e) { // ignore close exception } } } }