Java Serializable Serialize serializeObject(Serializable o)

Here you can find the source of serializeObject(Serializable o)

Description

Write the object to a Base64 string.

License

Open Source License

Declaration

public static String serializeObject(Serializable o) throws IOException 

Method Source Code

//package com.java2s;

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

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

import java.util.Base64;

public class Main {
    /** Write the object to a Base64 string. */
    public static String serializeObject(Serializable o) throws IOException {
        if (o == null)
            return null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(o);//from  w  w  w  .ja  v a 2 s  .  com
        oos.close();
        return Base64.getEncoder().encodeToString(baos.toByteArray());
    }
}

Related

  1. serializeObject(File inFile, Serializable inObject)
  2. serializeObject(Serializable cds)
  3. serializeObject(Serializable obj, String filename)
  4. serializeObject(Serializable ser)
  5. serializeObject(Serializable serializable)
  6. serializeObjectToFile(File targetFile, Serializable serializable)