Java Object to Byte Array getBytes(Object o)

Here you can find the source of getBytes(Object o)

Description

get Bytes

License

Apache License

Declaration

static public final byte[] getBytes(Object o) throws IOException 

Method Source Code


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

import java.io.BufferedOutputStream;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    static public final byte[] getBytes(Object o) throws IOException {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(5000);
        ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(byteStream));
        os.flush();//from  w  w w  .j a v  a 2 s  . c  o  m
        os.writeObject(o);
        os.flush();
        return byteStream.toByteArray();
    }
}

Related

  1. getBytes(Object o)
  2. getBytes(Object o)
  3. getBytes(Object obj)
  4. getBytes(Object obj)
  5. getBytes(Object obj)