Java InputStream Create getInputStream(final Serializable obj)

Here you can find the source of getInputStream(final Serializable obj)

Description

get Input Stream

License

Open Source License

Declaration

public static ByteArrayInputStream getInputStream(final Serializable obj) throws Exception 

Method Source Code


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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

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

public class Main {

    public static ByteArrayInputStream getInputStream(final Serializable obj) throws Exception {
        byte[] bin = getBytes(obj);
        return new ByteArrayInputStream(bin);
    }/*from  w ww  . j  av  a  2  s.co m*/

    public static byte[] getBytes(final Serializable obj) throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            try {
                oos.writeObject(obj);
            } finally {
                oos.close();
            }
        } finally {
            bos.close();
        }
        return bos.toByteArray();
    }
}

Related

  1. getInputStream(File TheFile)
  2. getInputStream(FileInputStream fileInput)
  3. getInputStream(final File file)
  4. getInputStream(final File file)
  5. getInputStream(final File file, final boolean createFile)
  6. getInputStream(final String fileName)
  7. getInputStream(final String sourceFolder, final Class clazz)
  8. getInputStream(String content)
  9. getInputStream(String data)