Example usage for java.io ObjectOutputStream close

List of usage examples for java.io ObjectOutputStream close

Introduction

In this page you can find the example usage for java.io ObjectOutputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the stream.

Usage

From source file:com.izforge.izpack.panels.target.TargetPanelHelperTest.java

/**
 * Tests the {@link TargetPanelHelper#isIncompatibleInstallation(String, Boolean)} method.
 *
 * @throws IOException for any I/O error
 *///w  ww .  j a v  a2 s.co m
@Test
public void testIsIncompatibleInstallation() throws IOException {
    File dir = File.createTempFile("junit", "");
    FileUtils.deleteQuietly(dir);

    // verify that the method returns false for non-existent directory
    assertFalse(dir.exists());
    assertFalse(TargetPanelHelper.isIncompatibleInstallation(dir.getPath(), true));

    // verify that the method returns false for existing directory
    assertTrue(dir.mkdir());
    assertFalse(TargetPanelHelper.isIncompatibleInstallation(dir.getPath(), true));

    // verify that the method returns false for valid data
    File file = new File(dir, InstallData.INSTALLATION_INFORMATION);
    FileOutputStream stream = new FileOutputStream(file);
    ObjectOutputStream objStream = new ObjectOutputStream(stream);
    objStream.writeObject(new ArrayList<Pack>());
    objStream.close();
    assertFalse(TargetPanelHelper.isIncompatibleInstallation(dir.getPath(), true));

    // verify that the method returns true for invalid data
    assertTrue(file.delete());
    stream = new FileOutputStream(file);
    objStream = new ObjectOutputStream(stream);
    objStream.writeObject(new Integer(1));
    objStream.close();
    assertTrue(TargetPanelHelper.isIncompatibleInstallation(dir.getPath(), true));
}

From source file:jhttpp2.Jhttpp2Launcher.java

public boolean saveServerSettings() {
    storeServerProperties();/*from w  w w . jav a 2  s  .com*/
    ObjectOutputStream file;
    try {
        file = new ObjectOutputStream(new FileOutputStream(DATA_FILE));
        file.writeObject(server.getWildcardDictionary());
        file.writeObject(server.getURLActions());
        file.close();
        return true;
    } catch (Exception e) {
        log.warn("Was not able to save the settings", e);
    }
    return false;

}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.network.ServletReceiver.java

/** Send the given reponse to the client waiting for the given HttpServletResponse */
protected void respond(HttpServletResponse r, Response res) {
    try {/*from ww  w .j av  a  2  s  .c o  m*/
        OutputStream out = r.getOutputStream();
        ObjectOutputStream outputToApplet = new ObjectOutputStream(out);
        outputToApplet.writeObject(res);

        outputToApplet.flush();
        outputToApplet.close();
    } catch (IOException e) {
        log.error("Failed to respond to request", e);
    }
}

From source file:org.activiti.rest.service.api.runtime.SerializableVariablesDiabledTest.java

@Test
public void testCreateSingleSerializableProcessVariable() throws Exception {

    repositoryService.createDeployment().addClasspathResource(
            "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml")
            .deploy();//from   w ww . j  a  v a 2s .c  o m

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    TestSerializableVariable serializable = new TestSerializableVariable();
    serializable.setSomeField("some value");

    // Serialize object to readable stream for representation
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(buffer);
    output.writeObject(serializable);
    output.close();

    InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray());

    // Add name, type and scope
    Map<String, String> additionalFields = new HashMap<String, String>();
    additionalFields.put("name", "serializableVariable");
    additionalFields.put("type", "serializable");

    // Upload a valid BPMN-file using multipart-data
    HttpPost httpPost = new HttpPost(serverUrlPrefix + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object",
            binaryContent, additionalFields));

    // We have serializeable object disabled, we should get a 415.
    assertResponseStatus(httpPost, HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
}

From source file:org.activiti.rest.service.api.runtime.SerializableVariablesDiabledTest.java

