Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String objectSerializableToString(Serializable object) {
        ByteArrayOutputStream baos = null;
        ObjectOutputStream os = null;
        try {
            if (object != null) {
                baos = new ByteArrayOutputStream();
                os = new ObjectOutputStream(baos);
                os.writeObject(object);
                os.flush();
                baos.flush();
                return baos.toString("UTF-8");
            }
        } catch (Throwable e) {
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
            } catch (Throwable e2) {
            }

            try {
                if (baos != null) {
                    baos.close();
                }
            } catch (Throwable e2) {
            }
        }
        return null;
    }
}