Java Byte Array to Object deserialize(byte[] buffer, int count)

Here you can find the source of deserialize(byte[] buffer, int count)

Description

This method takes the given buffer and extracts count number of objects from it.

License

Open Source License

Declaration

public static final Object[] deserialize(byte[] buffer, int count) 

Method Source Code


//package com.java2s;
/*// w  ww  . j a v  a2 s .  c om
 *   Copyright 2010 The Portico Project
 *
 *   This file is part of portico.
 *
 *   portico is free software; you can redistribute it and/or modify
 *   it under the terms of the Common Developer and Distribution License (CDDL) 
 *   as published by Sun Microsystems. For more information see the LICENSE file.
 *   
 *   Use of this software is strictly AT YOUR OWN RISK!!!
 *   If something bad happens you do not have permission to come crying to me.
 *   (that goes for your lawyer as well)
 *
 */

import java.io.ByteArrayInputStream;

import java.io.ObjectInputStream;

public class Main {
    /**
     * This method takes the given buffer and extracts <code>count</code> number of objects
     * from it. These objects are returned in an array.
     */
    public static final Object[] deserialize(byte[] buffer, int count) {
        try {
            Object[] objects = new Object[count];
            ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
            ObjectInputStream ois = new ObjectInputStream(bais);

            for (int i = 0; i < count; i++)
                objects[i] = ois.readObject();

            ois.close();
            return objects;
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. deserialize(byte[] array)
  2. deserialize(byte[] b)
  3. deserialize(byte[] blob)
  4. deserialize(byte[] buf)
  5. deserialize(byte[] buf)
  6. deserialize(byte[] byteArray)
  7. deserialize(byte[] byteArray)
  8. deserialize(byte[] bytes)
  9. deserialize(byte[] bytes)