Java Serialize serializeToBase64(Serializable object)

Here you can find the source of serializeToBase64(Serializable object)

Description

serialize To Base

License

Apache License

Declaration

static String serializeToBase64(Serializable object) throws IOException 

Method Source Code

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

import com.amazonaws.util.Base64;

import java.io.*;

public class Main {
    static String serializeToBase64(Serializable object) throws IOException {
        if (object == null) {
            return "";
        }//  w  ww.j  a  v a2s  . co  m

        ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
        ObjectOutputStream objectStream = null;
        try {
            objectStream = new ObjectOutputStream(byteArrayStream);
            objectStream.writeObject(object);
            return new String(Base64.encode(byteArrayStream.toByteArray()));
        } finally {
            if (objectStream != null)
                objectStream.close();
        }
    }
}

Related

  1. serializeObjectToFile(Object object, String filename)
  2. serializer(Object object)
  3. serializeSafe(T obj)
  4. serializeShort(short value, byte[] outbuf, int offset)
  5. serializeString(File file, String string)
  6. serializeToFile(Object obj, String fileName)
  7. serializeToFile(Object object, File file)
  8. serializeToFile(Serializable s, String path)
  9. serializeToString(Object o)