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:berlin.iconn.persistence.InOutOperations.java

public static float[][] loadSimpleWeights(File file) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file.toPath()));
    float[][] weights = (float[][]) ois.readObject();
    ois.close();
    return weights;
}

From source file:net.mindengine.oculus.frontend.web.Auth.java

public static User decodeUser(String encodedString) {
    try {//  w w  w  .ja v  a2  s.c  o  m
        ObjectInputStream ois = new ObjectInputStream(
                new ByteArrayInputStream(Base64.decodeBase64(encodedString.getBytes())));
        SealedObject sealedObject = (SealedObject) ois.readObject();
        ois.close();

        Cipher dcipher = Cipher.getInstance("DES");
        dcipher.init(Cipher.DECRYPT_MODE, secrectAuthKey);

        User user = (User) sealedObject.getObject(dcipher);
        return user;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static synchronized ArrayList<double[]> readArrayListFromFile(String filename) {
    ObjectInputStream input;
    ArrayList<double[]> x = null;
    try {// w  w w  . j ava2s. c om
        input = new ObjectInputStream(new FileInputStream(new File(filename)));
        Object obj = input.readObject();
        if (obj != null)
            x = (ArrayList<double[]>) input.readObject();
        input.close();
        return x;
    } catch (StreamCorruptedException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    return x;
}

From source file:Main.java

public static <T> List<T> readList(String root, String filename, Class<T> type) {
    List<T> objects = new ArrayList<>();
    File file = new File(root, filename);
    try {//w  w  w  . j  a  va2  s . co  m
        if (file.exists()) {
            FileInputStream fis = new FileInputStream(file);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Object object = ois.readObject();
            if (object instanceof List) {
                for (Object it : (List) object) {
                    objects.add(type.cast(it));
                }
            }
            ois.close();
            return Collections.unmodifiableList(objects);
        }
    } catch (Exception e) {
        Log.e(TAG, String.format("Failed to read [%s]", file), e);
    }
    return Collections.emptyList();
}

From source file:bencoding.securely.Converters.java

public static Object deserializeObjectFromString(String objectString) throws Exception {

    ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(
            Base64.decode(objectString, Base64.DEFAULT));
    GZIPInputStream gzipInputStream = new GZIPInputStream(arrayInputStream);
    ObjectInputStream objectInputStream = new ObjectInputStream(gzipInputStream);

    Object object = objectInputStream.readObject();

    objectInputStream.close();
    gzipInputStream.close();//from  ww  w  . j  a  v a  2 s  .  c  o  m
    arrayInputStream.close();

    return object;
}

From source file:it.polito.elite.dog.core.library.model.DeviceStatus.java

/**
 * Deserialize a DeviceStatus from a byte encoded String 
 * @param serialization/*from  www  .  j  a  va2  s  .c om*/
 *          a byte encoded String of a DeviceStatus
 * @return a deserialized DeviceStatus
 * @throws IOException 
 * @throws ClassNotFoundException 
 */
public static DeviceStatus deserializeFromString(String serialization)
        throws IOException, ClassNotFoundException {
    byte[] data = Base64.decodeBase64(serialization);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    ObjectInputStream decoder = new ObjectInputStream(bais);
    //deserialize the DeviceStatus
    DeviceStatus o = (DeviceStatus) decoder.readObject();
    decoder.close();
    return o;
}

From source file:org.alfresco.rad.test.AlfrescoTestRunner.java

protected static Object objectFromString(String string) throws IOException, ClassNotFoundException {
    byte[] buffer = Base64.decodeBase64(string);
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer));
    Object object = ois.readObject();
    ois.close();
    return object;
}

From source file:it.unimi.di.big.mg4j.io.IOFactories.java

public static Object loadObject(final IOFactory ioFactory, final String filename)
        throws IOException, ClassNotFoundException {
    final ObjectInputStream ois = new ObjectInputStream(
            new FastBufferedInputStream(ioFactory.getInputStream(filename)));
    final Object result = ois.readObject();
    ois.close();
    return result;
}

From source file:info.usbo.skypetwitter.Run.java

public static int load_file() {
    // TWITTER//from   www .  jav  a 2 s . c o m
    try {
        FileInputStream fis = new FileInputStream(work_dir + "\\twitter_ids.data");
        ObjectInputStream ois = new ObjectInputStream(fis);
        twitter_ids = (ArrayList) ois.readObject();
        ois.close();
        fis.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        return 0;
    } catch (ClassNotFoundException c) {
        System.out.println("Class not found");
        c.printStackTrace();
        return 0;
    }
    // VK
    try {
        FileInputStream fis = new FileInputStream(work_dir + "\\vk_ids.data");
        ObjectInputStream ois = new ObjectInputStream(fis);
        vk_ids = (ArrayList) ois.readObject();
        ois.close();
        fis.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        return 0;
    } catch (ClassNotFoundException c) {
        System.out.println("Class not found");
        c.printStackTrace();
        return 0;
    }
    return 1;
}

From source file:BytesUtil.java

public static Object toObject(byte[] bytes) throws IOException, ClassNotFoundException {
    Object obj = null;/*  w  w  w.  j  a  v a  2  s.  c  o m*/
    ByteArrayInputStream bis = null;
    ObjectInputStream ois = null;
    try {
        bis = new ByteArrayInputStream(bytes);
        ois = new ObjectInputStream(bis);
        obj = ois.readObject();
    } finally {
        if (bis != null) {
            bis.close();
        }
        if (ois != null) {
            ois.close();
        }
    }
    return obj;
}