List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:org.apache.servicemix.nmr.audit.jdbc.JdbcAuditor.java
protected byte[] getDataForExchange(Exchange exchange) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(baos); os.writeObject(checkSerializable(exchange)); os.close(); return baos.toByteArray(); }
From source file:edu.harvard.i2b2.Icd9ToSnomedCT.BinResourceFromIcd9ToSnomedCTMap.java
public void serializeIcd9CodeToNameMap() throws IOException { FileOutputStream fos = null;//from www . j av a2 s .com ObjectOutputStream oos = null; try { fos = new FileOutputStream(binFileName); oos = new ObjectOutputStream(fos); oos.writeObject(Icd9ToSnomedCTMap); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { fos.close(); oos.close(); } }
From source file:edu.harvard.i2b2.loinc.BinResourceFromLoincData.java
public void serializeLoincCodeToNameMap() throws IOException { FileOutputStream fos = null;/*from w w w .j av a 2s . c om*/ ObjectOutputStream oos = null; try { fos = new FileOutputStream("loincCodeToNameMap.bin"); oos = new ObjectOutputStream(fos); oos.writeObject(loincCodeToNameMap); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { fos.close(); oos.close(); } }
From source file:com.servoy.extensions.plugins.http.AllowedCertTrustStrategy.java
public void add(X509Certificate[] certificates) { getCertificatesHolder();/*from w ww . j a v a 2s.c om*/ holder.add(certificates); File file = new File(System.getProperty("user.home"), J2DBGlobals.CLIENT_LOCAL_DIR + "servoy.ks"); //$NON-NLS-1$//$NON-NLS-2$ if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); oos.writeObject(holder); } catch (Exception e) { Debug.error(e); } finally { try { if (oos != null) oos.close(); } catch (Exception e) { } } }
From source file:hudson.console.AnnotatedLargeText.java
public long writeHtmlTo(long start, Writer w) throws IOException { ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, createAnnotator(Stapler.getCurrentRequest()), context, charset); long r = super.writeLogTo(start, caw); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Cipher sym = PASSING_ANNOTATOR.encrypt(); ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym))); oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack oos.writeObject(caw.getConsoleAnnotator()); oos.close(); StaplerResponse rsp = Stapler.getCurrentResponse(); if (rsp != null) rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); return r;/*from w ww . j a v a 2 s . co m*/ }
From source file:net.sf.ehcache.StatisticsTest.java
/** * We want to be able to use Statistics as a value object. * We need to do some magic with the refernence held to Cache *//*from www.j a v a 2 s . c om*/ public void testSerialization() throws IOException, ClassNotFoundException { Cache cache = new Cache("test", 1, true, false, 5, 2); manager.addCache(cache); cache.put(new Element("key1", "value1")); cache.put(new Element("key2", "value1")); cache.get("key1"); cache.get("key1"); Statistics statistics = cache.getStatistics(); assertEquals(2, statistics.getCacheHits()); assertEquals(1, statistics.getOnDiskHits()); assertEquals(1, statistics.getInMemoryHits()); assertEquals(0, statistics.getCacheMisses()); assertEquals(Statistics.STATISTICS_ACCURACY_BEST_EFFORT, statistics.getStatisticsAccuracy()); statistics.clearStatistics(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bout); oos.writeObject(statistics); byte[] serializedValue = bout.toByteArray(); oos.close(); Statistics afterDeserializationStatistics = null; ByteArrayInputStream bin = new ByteArrayInputStream(serializedValue); ObjectInputStream ois = new ObjectInputStream(bin); afterDeserializationStatistics = (Statistics) ois.readObject(); ois.close(); //Check after Serialization assertEquals(2, afterDeserializationStatistics.getCacheHits()); assertEquals(1, afterDeserializationStatistics.getOnDiskHits()); assertEquals(1, afterDeserializationStatistics.getInMemoryHits()); assertEquals(0, afterDeserializationStatistics.getCacheMisses()); assertEquals(Statistics.STATISTICS_ACCURACY_BEST_EFFORT, statistics.getStatisticsAccuracy()); statistics.clearStatistics(); }
From source file:org.flowable.mule.MuleSendActivityBehavior.java
public void execute(DelegateExecution execution) { String endpointUrlValue = this.getStringFromField(this.endpointUrl, execution); String languageValue = this.getStringFromField(this.language, execution); String payloadExpressionValue = this.getStringFromField(this.payloadExpression, execution); String resultVariableValue = this.getStringFromField(this.resultVariable, execution); String usernameValue = this.getStringFromField(this.username, execution); String passwordValue = this.getStringFromField(this.password, execution); boolean isFlowable5Execution = false; Object payload = null;/*from ww w .j av a2 s .co m*/ if ((Context.getCommandContext() != null && Flowable5Util .isFlowable5ProcessDefinitionId(Context.getCommandContext(), execution.getProcessDefinitionId())) || (Context.getCommandContext() == null && Flowable5Util.getFlowable5CompatibilityHandler() != null)) { payload = Flowable5Util.getFlowable5CompatibilityHandler() .getScriptingEngineValue(payloadExpressionValue, languageValue, execution); isFlowable5Execution = true; } else { ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines(); payload = scriptingEngines.evaluate(payloadExpressionValue, languageValue, execution); } if (endpointUrlValue.startsWith("vm:")) { LocalMuleClient client = this.getMuleContext().getClient(); MuleMessage message = new DefaultMuleMessage(payload, this.getMuleContext()); MuleMessage resultMessage; try { resultMessage = client.send(endpointUrlValue, message); } catch (MuleException e) { throw new RuntimeException(e); } Object result = resultMessage.getPayload(); if (resultVariableValue != null) { execution.setVariable(resultVariableValue, result); } } else { HttpClientBuilder clientBuilder = HttpClientBuilder.create(); if (usernameValue != null && passwordValue != null) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(usernameValue, passwordValue); provider.setCredentials(new AuthScope("localhost", -1, "mule-realm"), credentials); clientBuilder.setDefaultCredentialsProvider(provider); } HttpClient client = clientBuilder.build(); HttpPost request = new HttpPost(endpointUrlValue); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(payload); oos.flush(); oos.close(); request.setEntity(new ByteArrayEntity(baos.toByteArray())); } catch (Exception e) { throw new FlowableException("Error setting message payload", e); } byte[] responseBytes = null; try { // execute the POST request HttpResponse response = client.execute(request); responseBytes = IOUtils.toByteArray(response.getEntity().getContent()); } catch (Exception e) { throw new RuntimeException(e); } finally { // release any connection resources used by the method request.releaseConnection(); } if (responseBytes != null) { try { ByteArrayInputStream in = new ByteArrayInputStream(responseBytes); ObjectInputStream is = new ObjectInputStream(in); Object result = is.readObject(); if (resultVariableValue != null) { execution.setVariable(resultVariableValue, result); } } catch (Exception e) { throw new FlowableException("Failed to read response value", e); } } } if (isFlowable5Execution) { Flowable5Util.getFlowable5CompatibilityHandler().leaveExecution(execution); } else { this.leave(execution); } }
From source file:fr.paris.lutece.portal.business.mail.MailItemQueueDAO.java
/** * Insert a new mail item in the table.//from w w w . j av a2 s.c o m * * @param mailItemQueue * the mail item */ @Override public synchronized void insert(MailItemQueue mailItemQueue) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream; objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(mailItemQueue.getMailItem()); objectOutputStream.close(); byteArrayOutputStream.close(); TransactionManager.beginTransaction(null); try { DAOUtil daoUtil = new DAOUtil(SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS); daoUtil.executeUpdate(); daoUtil.nextGeneratedKey(); int nNewPrimaryKey = daoUtil.getGeneratedKeyInt(1); mailItemQueue.setIdMailItemQueue(nNewPrimaryKey); daoUtil.free(); daoUtil = new DAOUtil(SQL_QUERY_INSERT_MAIL_ITEM); daoUtil.setInt(1, nNewPrimaryKey); daoUtil.setBytes(2, byteArrayOutputStream.toByteArray()); daoUtil.executeUpdate(); daoUtil.free(); TransactionManager.commitTransaction(null); } catch (Exception e) { TransactionManager.rollBack(null); AppLogService.error(e); } } catch (Exception e) { AppLogService.error(e); } }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test(expected = ObjectTypeNotExpectedException.class) public void testReadObject1() throws Exception { MockTestObject1 object = new MockTestObject1(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(object);/* ww w . java2 s. c om*/ stream.close(); byte[] data = bytes.toByteArray(); this.serializer.readObject(MockTestObject2.class, data); }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test(expected = ObjectTypeNotExpectedException.class) public void testReadObject4() throws Exception { MockTestObject2 object = new MockTestObject2(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(object);/*from w w w. ja v a 2 s .c o m*/ stream.close(); byte[] data = bytes.toByteArray(); this.serializer.readObject(MockTestObject1.class, data); }