List of usage examples for java.io ObjectInputStream close
public void close() throws IOException
From source file:license.rsa.WakeRSA.java
/** * ?/*from ww w . jav a2s .co m*/ * * @param keyFileName * @return * @throws Exception */ static PublicKey readPublicKeyFromFile() throws Exception { ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(KeyData.publicKey)); try { BigInteger m = (BigInteger) oin.readObject(); BigInteger e = (BigInteger) oin.readObject(); System.out.println(); System.out.println(); System.out.println("=======mmm=====" + m); System.out.println("=======eeee=====" + e); System.out.println(); System.out.println(); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(m, e); KeyFactory fact = KeyFactory.getInstance("RSA"); return fact.generatePublic(keySpec); } finally { oin.close(); } }
From source file:license.regist.ProjectInfo.java
private static PrivateKey readPrivateKeyFromFile() throws Exception { ObjectInputStream oin = new ObjectInputStream( new BufferedInputStream(ProjectInfo.class.getClassLoader().getResourceAsStream("private.key"))); try {/*from ww w . ja va 2s . c o m*/ 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: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 *///w ww .jav a2s. 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; }
From source file:license.TestWakeLicense.java
/** * ?//from ww w . j a v a2 s .com * @return * @throws Exception */ static PublicKey readPublicKeyFromFile() throws Exception { ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(KeyData.publicKey)); try { BigInteger m = (BigInteger) oin.readObject(); BigInteger e = (BigInteger) oin.readObject(); RSAPublicKeySpec keySpec = new RSAPublicKeySpec(m, e); KeyFactory fact = KeyFactory.getInstance("RSA"); return fact.generatePublic(keySpec); } finally { oin.close(); } }
From source file:com.conwet.silbops.model.JSONvsRMIPerfT.java
public static void desexternalizeObjects(ByteArrayInputStream bais, int nElements) { long start = 0, end = 0; try {/* w w w. j ava2 s . c o m*/ ObjectInputStream in = new ObjectInputStream(bais); start = System.nanoTime(); for (int i = 0; i < nElements; i++) { in.readObject(); } end = System.nanoTime(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } long elapsed = end - start; long elapsedPerMessage = elapsed / nElements; System.out.println(" Elapsed Time " + nElements + " messages - Desexternalize: " + elapsed + " nanoseconds (" + elapsedPerMessage + " nanoseconds/msg)"); }
From source file:gov.va.chir.tagline.dao.FileDao.java
private static Collection<Feature> loadFeatures(final File file) throws IOException, ClassNotFoundException { final Collection<Feature> features = new ArrayList<Feature>(); final ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); try {//from w ww . jav a2 s. co m Object o = in.readObject(); while (o != null) { if (o instanceof Feature) { features.add((Feature) o); o = in.readObject(); } } } catch (EOFException ex) { // ignore } in.close(); return features; }
From source file:com.sec.ose.osi.sdk.protexsdk.component.ComponentAPIWrapper.java
public static void init() { ObjectInputStream ois; try {//from w ww. ja v a 2 s . c om ois = new ObjectInputStream(new FileInputStream(new File(COMPONENT_FILE_PATH))); ComponentInfo componentInfoTmp = null; while ((componentInfoTmp = (ComponentInfo) ois.readObject()) != null) { globalComponentManager.addComponent(componentInfoTmp); } ois.close(); } catch (FileNotFoundException e) { return; } catch (IOException e) { return; } catch (ClassNotFoundException e) { return; } }
From source file:com.swingtech.commons.util.ClassUtil.java
public static Object deserializeObject(final byte[] bytes) { ObjectInputStream in = null; Object obj = null;//from w w w. jav a 2 s .co m if (bytes == null) { return null; } try { in = new ObjectInputStream(new ByteArrayInputStream(bytes)); obj = in.readObject(); in.close(); } catch (final Exception e) { throw new RuntimeException("Error trying to deserializeObject from this byte array: " + bytes, e); } return obj; }
From source file:de.pawlidi.openaletheia.generator.KeyGenerator.java
public static RSAPublicKeySpec readPublicKeySpec(final String directory) { if (StringUtils.isBlank(directory) || !new File(directory).isDirectory()) { return null; }//w w w .j a va2s. c om RSAPublicKeySpec publicKeySpec = null; ObjectInputStream inputStream = null; try { inputStream = new ObjectInputStream( new BufferedInputStream(new FileInputStream(new File(directory, PUBLIC_KEYSPEC_FILE)))); try { BigInteger m = (BigInteger) inputStream.readObject(); BigInteger e = (BigInteger) inputStream.readObject(); publicKeySpec = new RSAPublicKeySpec(m, e); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { if (inputStream != null) { inputStream.close(); inputStream = null; } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return publicKeySpec; }
From source file:de.pawlidi.openaletheia.generator.KeyGenerator.java
public static RSAPrivateKeySpec readPrivateKeySpec(final String directory) { if (StringUtils.isBlank(directory) || !new File(directory).isDirectory()) { return null; }/* ww w. ja v a2s. co m*/ RSAPrivateKeySpec privateKeySpec = null; ObjectInputStream inputStream = null; try { inputStream = new ObjectInputStream( new BufferedInputStream(new FileInputStream(new File(directory, PRIVATE_KEYSPEC_FILE)))); try { BigInteger m = (BigInteger) inputStream.readObject(); BigInteger e = (BigInteger) inputStream.readObject(); privateKeySpec = new RSAPrivateKeySpec(m, e); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { if (inputStream != null) { inputStream.close(); inputStream = null; } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return privateKeySpec; }