Example usage for java.io ObjectInputStream close

List of usage examples for java.io ObjectInputStream close

Introduction

In this page you can find the example usage for java.io ObjectInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the input stream.

Usage

From source file:com.plexobject.testplayer.dao.jdbc.GenericDaoJdbc.java

protected static Object toObject(Blob blob) {
    try {/* www .ja v a  2s  .  c om*/
        if (blob == null)
            return null;
        InputStream in = blob.getBinaryStream();
        if (in == null)
            return null;
        int c;
        ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
        while ((c = in.read()) != -1) {
            out.write(c);
        }
        byte[] b = out.toByteArray();
        if (b.length == 0)
            return null;
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(b));
        Object object = ois.readObject();
        ois.close();
        return object;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new DaoException("Failed to deserialize", e);
    }
}

From source file:Main.java

public static Object readObject(Context context, String filename) {
    FileInputStream in = null;/*  w  ww .  java2  s.  c  o m*/
    ObjectInputStream oin = null;
    Object data = null;
    try {
        in = context.openFileInput(filename + ".odb");
        oin = new ObjectInputStream(in);
        data = oin.readObject();
        oin.close();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return data;
}

From source file:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java

public static <T> T deserialize(byte[] serialized, Class<T> clazz) throws JobPersistenceException {
    // ToDO(keith): Serialize better than Java serialization.
    ByteArrayInputStream byteStream = new ByteArrayInputStream(serialized);
    try {// w  ww .  j  av  a 2 s.  c  om
        ObjectInputStream objectStream = new ObjectInputStream(byteStream);
        Object deserialized = objectStream.readObject();
        objectStream.close();
        if (clazz.isInstance(deserialized)) {
            @SuppressWarnings("unchecked")
            T obj = (T) deserialized;
            return obj;
        }

        throw new JobPersistenceException("Deserialized object is not of the desired type");
    } catch (IOException | ClassNotFoundException e) {
        throw new JobPersistenceException("Could not deserialize.", e);
    }
}

From source file:jedi.util.serialization.Pickle.java

/**
 * Receives a sequence of bytes and returns a object.
 * /*w w w.ja v  a 2 s .c o m*/
 * @param s Sequence of bytes.
 * @return Object
 */
public static Object loads(String s) {
    Object o = null;
    ByteArrayInputStream bais;

    try {
        bais = new ByteArrayInputStream(Base64.decodeBase64(s.getBytes()));
        ObjectInputStream ois = new ObjectInputStream(bais);

        o = ois.readObject();

        ois.close();
        bais.close();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return o;
}

From source file:jedi.util.serialization.Pickle.java

/**
 * Deserializes objects.//from  www.  j av  a2s .c o m
 * 
 * @param f File that holds the serialized objects.
 * @return Object
 */
public static Object load(File f) {
    Object o = null;

    if (f != null) {
        try {
            FileInputStream fis = new FileInputStream(f);

            // The file reader.
            ObjectInputStream ois = new ObjectInputStream(fis);
            o = ois.readObject();
            ois.close();

            fis.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    return o;
}

From source file:com.cj.restspecs.mojo.Util.java

@SuppressWarnings("unchecked")
public static <T> T readObject(File path) {
    try {//w w w.j av  a2 s  .co  m
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(path));
        try {
            return (T) in.readObject();
        } finally {
            in.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.cloudera.kitten.util.LocalDataHelper.java

public static <T> Map<String, T> deserialize(String serialized) {
    byte[] data = Base64.decodeBase64(serialized);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    Map<String, T> mapping = null;
    try {/*from   ww w. j av  a 2s .  com*/
        ObjectInputStream ois = new ObjectInputStream(bais);
        mapping = (Map<String, T>) ois.readObject();
        ois.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return mapping;
}

From source file:org.pgptool.gui.config.impl.ConfigRepositoryImpl.java

public static void safeClose(ObjectInputStream fis) {
    if (fis != null) {
        try {/*from w  ww  .j  a v a2  s . com*/
            fis.close();
        } catch (Throwable t) {
            // don't care
        }
    }
}

From source file:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java

private static Map<String, ?> stringMapFromBytes(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bais);
    @SuppressWarnings("unchecked")
    Map<String, ?> map = (Map<String, ?>) ois.readObject();
    ois.close();
    return map;//  w w  w  .  j  a va  2  s. co  m
}

From source file:io.lqd.sdk.model.LQLiquidPackage.java

public static LQLiquidPackage loadFromDisk(Context context) {
    LQLog.data("Loading from local storage");
    try {/*w w w  . j a v a  2 s.co  m*/
        FileInputStream fileInputStream = context.openFileInput(LIQUID_PACKAGE_FILENAME + ".vars");
        ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        Object result = objectInputStream.readObject();
        objectInputStream.close();
        return (LQLiquidPackage) result;
    } catch (IOException e) {
        LQLog.infoVerbose("Could not load liquid package from file");
    } catch (ClassNotFoundException e) {
        LQLog.infoVerbose("Could not load liquid package from file");
    }
    return new LQLiquidPackage();
}