List of usage examples for java.io ObjectInputStream ObjectInputStream
public ObjectInputStream(InputStream in) throws IOException
From source file:co.rsk.peg.RepositoryBlockStoreTest.java
@Test public void test() throws Exception { // This Is how I produced RepositoryBlockStore_data.ser. I had a bitcoind in regtest with 613 blocks + genesis block // NetworkParameters params = RegTestParams.get(); // Context context = new Context(params); // Wallet wallet = new Wallet(context); // BlockStore store = new SPVBlockStore(params, new File("spvBlockstore")); // AbstractBlockChain chain = new BlockChain(context, wallet, store); // PeerGroup peerGroup = new PeerGroup(context, chain); // peerGroup.start(); // final DownloadProgressTracker listener = new DownloadProgressTracker(); // peerGroup.startBlockChainDownload(listener); // listener.await(); // peerGroup.stop(); // StoredBlock storedBlock = chain.getChainHead(); // FileOutputStream fos = new FileOutputStream("RepositoryBlockStore_data.ser"); // ObjectOutputStream oos = new ObjectOutputStream(fos); // for (int i = 0; i < 614; i++) { // Triple<byte[], BigInteger , Integer> tripleStoredBlock = new ImmutableTriple<>(storedBlock.getHeader().bitcoinSerialize(), storedBlock.getChainWork(), storedBlock.getHeight()); // oos.writeObject(tripleStoredBlock); // storedBlock = store.get(storedBlock.getHeader().getPrevBlockHash()); // }/*from w ww . ja v a2 s . co m*/ // oos.close(); // Read original store InputStream fileInputStream = ClassLoader.getSystemResourceAsStream("peg/RepositoryBlockStore_data.ser"); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); Repository repository = new RepositoryImplForTesting(); RepositoryBlockStore store = new RepositoryBlockStore(repository, PrecompiledContracts.BRIDGE_ADDR); for (int i = 0; i < 614; i++) { Triple<byte[], BigInteger, Integer> tripleStoredBlock = (Triple<byte[], BigInteger, Integer>) objectInputStream .readObject(); BtcBlock header = RegTestParams.get().getDefaultSerializer().makeBlock(tripleStoredBlock.getLeft()); StoredBlock storedBlock = new StoredBlock(header, tripleStoredBlock.getMiddle(), tripleStoredBlock.getRight()); if (i == 0) { store.setChainHead(storedBlock); } store.put(storedBlock); } // Create a new instance of the store RepositoryBlockStore store2 = new RepositoryBlockStore(repository, PrecompiledContracts.BRIDGE_ADDR); // Check a specific block that used to fail when we had a bug assertEquals(store.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a")), store2.get(Sha256Hash.wrap("373941fe83961cf70e181e468abc5f9f7cc440c711c3d06948fa66f3912ed27a"))); //Check new instance content is identical to the original one StoredBlock storedBlock = store.getChainHead(); StoredBlock storedBlock2 = store2.getChainHead(); int headHeight = storedBlock.getHeight(); for (int i = 0; i < headHeight; i++) { assertNotNull(storedBlock); assertEquals(storedBlock, storedBlock2); Sha256Hash prevBlockHash = storedBlock.getHeader().getPrevBlockHash(); storedBlock = store.get(prevBlockHash); storedBlock2 = store2.get(prevBlockHash); } }
From source file:com.googlecode.DownloadCache.java
private void loadIndex() throws Exception { if (this.indexFile.isFile()) { FileInputStream input = new FileInputStream(this.indexFile); ObjectInputStream deserialize = new ObjectInputStream(input); this.index = (Map<String, CachedFileEntry>) deserialize.readObject(); deserialize.close();//from ww w . j a v a 2 s . c om } else { this.index = new HashMap<String, CachedFileEntry>(); } }
From source file:com.gsma.mobileconnect.discovery.DiscoveryResponseTest.java
private DiscoveryResponse roundTripSerialize(DiscoveryResponse in) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput output = new ObjectOutputStream(baos); output.writeObject(in);/*from w ww. j a v a 2s . c om*/ output.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInput input = new ObjectInputStream(bais); DiscoveryResponse out = (DiscoveryResponse) input.readObject(); input.close(); return out; }
From source file:corner.util.crypto.Cryptor.java
/** * ?IO?.IO?,./*ww w . ja v a 2s.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:net.schweerelos.parrot.ui.NodeWrapperPersistentLayoutImpl.java
@SuppressWarnings("unchecked") @Override//from w ww. ja v a 2 s. c om public synchronized void restore(String fileName) throws IOException, ClassNotFoundException { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName)); uriToNodeLocation = (Map<String, Point>) ois.readObject(); ois.close(); initializeLocations(); locked = true; fireStateChanged(); }
From source file:org.blanco.techmun.android.cproviders.MesasFetcher.java
private Mesas tryToLoadFromCache(Context context) { try {//from w ww . ja va2 s .c om FileInputStream mesasFIS = context.openFileInput("mesas.df"); ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS); Mesas result = (Mesas) mesasOIS.readObject(); mesasOIS.close(); return result; } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be restored", e); return null; } catch (ClassNotFoundException e) { Log.e("tachmun", "Error in cache file for mesas in content provider. " + "Something is there but is not a Mesas object. Cache no restored", e); return null; } }
From source file:org.blanco.techmun.android.cproviders.EventosFetcher.java
private Eventos tryToLoadFromCache(Context context, long mesaId) { try {/*from ww w . j a v a2 s. c o m*/ FileInputStream mesasFIS = context.openFileInput("eventos_" + mesaId + ".df"); ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS); Eventos result = (Eventos) mesasOIS.readObject(); mesasOIS.close(); return result; } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be restored", e); return null; } catch (ClassNotFoundException e) { Log.e("tachmun", "Error in cache file for mesas in content provider. " + "Something is there but is not a Mesas object. Cache no restored", e); return null; } }
From source file:com.g3net.tool.ObjectUtils.java
/** * //ww w.ja va2s . c om * @param data ?? * @return ??? * @throws Exception */ public static Object deSerializeObject(byte[] data) throws Exception { ByteArrayInputStream bis = null; ObjectInputStream ois = null; if (data == null || data.length == 0) { return null; } try { bis = new ByteArrayInputStream(data); ois = new ObjectInputStream(bis); return ois.readObject(); } finally { if (ois != null) { ois.close(); } } }
From source file:net.sf.dynamicreports.googlecharts.test.AbstractJasperTest.java
private JasperReportBuilder serializableTest(JasperReportBuilder report) throws IOException, ClassNotFoundException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(report);//from www. j a v a 2s. c o m oos.flush(); oos.close(); InputStream stream = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(stream); return (JasperReportBuilder) ois.readObject(); }
From source file:com.google.u2f.gaedemo.impl.DataStoreImpl.java
@Override public EnrollSessionData getEnrollSessionData(String sessionId) { SecretKey key = new SecretKeySpec(SecretKeys.get().sessionEncryptionKey(), "AES"); byte[] serialized = Base64.decodeBase64(sessionId); ByteArrayInputStream inner = new ByteArrayInputStream(serialized); try {//from ww w. ja v a 2 s .com ObjectInputStream in = new ObjectInputStream(inner); SealedObject sealed = (SealedObject) in.readObject(); return (EnrollSessionData) sealed.getObject(key); } catch (InvalidKeyException | ClassNotFoundException | NoSuchAlgorithmException | IOException e) { throw new RuntimeException(e); } }