Example usage for java.io ObjectOutputStream flush

List of usage examples for java.io ObjectOutputStream flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:com.sec.ose.osi.thread.job.identify.data.IdentifyErrorQueue.java

private boolean updateDatFileByIdentifyErrorQueue() {

    log.debug("updateIdentifyErrorQueueFile-start - num of item:" + size());

    FileOutputStream fos = null;//from w  ww.java  2s  .  c o  m
    try {
        // Check Folder
        File dir = new File(DAT_FILE_DIRECTORY);
        if (!dir.exists()) {
            if (dir.mkdirs() == false) {
                System.err.println("Can not create folder.");
            }
        }

        // Check File
        File file = new File(identifyQueueErrorFileName);
        if (file.exists() == false) {
            file.createNewFile();
        }
        fos = new FileOutputStream(file); // Overwrite
        if (identifyDataQueueError.size() > 0) {
            ObjectOutputStream oosWriter = new ObjectOutputStream(fos);
            for (IdentifyData tmpIdentifiedData : identifyDataQueueError) {
                oosWriter.writeObject(tmpIdentifiedData);
            }
            oosWriter.flush();
            oosWriter.close();
        }
        fos.close();

        log.debug("updateIdentifyErrorQueueFile-end");

        // write text file
        writeTextFile(toHTMLForm());

        return true;
    } catch (IOException e) {
        log.warn(e);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (Exception e) {
                log.debug(e);
            }
        }
    }
    return false;
}

From source file:com.adaptris.core.services.metadata.CheckUniqueMetadataValueService.java

private void storePreviouslyReceivedValues() {
    if (store != null) {
        try {/*w w w  .  j  av a  2s.  c o  m*/
            ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(store));

            o.writeObject(previousValuesStore);
            o.flush();
            o.close();
        } catch (Exception e) {
            log.error("exception storing previously received values", e);
            log.error(previousValuesStore.toString());
        }
    }
}

From source file:com.izforge.izpack.compiler.packager.impl.MultiVolumePackager.java

/**
 * Writes packs to one or more <em>.pak</em> volumes.
 * <p/>/*from  w  ww. j  a va 2  s.  c  o m*/
 * Pack meta-data is written to the installer jar.
 *
 * @throws IOException for any I/O error
 */
@Override
protected void writePacks() throws IOException {
    String classname = getClass().getSimpleName();

    // propagate the configuration to the variables, for debugging purposes
    getVariables().setProperty(classname + "." + FIRST_VOLUME_FREE_SPACE, Long.toString(maxFirstVolumeSize));
    getVariables().setProperty(classname + "." + VOLUME_SIZE, Long.toString(maxVolumeSize));

    List<PackInfo> packs = getPacksList();
    final int count = packs.size();
    sendMsg("Writing " + count + " Pack" + (count > 1 ? "s" : "") + " into installer");
    logger.fine("Writing " + count + " Pack" + (count > 1 ? "s" : "") + " into installer");
    logger.fine("First volume size: " + maxFirstVolumeSize);
    logger.fine("Subsequent volume size: " + maxVolumeSize);

    File volume = new File(getInfo().getInstallerBase() + ".pak").getAbsoluteFile();
    int volumes = writePacks(packs, volume);

    // write metadata for reading in volumes
    logger.fine("Written " + volumes + " volumes");

    JarOutputStream installerJar = getInstallerJar();
    installerJar.putNextEntry(new ZipEntry(RESOURCES_PATH + "volumes.info"));
    ObjectOutputStream out = new ObjectOutputStream(installerJar);
    out.writeInt(volumes);
    out.writeUTF(volume.getName());
    out.flush();
    installerJar.closeEntry();

    // Now that we know sizes, write pack metadata to primary jar.
    installerJar.putNextEntry(new ZipEntry(RESOURCES_PATH + "packs.info"));
    out = new ObjectOutputStream(installerJar);
    out.writeInt(count);

    for (PackInfo pack : packs) {
        out.writeObject(pack.getPack());
    }
    out.flush();
    installerJar.closeEntry();
}

From source file:com.nabla.project.application.tool.runner.ServiceInvoker.java

private void invokeInNewJVM(MethodInvocation invocation) {

    try {//  w ww .  j  a  va 2 s. co  m

        checkInvocationArgumentsForJVMTransfer(invocation.getArguments());

        String classpath = System.getProperty("java.class.path");

        if (newVMClasspathRoot != null) {

            classpath = generateClassPath(newVMClasspathRoot);

        }

        ProcessBuilder pb = new ProcessBuilder(new String[] { "java", "-classpath", classpath,
                "com.nabla.project.application.tool.runner.ServiceRunner", newVMconfigFileName,
                newVMServiceBeanName, invocation.getMethod().getName() });
        Process p = pb.start();

        ObjectOutputStream oos = new ObjectOutputStream(p.getOutputStream());

        oos.writeObject(invocation.getArguments());
        oos.flush();

    } catch (Exception ioe) {

        throw new RuntimeException(ioe);

    }

}

From source file:org.digidoc4j.SignatureParameters.java

/**
 * Clones signature parameters// w w w.  ja v a  2s.co  m
 *
 * @return new signature parameters object
 */
public SignatureParameters copy() {
    logger.debug("");
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    SignatureParameters copySignatureParameters = null;
    // deep copy
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        oos = new ObjectOutputStream(bos);
        oos.writeObject(this);
        oos.flush();
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
        ois = new ObjectInputStream(bin);
        copySignatureParameters = (SignatureParameters) ois.readObject();
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new DigiDoc4JException(e);
    } finally {
        IOUtils.closeQuietly(oos);
        IOUtils.closeQuietly(ois);
        IOUtils.closeQuietly(bos);
    }
    return copySignatureParameters;
}

