Android ByteBuffer Get getObject(ByteBuffer byteBuffer)

Here you can find the source of getObject(ByteBuffer byteBuffer)

Description

get Object

License

Open Source License

Declaration

public static Object getObject(ByteBuffer byteBuffer)
            throws ClassNotFoundException, IOException 

Method Source Code

//package com.java2s;
import java.io.ByteArrayInputStream;

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

import java.nio.ByteBuffer;

public class Main {
    public static Object getObject(byte[] bytes) throws IOException,
            ClassNotFoundException {
        ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
        ObjectInputStream oi = new ObjectInputStream(bi);
        Object obj = oi.readObject();
        bi.close();//ww  w.jav  a2 s  . c o  m
        oi.close();
        return obj;
    }

    public static Object getObject(ByteBuffer byteBuffer)
            throws ClassNotFoundException, IOException {
        InputStream input = new ByteArrayInputStream(byteBuffer.array());
        ObjectInputStream oi = new ObjectInputStream(input);
        Object obj = oi.readObject();
        input.close();
        oi.close();
        byteBuffer.clear();
        return obj;
    }
}

Related

  1. getUnsignedInt(final ByteBuffer pByteBuffer, final int pPosition)
  2. extractNullTerminatedString(ByteBuffer bb)
  3. allocateMore(ByteBuffer output)
  4. removeFirstBytes(ByteBuffer buffer, int num)
  5. shorts(ByteBuffer buffer)
  6. skip(ByteBuffer buffer, int length)