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:Main.java

private static Map<UUID, String> readPageNameHashesFromFile(File folder) {
    Map<UUID, String> map = new HashMap<UUID, String>();

    try {/*  ww  w .  ja  v  a  2s  . c om*/
        FileInputStream fis = new FileInputStream(folder.getAbsolutePath() + fileName);
        ObjectInputStream ois = new ObjectInputStream(fis);
        map = (Map<UUID, String>) ois.readObject();
        ois.close();
        printMap();
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("Read from file", e.toString());
    }

    return map;
}

From source file:id.co.nlp.MachineTranslation.Utils.Util.java

public static Object deserializing(String pathfile)
        throws FileNotFoundException, IOException, ClassNotFoundException {
    FileInputStream fileIn = new FileInputStream(pathfile);
    ObjectInputStream in = new ObjectInputStream(fileIn);
    Object object = in.readObject();
    in.close();
    fileIn.close();/*from  w w  w . j  ava  2 s  . co  m*/
    return object;
}

From source file:com.yfiton.oauth.OAuthUtils.java

public static AuthorizationData readAuthorizationInfo(Path file)
        throws ConfigurationException, IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file));
    AuthorizationData data = (AuthorizationData) ois.readObject();
    ois.close();

    Files.delete(file);//from   w w  w  .j  ava 2s .co  m

    return data;
}

From source file:com.evolveum.midpoint.util.SerializationUtil.java

public static <T> T fromString(String string) throws IOException, ClassNotFoundException {
    byte[] data = Base64.decodeBase64(string);
    ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(data));
    Object object = objectInputStream.readObject();
    objectInputStream.close();
    return (T) object;
}

From source file:Main.java

/**
 * deserialization from file//from  w  w w .  ja  va2s. c o m
 * 
 * @param filePath
 * @return
 * @throws RuntimeException if an error occurs
 */
public static Object deserialization(String filePath) {
    ObjectInputStream in = null;
    try {
        in = new ObjectInputStream(new FileInputStream(filePath));
        Object o = in.readObject();
        in.close();
        return o;
    } catch (FileNotFoundException e) {
        throw new RuntimeException("FileNotFoundException occurred. ", e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("ClassNotFoundException occurred. ", e);
    } catch (IOException e) {
        throw new RuntimeException("IOException occurred. ", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                throw new RuntimeException("IOException occurred. ", e);
            }
        }
    }
}

From source file:Main.java

public static Serializable toSerializable(byte[] bytes) {
    if (bytes == null) {
        return null;
    }//  w  ww.  j a v a  2 s.c  o  m
    try {
        final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        final ObjectInputStream ois = new ObjectInputStream(bais);
        try {
            return (Serializable) ois.readObject();
        } finally {
            ois.close();
        }
    } catch (Exception e) {
        String msg = "Failed to convert the object to binary: bytes.length=" + bytes.length;
        throw new IllegalStateException(msg, e);
    }
}

From source file:MSUmpire.SpectrumParser.DIA_Setting.java

public static DIA_Setting ReadDIASettingSerialization(String filepath) {
    if (!new File(FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser")
            .exists()) {/*  www.j  ava  2 s  . c o m*/
        return null;
    }
    try {
        Logger.getRootLogger().debug("Reading DIA setting from file:" + FilenameUtils.getFullPath(filepath)
                + FilenameUtils.getBaseName(filepath) + "_diasetting.ser...");

        FileInputStream fileIn = new FileInputStream(
                FilenameUtils.getFullPath(filepath) + FilenameUtils.getBaseName(filepath) + "_diasetting.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        DIA_Setting setting = (DIA_Setting) in.readObject();
        in.close();
        fileIn.close();
        return setting;

    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return null;
    }
}

From source file:Main.java

public static Object readObject(String path, int fileStatus) {
    if (!TextUtils.isEmpty(path) && fileStatus == FILE_EXISTS) {
        try {/*  ww w .j  a v a 2s. c  o  m*/
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(path));
            Object mObject = in.readObject();
            in.close();
            return mObject;
        } catch (Exception e) {

        }
    }
    return null;
}

From source file:Main.java

public static Object byteToObject(byte[] bytes) throws Exception {
    ObjectInputStream ois = null;
    try {/*  www . j ava2s  .  c o m*/
        ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        return ois.readObject();
    } finally {
        if (ois != null)
            ois.close();
    }
}

From source file:de.kbs.acavis.service.SerializationHelper.java

public static AuthorIdentifier deserializeAuthorIdentifier(String serialization)
        throws IOException, ClassNotFoundException {
    byte b[] = serialization.getBytes();

    ByteArrayInputStream bi = new ByteArrayInputStream(b);
    ObjectInputStream si = new ObjectInputStream(bi);

    AuthorIdentifier identifier = (AuthorIdentifier) si.readObject();

    si.close();
    bi.close();/*from ww w.j  a  v a  2 s.c o m*/

    return identifier;
}