Java Object Deserialize deserializeObject(File inFile)

Here you can find the source of deserializeObject(File inFile)

Description

deserialize Object

License

Open Source License

Declaration

public static <T> T deserializeObject(File inFile) throws ClassNotFoundException, IOException 

Method Source Code

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

import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;

import java.io.ObjectInputStream;

import java.io.OutputStream;

import java.io.Writer;

import java.util.Collection;

public class Main {
    public static <T> T deserializeObject(File inFile) throws ClassNotFoundException, IOException {

        return deserializeObject(new FileInputStream(inFile), true);
    }//ww w  . j a  v  a 2  s .c om

    @SuppressWarnings("unchecked")
    public static <T> T deserializeObject(InputStream inInputStream, boolean inCloseStream)
            throws IOException, ClassNotFoundException {

        ObjectInputStream theIs = null;

        try {

            theIs = new ObjectInputStream(inInputStream);
            return (T) theIs.readObject();

        } finally {

            if (inCloseStream) {

                close(theIs);
            }
        }

    }

    public static void close(Closeable inCloseable) {
        close(inCloseable, false);
    }

    public static void close(Closeable inCloseable, boolean inFlush) {

        if (inFlush) {
            flush(inCloseable);
        }

        try {

            inCloseable.close();

        } catch (final Exception e) {
        }

    }

    public static void close(Closeable... inCloseable) {

        if (inCloseable != null) {

            for (final Closeable closeable : inCloseable) {

                close(closeable);
            }
        }
    }

    public static void close(Collection<Closeable> inCloseables) {

        if (inCloseables != null) {

            for (final Closeable closeable : inCloseables) {

                close(closeable);
            }
        }
    }

    public static void flush(OutputStream inOutputStream) {

        try {

            inOutputStream.flush();

        } catch (final IOException e) {
            // swallow
        }
    }

    public static void flush(Writer inWriter) {

        try {

            inWriter.flush();

        } catch (final IOException e) {
            // swallow
        }
    }

    public static void flush(Object inOut) {

        if (inOut instanceof OutputStream) {

            flush((OutputStream) inOut);
        } else if (inOut instanceof Writer) {

            flush((Writer) inOut);
        }
    }
}

Related

  1. deserializeObject(byte[] data)
  2. deserializeObject(byte[] data, Class clazz)
  3. deserializeObject(byte[] obj)
  4. deserializeObject(byte[] serializedObj)
  5. deserializeObject(File file)
  6. deserializeObject(final byte[] b)
  7. deserializeObject(final byte[] bytes)
  8. deserializeToObject(byte[] bytes)