Example usage for java.io ObjectInputStream ObjectInputStream

List of usage examples for java.io ObjectInputStream ObjectInputStream

Introduction

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

Prototype

public ObjectInputStream(InputStream in) throws IOException 

Source Link

Document

Creates an ObjectInputStream that reads from the specified InputStream.

Usage

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();/*w  w  w . j a  v a 2s.co  m*/
    oi.close();
    byteBuffer.clear();
    return obj;
}

From source file:Main.java

public static Object fromBytes(byte[] arr) throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(arr);
    ObjectInputStream ois = new ObjectInputStream(bais);
    return ois.readObject();
}

From source file:Main.java

private static Object bytes2Object(final byte[] bytes) {
    if (bytes == null)
        return null;
    ObjectInputStream ois = null;
    try {//from   ww w  .  j a  v a  2  s. co m
        ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        return ois.readObject();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        try {
            if (ois != null) {
                ois.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:SerializationUtils.java

public static Object deserialize(byte[] bytes) throws ClassNotFoundException {
    try {/* www  .java2 s. c o m*/
        ByteArrayInputStream input = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(input);
        return ois.readObject();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("error reading from byte-array!");
    }
}

From source file:com.vico.license.util.rsa.RSAdoDecrypt.java

public static String decrypt(String cryptograph) throws Exception {
    Key privateKey;/*  w w  w . j  a va  2  s .co  m*/
    String path = Thread.currentThread().getContextClassLoader().getResource("/").toURI().getPath();
    ObjectInputStream ois = null;
    try {
        /** ? */
        ois = new ObjectInputStream(new FileInputStream(path + FileNames.PRIVATEKEY_NAME));
        privateKey = (Key) ois.readObject();
    } catch (Exception e) {
        throw e;
    } finally {
        ois.close();
    }

    /** Cipher?RSA */
    Cipher cipher = Cipher.getInstance(ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE, privateKey);

    /** ? */
    byte[] b1 = Base64.decodeBase64(cryptograph);
    /** ? */
    byte[] b = cipher.doFinal(b1);
    return new String(b);
}

From source file:Main.java

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

    try {//from ww w  .  j  a va2 s  .c  o m
        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:Main.java

public static Object readObject(String path, int fileStatus) {
    if (!TextUtils.isEmpty(path) && fileStatus == FILE_EXISTS) {
        try {//www  .  java2s . 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 Serializable toSerializable(byte[] bytes) {
    if (bytes == null) {
        return null;
    }/*from w  w  w  .ja  va 2s.  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:Util.java

public static Object decompress(byte[] data) {
    if (data == null) {
        return null;
    }// w  w  w .  j  a v  a 2  s .co  m
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        GZIPInputStream gin = new GZIPInputStream(bais);
        ObjectInputStream ois = new ObjectInputStream(gin);
        return ois.readObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Object readGZipCompressedObject(InputStream in) throws IOException, ClassNotFoundException {

    GZIPInputStream gis = new GZIPInputStream(in);
    ObjectInputStream ois = new ObjectInputStream(gis);
    return ois.readObject();

}