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

/** Read the object from Base64 string. */
public static Object fromString(String s) throws IOException, ClassNotFoundException {
    byte[] data = Base64.decode(s, 0);
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
    Object o = ois.readObject();//from w w w  .j a v a2  s .co  m
    ois.close();
    return o;
}

From source file:Main.java

public static Object deserialize(byte[] array) throws Exception {
    //System.err.println("neser#"+new String(array));
    ObjectInputStream rin = new ObjectInputStream(new ByteArrayInputStream(array));
    Object obj = rin.readObject();
    rin.close();
    //System.err.println("neser##"+obj);
    return obj;/*from   ww w . ja  va2 s . co  m*/
}

From source file:MainClass.java

public static void blowfishEncrypt(String f1, String f2) throws Exception {
    SecretKey key = null;//from  ww  w  .  j  a v a 2 s . c  o  m

    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("BlowfishKey.ser"));
    key = (SecretKey) keyFile.readObject();
    keyFile.close();
    Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, key);
    CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)), cipher);
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2));
    int i;
    do {
        i = in.read();
        if (i != -1)
            out.write(i);
    } while (i > 0);
    in.close();
    out.close();
}

From source file:Main.java

public static Object getObject(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
    ObjectInputStream oi = new ObjectInputStream(bi);
    Object obj = oi.readObject();
    bi.close();/*from w w w.  j a  va  2s. co m*/
    oi.close();
    return obj;
}

From source file:Main.java

public static Object readObject(InputStream o) throws IOException, ClassNotFoundException {
    ObjectInputStream oo = new ObjectInputStream(o);
    try {/* w  w  w .  j a  v a 2 s  . co  m*/
        return oo.readObject();
    } finally {
        oo.close();
    }
}

From source file:Main.java

public static Object getObject(ByteBuffer byteBuffer) throws ClassNotFoundException, IOException {
    InputStream input = new ByteArrayInputStream(byteBuffer.array());
    ObjectInputStream oi = new ObjectInputStream(input);
    Object obj = oi.readObject();
    input.close();//  www.jav  a 2 s .c o m
    oi.close();
    byteBuffer.clear();
    return obj;
}

From source file:Main.java

public static Object ByteToObject(byte[] bytes) {
    Object obj = null;//from w w  w.j  av  a  2  s  .  c  om
    try {
        // bytearray to object
        ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
        ObjectInputStream oi = new ObjectInputStream(bi);

        obj = oi.readObject();
        bi.close();
        oi.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return obj;
}

From source file:MainClass.java

public static void desEncrypt(String f1, String f2) throws Exception {
    SecretKey key = null;/*from  w  w  w .  j av a2  s .  c  o m*/
    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("DESKey.ser"));
    key = (SecretKey) keyFile.readObject();
    keyFile.close();

    KeyGenerator keygen = KeyGenerator.getInstance("DES");
    key = keygen.generateKey();
    ObjectOutputStream keyFileout = new ObjectOutputStream(new FileOutputStream("DESKey.ser"));
    keyFileout.writeObject(key);
    keyFileout.close();
    Cipher cipher = null;
    cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, key);
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(f1));

    CipherOutputStream out = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(f2)), cipher);
    int i;
    do {
        i = in.read();
        if (i != -1)
            out.write(i);
    } while (i != -1);
    in.close();
    out.close();
}

From source file:Main.java

public static Object toObject(byte[] bytes) {
    Object obj = null;//w ww  .j av a 2  s  .  co  m
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);
        obj = ois.readObject();
        ois.close();
        bis.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return obj;
}

From source file:Main.java

public static Object deserializable(byte[] bytes) {
    Object obj = null;//from  ww w  .ja  v  a  2  s.com
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);

        obj = ois.readObject();
        bis.close();
        ois.close();
    } catch (Exception e) {
        System.out.println("tanslation " + e.getMessage());
        e.printStackTrace();
    }

    return obj;
}