Java Encode encode(Serializable s)

Here you can find the source of encode(Serializable s)

Description

encode

License

Apache License

Declaration

public static String encode(Serializable s) 

Method Source Code

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

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

import java.io.ObjectOutputStream;

import java.io.Serializable;

import java.util.Base64;

public class Main {
    public static String encode(Serializable s) {
        try (ByteArrayOutputStream of = new ByteArrayOutputStream();
                ObjectOutputStream so = new ObjectOutputStream(of)) {
            so.writeObject(s);/*from   ww w.jav a2s. c  o m*/
            so.flush();
            return Base64.getEncoder().encodeToString(of.toByteArray());
        } catch (IOException e) {
            throw new UnsupportedOperationException(e);
        }
    }
}

Related

  1. encode(Object o)
  2. encode(Object o)
  3. encode(Object obj)
  4. encode(T obj)
  5. encode2Encode(String original, String encode1, String encode2)
  6. encode_u8(String what)
  7. encodeAddresses(String string, String charset)