List of usage examples for java.io ObjectInputStream readObject
public final Object readObject() throws IOException, ClassNotFoundException
From source file:com.icesoft.faces.webapp.parser.TagToComponentMap.java
/** * Build the map from a serialized source. * * @param fis Input stream for the serialized data. * @return The map/*from ww w .ja va 2s .c o m*/ * @throws IOException * @throws ClassNotFoundException */ static TagToComponentMap loadFrom(InputStream fis) throws IOException, ClassNotFoundException { try { ObjectInputStream ois = new ObjectInputStream(fis); return (TagToComponentMap) ois.readObject(); } catch (IOException e) { log.error("Error building map from TLD tag names", e); throw e; } catch (ClassNotFoundException e) { log.error("Error building map from TLD tag names", e); throw e; } catch (Exception e) { return new TagToComponentMap(); } }
From source file:net.sourceforge.jabm.gametheory.CompressedPayoffMatrix.java
public static CompressedPayoffMatrix readFromFile(String fileName) { CompressedPayoffMatrix result = null; try {//from ww w.java2s. co m ObjectInputStream ois; ois = new ObjectInputStream(new FileInputStream(fileName)); result = (CompressedPayoffMatrix) ois.readObject(); } catch (Exception e) { throw new RuntimeException(e); } return result; }
From source file:hugonicolau.openbrailleinput.wordcorrection.mafsa.MAFSA.java
/** * Factory method. Creates a new Dawg entry by reading in data from the given InputStream. Once the data is read, * the stream remains open./* w w w .j av a 2 s .c om*/ * * @param is the stream with the data to create the Dawg instance. * @return a new Dawg instance with the data loaded * @throws DataFormatException if the InputStream doesn't contain the proper data format for loading a Dawg instance * @throws IOException if reading from the stream casues an IOException. */ public static MAFSA load(InputStream is) throws IOException { BufferedInputStream bis = new BufferedInputStream(is, 8 * 1024); ObjectInputStream ois = new ObjectInputStream(bis); long[] longs; try { longs = (long[]) ois.readObject(); } catch (ClassNotFoundException cnfe) { throw new DataFormatException("Bad file. Not valid for loading com.icantrap.collections.dawg.Dawg", cnfe); } return new MAFSA(longs); }
From source file:com.kellerkindt.scs.utilities.Utilities.java
/** * Deserializes the ItemMeta of an ItemStack from a marshaled String * @param hex ItemMeta marshaled in a String * @return The deserialized ItemMeta//from www . ja va 2 s. c o m * @throws IOException On any internal exception */ @SuppressWarnings("unchecked") public static ItemMeta toItemMeta(String hex) throws IOException { // create streams byte[] bytes = new HexBinaryAdapter().unmarshal(hex); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); try { return (ItemMeta) ConfigurationSerialization.deserializeObject((Map<String, Object>) ois.readObject()); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } }
From source file:com.ligadata.Utils.EncryptDecryptUtils.java
/** * Decrypt text using private key.//from w w w . j a v a2s.c om * * @param algorithm * : algorithm used * @param text * :encrypted text * @param key * :The private key * @return plain text * @throws java.lang.Exception */ public static String decrypt(String algorithm, byte[] text, String privateKeyFile) throws Exception { byte[] dectyptedText = null; try { ObjectInputStream inputStream = null; // Decrypt the cipher text using the private key. inputStream = new ObjectInputStream(new FileInputStream(privateKeyFile)); final PrivateKey privateKey = (PrivateKey) inputStream.readObject(); // get a cipher object and print the provider final Cipher cipher = Cipher.getInstance(algorithm); // decrypt the text using the private key cipher.init(Cipher.DECRYPT_MODE, privateKey); dectyptedText = cipher.doFinal(text); } catch (Exception e) { logger.error("Failed to decrypt given password", e); throw e; } return new String(dectyptedText); }
From source file:com.griddynamics.jagger.util.SerializationUtils.java
public static Object deserialize(byte[] data, ClassLoader classLoader) { ObjectInputStream ois = null; try {/*from w w w . j a v a 2 s .co m*/ try { //TODO fixes for support old reports ois = new JBossObjectInputStream(new ByteArrayInputStream(data), classLoader); } catch (IOException e) { //data stored not with JBoss ois = new ClassLoaderObjectInputStream(classLoader, new ByteArrayInputStream(data)); } return ois.readObject(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { Closeables.close(ois, true); } catch (IOException e) { log.warn("IOException should not have been thrown.", e); } } }
From source file:license.TestWakeLicense.java
/** * ??//from w w w . j a va2 s . com * @return * @throws Exception */ private static PrivateKey readPrivateKeyFromFile() throws Exception { //?? ObjectInputStream oin = new ObjectInputStream(new BufferedInputStream( new FileInputStream(new File("E:\\workspace\\TestProject\\src\\license\\private.key")))); try { BigInteger m = (BigInteger) oin.readObject(); BigInteger e = (BigInteger) oin.readObject(); RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(m, e); KeyFactory fact = KeyFactory.getInstance("RSA"); return fact.generatePrivate(keySpec); } finally { // oin.close(); } }
From source file:edu.stanford.cfuller.colocalization3d.correction.Correction.java
/** * Reads a stored correction from disk./*from www . j av a 2 s . c om*/ * * @param filename The name of the file containing the Correction that was previously written to disk. * @return The Correction contained in the file. * @throws java.io.IOException if the Correction cannot be successfully read. * @throws ClassNotFoundException if the file does not contain a Correction. */ public static Correction readFromDisk(String filename) throws java.io.IOException, ClassNotFoundException { File f = new File(filename); FileReader fr = new FileReader(f); XMLStreamReader xsr = null; String encBinData = null; try { xsr = XMLInputFactory.newFactory().createXMLStreamReader(fr); while (xsr.hasNext()) { int event = xsr.next(); if (event != XMLStreamReader.START_ELEMENT) continue; if (xsr.hasName() && xsr.getLocalName() == BINARY_DATA_ELEMENT) { encBinData = xsr.getElementText(); break; } } } catch (XMLStreamException e) { java.util.logging.Logger.getLogger(LOG_NAME) .severe("Exception encountered while reading XML correction: " + e.getMessage()); } byte[] binData = (new HexBinaryAdapter()).unmarshal(encBinData); ObjectInputStream oi = new ObjectInputStream(new ByteArrayInputStream(binData)); Object o = oi.readObject(); return (Correction) o; }
From source file:com.stromberglabs.jopensurf.Surf.java
public static Surf readFromFile(String location) { File file = new File(location); if (file != null && file.exists()) { try {// w ww . j a va 2s . co m ObjectInputStream str = new ObjectInputStream(new FileInputStream(file)); return (Surf) str.readObject(); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:com.uberspot.storageutils.StorageUtils.java
/** Loads the object with the given fileName from a file in external storage * @param fileName the fileName in which the object was saved * @return the Object read from the file *//*from w ww . j a va 2 s . c o m*/ public static Object loadObjectFromExternalStorage(String fileName) { if (!fileName.startsWith(File.separator)) fileName = File.separator + fileName; File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + fileName); Object obj = null; ObjectInputStream input = null; try { input = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file))); obj = input.readObject(); } catch (Exception e) { e.printStackTrace(System.out); } finally { if (input != null) try { input.close(); } catch (IOException e) { e.printStackTrace(System.out); } } return obj; }