Java Encode encode(T obj)

Here you can find the source of encode(T obj)

Description

encode

License

Apache License

Declaration

public static final <T extends Serializable> byte[] encode(T obj) 

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;

public class Main {
    public static final <T extends Serializable> byte[] encode(T obj) {
        byte[] bytes = null;
        try {//from   w  w  w.j  a  v  a 2s . co  m
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(bout);
            out.writeObject(obj);
            bytes = bout.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("Error serializing object" + obj + " => " + e);
        }
        return bytes;
    }
}

Related

  1. encode(Object o)
  2. encode(Object o)
  3. encode(Object obj)
  4. encode(Serializable s)
  5. encode2Encode(String original, String encode1, String encode2)
  6. encode_u8(String what)
  7. encodeAddresses(String string, String charset)
  8. encodeArguments(final String arg)