Java Object Deserialize from File deserialize(File file, Class clazz)

Here you can find the source of deserialize(File file, Class clazz)

Description

deserialize

License

Open Source License

Declaration

private static <T> T deserialize(File file, Class<T> clazz) throws IOException, ClassNotFoundException 

Method Source Code


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

import java.io.BufferedInputStream;

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

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

import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;

public class Main {
    private static <T> T deserialize(File file, Class<T> clazz) throws IOException, ClassNotFoundException {
        InputStream raw = new BufferedInputStream(new FileInputStream(file));
        int compress = raw.read();
        if (compress == 1) {
            raw = new InflaterInputStream(raw, new Inflater(true));
        }//  w  w  w  . j ava  2  s. c  o m

        T result;
        ObjectInputStream in = new ObjectInputStream(raw);
        try {
            result = clazz.cast(in.readObject());
        } finally {
            in.close();
        }
        return result;
    }
}

Related

  1. deserialize(File file)
  2. deserialize(File file)
  3. deserialize(File file)
  4. deserialize(File file)
  5. deserialize(File file)
  6. deserialize(final File file)
  7. deserialize(final String path)
  8. deserialize(String filename)
  9. deserialize(String fileName)