@Test
public void testCreateSingleSerializableTaskVariable() throws Exception {
    repositoryService.createDeployment().addClasspathResource(
            "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml")
            .deploy();/*from  w w  w  . ja v a2s  .  c  o  m*/

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    TestSerializableVariable serializable = new TestSerializableVariable();
    serializable.setSomeField("some value");

    // Serialize object to readable stream for representation
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(buffer);
    output.writeObject(serializable);
    output.close();

    InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray());

    // Add name, type and scope
    Map<String, String> additionalFields = new HashMap<String, String>();
    additionalFields.put("name", "serializableVariable");
    additionalFields.put("type", "serializable");

    HttpPost httpPost = new HttpPost(serverUrlPrefix
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
    httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object",
            binaryContent, additionalFields));

    // We have serializeable object disabled, we should get a 415.
    assertResponseStatus(httpPost, HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
}

From source file:org.flowable.rest.service.api.runtime.SerializableVariablesDiabledTest.java

@Test
public void testCreateSingleSerializableProcessVariable() throws Exception {

    repositoryService.createDeployment().addClasspathResource(
            "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml")
            .deploy();/*from  w  w  w .ja  va2s.  com*/

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    TestSerializableVariable serializable = new TestSerializableVariable();
    serializable.setSomeField("some value");

    // Serialize object to readable stream for representation
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(buffer);
    output.writeObject(serializable);
    output.close();

    InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray());

    // Add name, type and scope
    Map<String, String> additionalFields = new HashMap<String, String>();
    additionalFields.put("name", "serializableVariable");
    additionalFields.put("type", "serializable");

    // Upload a valid BPMN-file using multipart-data
    HttpPost httpPost = new HttpPost(serverUrlPrefix + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object",
            binaryContent, additionalFields));

    // We have serializeable object disabled, we should get a 415.
    assertResponseStatus(httpPost, HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
}

From source file:org.flowable.rest.service.api.runtime.SerializableVariablesDiabledTest.java

@Test
public void testCreateSingleSerializableTaskVariable() throws Exception {
    repositoryService.createDeployment().addClasspathResource(
            "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml")
            .deploy();//from  w  w w .j a  va 2s.c  o  m

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    TestSerializableVariable serializable = new TestSerializableVariable();
    serializable.setSomeField("some value");

    // Serialize object to readable stream for representation
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(buffer);
    output.writeObject(serializable);
    output.close();

    InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray());

    // Add name, type and scope
    Map<String, String> additionalFields = new HashMap<String, String>();
    additionalFields.put("name", "serializableVariable");
    additionalFields.put("type", "serializable");

    HttpPost httpPost = new HttpPost(serverUrlPrefix
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
    httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object",
            binaryContent, additionalFields));

    // We have serializeable object disabled, we should get a 415.
    assertResponseStatus(httpPost, HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
}

From source file:com.spoledge.audao.db.dao.RootDaoImpl.java

protected final byte[] serialize(Object o) {
    if (o == null)
        return null;

    try {//  ww  w.  j a  va 2  s  .c om
        ByteArrayOutputStream bos = new ByteArrayOutputStream(4096);
        ObjectOutputStream oos = new ObjectOutputStream(bos);

        oos.writeObject(o);
        oos.close();

        return bos.toByteArray();
    } catch (Exception e) {
        throw new DBException(e);
    }
}

From source file:edu.jhu.hlt.parma.inference.transducers.StringEditModelTrainer.java

private void writeModel(StringEditModel transducer, String filename) {
    try {/*from   w w w .ja v  a2s .c  om*/
        FileOutputStream out = new FileOutputStream(filename);
        ObjectOutputStream objOut = new ObjectOutputStream(out);
        objOut.writeObject(transducer);
        objOut.close();
    } catch (IOException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}

From source file:io.cloudslang.orchestrator.services.ExecutionSerializationUtil.java

public byte[] objToBytes(Execution obj) {
    ObjectOutputStream oos;
    try {/*  www .  jav  a  2  s .  c om*/
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(bout);
        oos = new ObjectOutputStream(bos);

        oos.writeObject(obj);
        oos.close();

        @SuppressWarnings({ "UnnecessaryLocalVariable" })
        byte[] bytes = bout.toByteArray();
        return bytes;
    } catch (IOException ex) {
        throw new RuntimeException("Failed to serialize execution . Error: ", ex);
    }
}