Java ByteBuffer Serialize deserialize(ByteBuffer b)

Here you can find the source of deserialize(ByteBuffer b)

Description

Deserialize an object from a ByteBuffer.

License

Apache License

Parameter

Parameter Description
b Buffer

Return

Deserialized object

Declaration

public static Object deserialize(ByteBuffer b) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

import java.nio.ByteBuffer;

public class Main {
    /**//from  w  w  w  .  j  a  va 2  s.c o  m
     * Deserialize an object from a ByteBuffer.
     * @param b Buffer
     * @return Deserialized object
     */
    public static Object deserialize(ByteBuffer b) {
        try {
            //todo: make serialization less clunky!
            ByteArrayInputStream bais = new ByteArrayInputStream(b.array());
            ObjectInputStream ois = new ObjectInputStream(bais);
            return ois.readObject();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException ce) {
            throw new RuntimeException(ce);
        }
    }
}

Related

  1. deserialize(ByteBuffer byteBuffer)
  2. deserializeBoolean(ByteBuffer buf)
  3. deserializeFromByteBufferNoHeader(ByteBuffer bytes)
  4. deserializeObject(ByteBuffer obj)