Java Object Deserialize deserialize(byte[] objectData)

Here you can find the source of deserialize(byte[] objectData)

Description

Deserializes a single object from an array of bytes.

License

Open Source License

Parameter

Parameter Description
objectData The serialized object.

Return

The deserialized object, or null on failure.

Declaration

public static Object deserialize(byte[] objectData) 

Method Source Code


//package com.java2s;
/*//from   w  ww . ja va  2 s  .  c  om
 * Copyright (c) 2007-2016 AREasy Runtime
 *
 * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software");
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT,
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 */

import java.io.*;

public class Main {
    /**
     * Deserializes a single object from an array of bytes.
     *
     * @param objectData The serialized object.
     * @return The deserialized object, or <code>null</code> on failure.
     */
    public static Object deserialize(byte[] objectData) {
        Object object = null;
        if (objectData != null) {
            // These streams are closed in finally.
            ObjectInputStream in = null;
            ByteArrayInputStream bin = new ByteArrayInputStream(objectData);
            BufferedInputStream bufin = new BufferedInputStream(bin);
            try {
                in = new ObjectInputStream(bufin);

                // If objectData has not been initialized, an exception will occur.
                object = in.readObject();
            } catch (Exception e) {
            } finally {
                try {
                    if (in != null)
                        in.close();

                    if (bufin != null)
                        bufin.close();

                    if (bin != null)
                        bin.close();
                } catch (IOException e) {
                }
            }
        }
        return object;
    }
}

Related

  1. deserialize(byte[] data)
  2. deserialize(byte[] features)
  3. deserialize(byte[] in)
  4. deserialize(byte[] in)
  5. Deserialize(byte[] objectBytes)
  6. deserialize(byte[] objectData)
  7. deserialize(byte[] objectData)
  8. deserialize(byte[] objectData)
  9. deserialize(byte[] serial)