List of usage examples for java.io ObjectOutputStream flush
public void flush() throws IOException
From source file:org.kepler.objectmanager.library.LibSearchConfiguration.java
public void serializeToDisk() { if (isDebugging) log.debug("serializeToDisk()"); File saveFile = new File(_saveFileName); if (saveFile.exists()) { if (isDebugging) log.debug("delete " + saveFile); saveFile.delete();/*w w w . j a v a 2 s .c o m*/ } try { ObjectOutputStream oos = null; try { OutputStream os = new FileOutputStream(saveFile); oos = new ObjectOutputStream(os); oos.writeObject(_searchTypes); oos.flush(); if (isDebugging) { log.debug("wrote " + saveFile); } } finally { if (oos != null) { oos.close(); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
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;// w ww. j a v a 2 s . c o 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:node.Mailbox.java
public void printMessageSize(MessageWrapper<AbstractMessage> message) { try {/*w ww. j ava 2 s .c o m*/ ByteArrayOutputStream baostemp = new ByteArrayOutputStream(); ObjectOutputStream oostemp = new ObjectOutputStream(baostemp); oostemp.writeObject(message.msg); oostemp.flush(); println("Message is " + baostemp.size() + " bytes"); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } }
From source file:haven.Utils.java
public static void serialize(Object obj, OutputStream out) throws IOException { ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeObject(obj);/*from ww w . j a v a 2s. co m*/ oout.flush(); }
From source file:org.nuxeo.ecm.core.TestSQLRepositoryDirectBlob.java
@Test public void testBinarySerialization() throws Exception { DocumentModel folder = session.getRootDocument(); DocumentModel file = new DocumentModelImpl(folder.getPathAsString(), "filea", "File"); file = session.createDocument(file); session.save();/*from w ww . jav a 2s .co m*/ // create a binary instance pointing to some content stored on the // filesystem String digest = createFile(); BinaryManager binaryManager = new DefaultBinaryManager(); binaryManager.initialize(new BinaryManagerDescriptor()); Binary binary = binaryManager.getBinary(digest); assertNotNull("Missing file for digest: " + digest, binary); String expected = "this is a file"; byte[] observedContent = new byte[expected.length()]; assertEquals(digest, binary.getDigest()); assertEquals(expected.length(), binary.getLength()); assertEquals(expected.length(), binary.getStream().read(observedContent)); assertEquals(expected, new String(observedContent)); // serialize and deserialize the binary instance ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(binary); out.flush(); out.close(); // Make an input stream from the byte array and read // a copy of the object back in. ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); Binary binaryCopy = (Binary) in.readObject(); observedContent = new byte[expected.length()]; assertEquals(digest, binaryCopy.getDigest()); assertEquals(expected.length(), binaryCopy.getLength()); assertEquals(expected.length(), binaryCopy.getStream().read(observedContent)); assertEquals(expected, new String(observedContent)); binaryManager.close(); }
From source file:org.kepler.gui.component.ShowFolders.java
/** * Save state to the module read/write area as a Java serialized object */// ww w. j a v a 2 s .com private void serializeToDisk() { if (isDebugging) log.debug("serializeToDisk()"); File saveFile = new File(_saveFileName); if (saveFile.exists()) { if (isDebugging) log.debug("delete " + saveFile); saveFile.delete(); } try { ObjectOutputStream oos = null; try { OutputStream os = new FileOutputStream(saveFile); oos = new ObjectOutputStream(os); oos.writeObject(_showFolders); oos.flush(); if (isDebugging) { log.debug("wrote " + saveFile); } } finally { if (oos != null) { oos.close(); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.nuclos.client.LocalUserCaches.java
private String serialize(Object object) { try {/* w w w . j a v a2 s. c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.flush(); oos.close(); return new String(new Base64().encode(bos.toByteArray())); } catch (IOException e) { LOG.warn("Serializing cache '" + object.getClass().getSimpleName() + "' failed.", e); } return null; }
From source file:com.moisespsena.vraptor.javaobjectserialization.JavaObjectSerializerBuilder.java
@Override public void serialize() { ObjectOutputStream out = null; try {/*www . ja va 2s.c o m*/ if (outputStream instanceof ObjectOutputStream) { out = (ObjectOutputStream) outputStream; } else { out = new ObjectOutputStream(outputStream); } out.writeObject(source); out.flush(); } catch (final IOException e) { throw new SerializationException(e); } finally { if (out != null) { try { out.close(); } catch (final IOException e) { throw new SerializationException(e); } } } }
From source file:io.cloudslang.engine.queue.entities.ExecutionMessageConverter.java
private byte[] objToBytes(Object obj) { ObjectOutputStream oos = null; try {//from www.j a v a 2 s . c o m ByteArrayOutputStream bout = new ByteArrayOutputStream(); initPayloadMetaData(bout); BufferedOutputStream bos = new BufferedOutputStream(bout); oos = new ObjectOutputStream(bos); oos.writeObject(obj); oos.flush(); return bout.toByteArray(); } catch (IOException ex) { throw new RuntimeException("Failed to serialize execution plan. Error: ", ex); } finally { IOUtils.closeQuietly(oos); } }
From source file:net.sf.nmedit.jpatch.ModuleDescriptions.java
public void writeCache(File cache) throws FileNotFoundException, IOException { ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(cache))); try {//from ww w . j a v a2 s .c om writeCache(out); } finally { out.flush(); out.close(); } }