List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:org.LexGrid.LexBIG.caCore.client.proxy.ProxyUnwrappingHttpInvokerRequestExecutor.java
protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException { ObjectOutputStream oos = new ProxyUnwrappingObjectStream(decorateOutputStream(os)); try {/* w w w. j a va2s . c om*/ doWriteRemoteInvocation(invocation, oos); oos.flush(); } finally { oos.close(); } }
From source file:com.sliit.rules.RuleContainer.java
private void loadSaveModel(String filePath, boolean status) { System.out.println("rule loadSaveModel"); if (status) { try {// w w w . ja v a2s . c o m ObjectOutputStream outStream = new ObjectOutputStream(new FileOutputStream(filePath)); outStream.writeObject(ruleMoldel); outStream.flush(); outStream.close(); } catch (IOException e) { log.error("Error occurred:" + e.getMessage()); } } else { try { ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(filePath)); ruleMoldel = (JRip) inputStream.readObject(); } catch (IOException e) { log.error("Error occurred:" + e.getMessage()); } catch (ClassNotFoundException e) { log.error("Error occurred:" + e.getMessage()); } } }
From source file:com.zaubersoftware.gnip4j.api.impl.XMLActivityStreamFeedProcessorTest.java
/** test */ @Test//from w w w. ja v a 2 s. c om public final void test() throws IOException, ParseException { final InputStream is = getClass().getResourceAsStream("fanpage.xml"); try { final AtomicInteger i = new AtomicInteger(); final ObjectMapper mapper = JsonActivityFeedProcessor.getObjectMapper(); final FeedProcessor p = new XMLActivityStreamFeedProcessor<Activity>("foo", new DirectExecuteService(), new StreamNotificationAdapter<Activity>() { @Override public void notify(final Activity activity, final GnipStream stream) { i.incrementAndGet(); try { final byte[] data0 = mapper.writeValueAsBytes(activity); final Activity e = mapper.reader(Activity.class).readValue(data0); final byte[] data1 = mapper.writeValueAsBytes(e); assertArrayEquals(data0, data1); // test serialization final ObjectOutputStream os = new ObjectOutputStream(new ByteArrayOutputStream()); os.writeObject(activity); os.close(); } catch (final Exception e) { throw new RuntimeException(e); } } }, new ActivityUnmarshaller("hola")); p.process(is); assertEquals(23, i.get()); } finally { IOUtils.closeQuietly(is); } }
From source file:com.cyberway.issue.crawler.datamodel.CrawlURITest.java
/** * Test serialization/deserialization works. * // www . j a v a 2 s . c o m * @throws IOException * @throws ClassNotFoundException */ final public void testSerialization() throws IOException, ClassNotFoundException { File serialize = new File(getTmpDir(), this.getClass().getName() + ".serialize"); try { FileOutputStream fos = new FileOutputStream(serialize); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(this.seed); oos.reset(); oos.writeObject(this.seed); oos.reset(); oos.writeObject(this.seed); oos.close(); // Read in the object. FileInputStream fis = new FileInputStream(serialize); ObjectInputStream ois = new ObjectInputStream(fis); CrawlURI deserializedCuri = (CrawlURI) ois.readObject(); deserializedCuri = (CrawlURI) ois.readObject(); deserializedCuri = (CrawlURI) ois.readObject(); assertTrue("Deserialized not equal to original", this.seed.toString().equals(deserializedCuri.toString())); String host = this.seed.getUURI().getHost(); assertTrue("Deserialized host not null", host != null && host.length() >= 0); } finally { serialize.delete(); } }
From source file:edu.cwru.sepia.runner.SimpleModelEpisodicRunner.java
@Override public void run() { seed = configuration.getInt("RandomSeed", 6); numEpisodes = configuration.getInt("NumEpisodes", 1); episodesPerSave = configuration.getInt("EpisodesPerSave", 0); saveAgents = configuration.getBoolean("SaveAgents", false); SimpleModel model = new SimpleModel(stateCreator.createState(), stateCreator, configuration); File baseDirectory = new File("saves"); baseDirectory.mkdirs();//from ww w .j a v a2 s. c om env = new Environment(agents, model, seed, configuration); for (int episode = 0; episode < numEpisodes; episode++) { if (logger.isLoggable(Level.FINE)) logger.fine("=======> Starting episode " + episode); try { env.runEpisode(); } catch (InterruptedException e) { logger.log(Level.SEVERE, "Unable to complete episode " + episode, e); } if (episodesPerSave > 0 && episode % episodesPerSave == 0) { saveState(new File(baseDirectory.getPath() + "/state" + episode + ".sepiaSave"), env.getModel().getState()); for (int j = 0; saveAgents && j < agents.length; j++) { try { ObjectOutputStream agentOut = new ObjectOutputStream( new FileOutputStream(baseDirectory.getPath() + "/agent" + j + "-" + episode)); agentOut.writeObject(agents[j]); agentOut.close(); } catch (Exception ex) { logger.info("Unable to save agent " + j); } } } } }
From source file:iqq.app.module.QQAccountModule.java
private void handleRecentAccountSave(QQAccountEntry entry) { try {/* w w w .j av a 2 s. c o m*/ IMResourceService resources = getContext().getSerivce(IMService.Type.RESOURCE); File userDir = resources.getFile("user" + File.separator + entry.qq); File datFile = new File(userDir, FILE); AESKeyPair key = genAesKeyPair(entry.qq + ""); ByteArrayOutputStream memOut = new ByteArrayOutputStream(); ObjectOutputStream objOut = new ObjectOutputStream(memOut); objOut.writeObject(entry); objOut.close(); byte[] plain = memOut.toByteArray(); byte[] encrypted = UIUtils.Crypt.AESEncrypt(plain, key.key, key.iv); FileUtils.writeByteArrayToFile(datFile, encrypted); } catch (IOException e) { LOG.warn("save account data Error!", e); } }
From source file:de.ingrid.interfaces.csw.admin.IndexScheduler.java
private void savePatternFile() { deletePatternFile();// w w w . j a v a2 s . com LOG.debug("saving pattern to file: " + _patternFile.getAbsolutePath()); try { final ObjectOutputStream writer = new ObjectOutputStream(new FileOutputStream(_patternFile)); writer.writeObject(_pattern); writer.close(); } catch (final Exception e) { LOG.error(e); } }
From source file:com.nextcloud.android.sso.InputStreamBinder.java
private <T extends Serializable> ByteArrayInputStream serializeObjectToInputStream(T obj) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj);//from ww w . java 2s. co m oos.flush(); oos.close(); return new ByteArrayInputStream(baos.toByteArray()); }
From source file:org.sakaiproject.orm.ibatis.support.BlobSerializableTypeHandler.java
protected void setParameterInternal(PreparedStatement ps, int index, Object value, String jdbcType, LobCreator lobCreator) throws SQLException, IOException { if (value != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); try {//from w ww .j ava 2 s .com oos.writeObject(value); oos.flush(); lobCreator.setBlobAsBytes(ps, index, baos.toByteArray()); } finally { oos.close(); } } else { lobCreator.setBlobAsBytes(ps, index, null); } }
From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.UkbDocumentDependentDictionaryInventory.java
public UkbDocumentDependentDictionaryInventory(String inputPath, String serializiblePath, String neededMentionsPath) throws FileNotFoundException, IOException { // Open the serialized version or create it from scratch try {/*from www .j av a 2 s . c o m*/ // System.out.println("Trying to load dictionary from serializable."); ObjectInputStream dictionaryReader = new ObjectInputStream( new BZip2CompressorInputStream(new FileInputStream(serializiblePath))); dictionary = (UkbDictionary) dictionaryReader.readObject(); dictionaryReader.close(); // System.out.println("Loaded dictionary from serializable."); } catch (Exception e) { // System.out.println("Trying to load dictionary from input."); dictionary = new UkbDictionary(inputPath, neededMentionsPath); System.out.println("Loaded dictionary from input."); ObjectOutputStream dictionaryWriter = new ObjectOutputStream( new BZip2CompressorOutputStream(new FileOutputStream(serializiblePath))); dictionaryWriter.writeObject(dictionary); dictionaryWriter.close(); // System.out.println("Stored dictionary in serializable."); } }