From source file:org.globus.examples.services.filebuy.seller.impl.FileResource.java

public synchronized void store() throws ResourceException {
    /* We will use these two variables to write the resource to disk */
    FileOutputStream fos = null;/*  www. j  a v a2  s .  c om*/
    File tmpFile = null;

    logger.info("Attempting to store resource " + this.getID());
    try {
        /* We start by creating a temporary file */
        tmpFile = File.createTempFile("math", ".tmp", getPersistenceHelper().getStorageDirectory());
        /* We open the file for writing */
        fos = new FileOutputStream(tmpFile);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        /* We write the RPs in the file */
        oos.writeFloat(this.price);
        oos.writeUTF(this.name);
        oos.writeUTF(this.location);
        oos.flush();
        logger.info("Successfully stored resource with Name=" + name);
    } catch (Exception e) {
        /* Delete the temporary file if something goes wrong */
        tmpFile.delete();
        throw new ResourceException("Failed to store resource", e);
    } finally {
        /* Clean up */
        if (fos != null) {
            try {
                fos.close();
            } catch (Exception ee) {
            }
        }
    }

    /*
     * We have successfully created a temporary file with our resource's
     * RPs. Now, if there is a previous copy of our resource on disk, we
     * first have to delete it. Next, we rename the temporary file to the
     * file representing our resource.
     */
    File file = getKeyAsFile(this.key);
    if (file.exists()) {
        file.delete();
    }
    if (!tmpFile.renameTo(file)) {
        tmpFile.delete();
        throw new ResourceException("Failed to store resource");
    }
}

From source file:jfs.sync.meta.AbstractMetaStorageAccess.java

/**
 * flushing listing as meta data info for pathAndName[0] in rootPath
 *
 * @param rootPath//ww  w . ja  v a  2 s . co m
 * @param pathAndName
 * path and name for the file and path for which this update takes place
 * @param listing
 */
public void flushMetaData(String rootPath, String[] pathAndName, Map<String, FileInfo> listing) {
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("flushMetaData() flushing " + listing);
        } // if
        OutputStream os = getOutputStream(rootPath, getMetaDataPath(pathAndName[0]), false);

        try {
            byte[] credentials = getCredentials(pathAndName[0]);
            Cipher cipher = SecurityUtils.getCipher(getCipherSpec(), Cipher.ENCRYPT_MODE, credentials);
            os = new CipherOutputStream(os, cipher);
        } catch (InvalidKeyException e) {
            LOG.error("flushMetaData()", e);
        } catch (NoSuchAlgorithmException e) {
            LOG.error("flushMetaData()", e);
        } catch (NoSuchPaddingException e) {
            LOG.error("flushMetaData()", e);
        } // try/catch

        ObjectOutputStream oos = new ObjectOutputStream(os);

        for (FileInfo info : listing.values()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("flushMetaData() writing " + info.getName());
            } // if
            oos.writeObject(info);
        } // for
        oos.flush();
        os.close();
        if (LOG.isDebugEnabled()) {
            Map<String, FileInfo> backtest = getMetaData(rootPath, pathAndName[0]);
            for (FileInfo info : backtest.values()) {
                LOG.debug("flushMetaData() reading " + info.getName());
            } // for
        } // if
    } catch (IOException ioe) {
        LOG.error("flushMetaData() error writing meta data ", ioe);
    } // try/catch
}

From source file:org.apache.flink.api.common.io.DelimitedInputFormatTest.java

@Test
public void testSerialization() throws Exception {
    final byte[] DELIMITER = new byte[] { 1, 2, 3, 4 };
    final int NUM_LINE_SAMPLES = 7;
    final int LINE_LENGTH_LIMIT = 12345;
    final int BUFFER_SIZE = 178;

    DelimitedInputFormat<String> format = new MyTextInputFormat();
    format.setDelimiter(DELIMITER);// w  w  w  . ja v a 2s  .  c  o m
    format.setNumLineSamples(NUM_LINE_SAMPLES);
    format.setLineLengthLimit(LINE_LENGTH_LIMIT);
    format.setBufferSize(BUFFER_SIZE);

    ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(format);
    oos.flush();
    oos.close();

    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    @SuppressWarnings("unchecked")
    DelimitedInputFormat<String> deserialized = (DelimitedInputFormat<String>) ois.readObject();

    assertEquals(NUM_LINE_SAMPLES, deserialized.getNumLineSamples());
    assertEquals(LINE_LENGTH_LIMIT, deserialized.getLineLengthLimit());
    assertEquals(BUFFER_SIZE, deserialized.getBufferSize());
    assertArrayEquals(DELIMITER, deserialized.getDelimiter());
}

From source file:com.izforge.izpack.compiler.packager.impl.Packager.java

/**
 * Write an arbitrary object to primary jar.
 *//*  www  . j a  va 2s . c  om*/
protected void writeInstallerObject(String entryName, Object object) throws IOException {
    primaryJarStream.putNextEntry(new org.apache.tools.zip.ZipEntry(RESOURCES_PATH + entryName));
    ObjectOutputStream out = new ObjectOutputStream(primaryJarStream);
    out.writeObject(object);
    out.flush();
    primaryJarStream.closeEntry();
}

From source file:org.apache.jackrabbit.oak.jcr.CompatibilityIssuesTest.java

private ByteArrayOutputStream serializeObject(Object o) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream(5000);
    ObjectOutputStream objectStream = new ObjectOutputStream(out);
    objectStream.writeObject(o);/* ww  w .j a v  a 2 s  . c om*/
    objectStream.flush();
    return out;
}