Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import java.io.ObjectOutputStream;

public class Main {
    public static byte[] toBytes(Object object) {
        if (object == null) {
            return null;
        }

        ByteArrayOutputStream __baos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream __oos = new ObjectOutputStream(__baos);
            __oos.writeObject(object);
        } catch (IOException ioe) {
            // Log the event here....
        }
        return __baos.toByteArray();
    }
}