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:org.versly.rest.wsdoc.RestDocumentation.java

/**
 * Read and return a serialized {@link RestDocumentation} instance from <code>in</code>,
 * as serialized by {@link #toStream}.//from w  ww . j  a  v a 2 s  .com
 */
public static RestDocumentation fromStream(InputStream in) throws IOException, ClassNotFoundException {
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(in);
        return (RestDocumentation) ois.readObject();
    } finally {
        if (ois != null)
            ois.close();
    }
}

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

public static String decrypt(String cryptograph) throws Exception {
    Key privateKey;/*from  w  ww . ja v  a 2 s .c  om*/
    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:com.joliciel.jochre.lexicon.TextFileLexicon.java

public static TextFileLexicon deserialize(ZipInputStream zis) {
    TextFileLexicon memoryBase = null;//  w ww .  j  av  a  2 s .  c o  m
    try {
        ZipEntry zipEntry;
        if ((zipEntry = zis.getNextEntry()) != null) {
            LOG.debug("Scanning zip entry " + zipEntry.getName());

            ObjectInputStream in = new ObjectInputStream(zis);
            memoryBase = (TextFileLexicon) in.readObject();
            zis.closeEntry();
            in.close();
        } else {
            throw new RuntimeException("No zip entry in input stream");
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }

    return memoryBase;
}

From source file:Main.java

public static Object readObjectFromFile(String fileName) {

    ObjectInputStream ois = null;
    FileInputStream fis = null;/*from   w ww .  ja va2  s  .  c  o  m*/
    try {
        fis = new FileInputStream(fileName);
        ois = new ObjectInputStream(fis);
        return ois.readObject();

    } catch (Exception e) {

    } finally {
        if (ois != null)
            try {
                ois.close();
                ois = null;
            } catch (IOException e) {
            }
        if (fis != null)
            try {
                fis.close();
                fis = null;
            } catch (IOException e) {
            }
    }

    return null;

}

From source file:corner.util.crypto.Cryptor.java

/**
 * ?IO?.IO?,.//from  w ww.j  a  va  2 s .com
 * @param inputFileName ????.
 * @param keyFile ??.
 * @return ?IO?.
 */
public static InputStream dencryptFileIO(String inputFileName, String keyFile) {
    if (keyFile == null) {
        try {
            return new FileInputStream(new File(inputFileName));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    SecretKey key = null;

    ObjectInputStream keyis;
    try {
        keyis = new ObjectInputStream(new FileInputStream(keyFile));
        key = (SecretKey) keyis.readObject();

        keyis.close();
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    //keyCipher
    Cipher cipher = null;

    try {
        //,
        cipher = Cipher.getInstance("DES");
        // ?
        cipher.init(Cipher.DECRYPT_MODE, key);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (NoSuchPaddingException e) {
        throw new RuntimeException(e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e);
    }

    File file = new File(inputFileName);

    try {

        //?
        CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(file)),
                cipher);
        return in;

    } catch (Exception e) {
        throw new RuntimeException(e);

    }

}

From source file:corner.util.crypto.Cryptor.java

/**
 * IO?,IO??,.//from   ww w  . ja v  a 2 s . com
 * @param outFileName ??. 
 * @param keyFile ??.
 * @return ??.
 */
public static OutputStream encryptFileIO(String outFileName, String keyFile) {
    if (keyFile == null) {
        try {
            return new FileOutputStream(outFileName);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    SecretKey key = null;

    //?
    ObjectInputStream keyis;
    try {
        keyis = new ObjectInputStream(new FileInputStream(keyFile));
        key = (SecretKey) keyis.readObject();
        keyis.close();
    } catch (FileNotFoundException e) {
        log.error("file not found!", e);
        throw new RuntimeException("file not found", e);
    } catch (IOException e) {
        log.error("io occour exception", e);
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        log.error("Class Not Found  exception", e);
        throw new RuntimeException(e);
    }

    //keyCipher
    Cipher cipher = null;
    //?Cipher?

    try {
        cipher = Cipher.getInstance("DES");
        //?

        cipher.init(Cipher.ENCRYPT_MODE, key);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (NoSuchPaddingException e) {
        throw new RuntimeException(e);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e);
    }

    //???

    //
    CipherOutputStream out = null;
    try {
        out = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(outFileName)), cipher);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    }

    return out;

}

From source file:Main.java

/**
 * Redintegrate a serialized object.//www.  jav  a2s .  c  om
 * @param serial a byte array of the serialized object.
 * @return the original object or null if an error occurs.
 */
public static Object deserialize(byte[] serial) {
    ByteArrayInputStream bais = new ByteArrayInputStream(serial);
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(bais);
        return ois.readObject();
    } catch (IOException e) {
        return null;
    } catch (ClassNotFoundException e) {
        return null;
    } finally {
        try {
            if (ois != null)
                ois.close();
        } catch (IOException e) {
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.StorageImpl.java

private static void load() {
    try {//  ww  w  .j  a v a2s  .c o  m
        final File file = new File(System.getProperty("user.home"), "htmlunit.storage");
        if (file.exists()) {
            final ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
            SINGLETON_ = (StorageImpl) in.readObject();
            SINGLETON_.sessionStorage_ = new HashMap<String, Map<String, String>>();
            in.close();
        }
    } catch (final Exception e) {
        LOG.info("Could not load storage", e);
    }
}

From source file:hydrograph.engine.hadoop.inputformat.TupleMemoryInputFormat.java

public static ITupleGenerator retrieveTupleGenerator(JobConf conf, String key) {
    String s = conf.get(key);/* w w  w. j a  va2  s .  c om*/
    if (s == null)

        return null;

    String[] pieces = s.split(":");

    byte[] val;

    if (pieces.length > 1) {
        val = decodeBytes(pieces[1]);
    } else {
        val = new byte[0];
    }

    ByteArrayInputStream stream = new ByteArrayInputStream(val);
    ObjectInputStream in;

    ITupleGenerator tupleGenerator;
    try {
        in = new ObjectInputStream(stream);
        tupleGenerator = (ITupleGenerator) in.readObject();
        in.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    return tupleGenerator;
}

From source file:Main.java

private static Object bytes2Object(final byte[] bytes) {
    if (bytes == null)
        return null;
    ObjectInputStream ois = null;
    try {/*ww  w. jav  a2  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();
        }
    }
}