Java Byte Array from getBytesFromObject(Serializable data)

Here you can find the source of getBytesFromObject(Serializable data)

Description

get Bytes From Object

License

Apache License

Declaration

public static byte[] getBytesFromObject(Serializable data) throws IOException 

Method Source Code

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

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
    public static byte[] getBytesFromObject(Serializable data) throws IOException {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ObjectOutputStream objos = new ObjectOutputStream(os);
        objos.writeObject(data);//from  w  ww  .  j a  va  2 s. c o m
        objos.flush();
        byte[] result = os.toByteArray();
        os.close();
        objos.close();
        return result;
    }
}

Related

  1. getBytesFromArrayList(final ArrayList fileList)
  2. getBytesFromHexaText(String text)
  3. getBytesFromImage(File file)
  4. getBytesFromInt(int value)
  5. getBytesFromList(List values)
  6. getBytesFromObject(Serializable obj)
  7. getBytesFromResource(String resource)
  8. getBytesFromStream(int length, ByteArrayInputStream bais)
  9. getBytesFromString(final String str, final int length, final String coding)

  10. HOME | Copyright © www.java2s.com 2016