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:org.ajax4jsf.resource.ResourceBuilderImpl.java

public String getUri(InternetResource resource, FacesContext context, Object storeData) {
    StringBuffer uri = new StringBuffer();// ResourceServlet.DEFAULT_SERVLET_PATH).append("/");
    uri.append(resource.getKey());//from ww  w .jav a2  s. co m
    // append serialized data as Base-64 encoded request string.
    if (storeData != null) {
        try {
            byte[] objectData;
            if (storeData instanceof byte[]) {
                objectData = (byte[]) storeData;
                uri.append(DATA_BYTES_SEPARATOR);
            } else {
                ByteArrayOutputStream dataSteram = new ByteArrayOutputStream(1024);
                ObjectOutputStream objStream = new ObjectOutputStream(dataSteram);
                objStream.writeObject(storeData);
                objStream.flush();
                objStream.close();
                dataSteram.close();
                objectData = dataSteram.toByteArray();
                uri.append(DATA_SEPARATOR);
            }
            byte[] dataArray = encrypt(objectData);
            uri.append(new String(dataArray, "ISO-8859-1"));

            // / byte[] objectData = dataSteram.toByteArray();
            // / uri.append("?").append(new
            // String(Base64.encodeBase64(objectData),
            // / "ISO-8859-1"));
        } catch (Exception e) {
            // Ignore errors, log it
            log.error(Messages.getMessage(Messages.QUERY_STRING_BUILDING_ERROR), e);
        }
    }

    boolean isGlobal = !resource.isSessionAware();

    String resourceURL = getWebXml(context).getFacesResourceURL(context, uri.toString(), isGlobal);// context.getApplication().getViewHandler().getResourceURL(context,uri.toString());
    if (!isGlobal) {
        resourceURL = context.getExternalContext().encodeResourceURL(resourceURL);
    }
    if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage(Messages.BUILD_RESOURCE_URI_INFO, resource.getKey(), resourceURL));
    }
    return resourceURL;// context.getExternalContext().encodeResourceURL(resourceURL);

}

From source file:com.inmobi.grill.driver.hive.TestRemoteHiveDriver.java

private byte[] persistContext(QueryContext ctx) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    try {//from w ww.  j  a v  a 2s  .c  o  m
        out.writeObject(ctx);
        boolean isDriverAvailable = (ctx.getSelectedDriver() != null);
        out.writeBoolean(isDriverAvailable);
        if (isDriverAvailable) {
            out.writeUTF(ctx.getSelectedDriver().getClass().getName());
        }
    } finally {
        out.flush();
        out.close();
        baos.close();
    }

    return baos.toByteArray();
}

From source file:org.deidentifier.arx.gui.worker.WorkerSave.java

/**
 * Writes the project to the file./*from  ww  w  .j ava2 s.c o m*/
 *
 * @param model
 * @param zip
 * @throws IOException
 */
private void writeModel(final Model model, final ZipOutputStream zip) throws IOException {
    zip.putNextEntry(new ZipEntry("project.dat")); //$NON-NLS-1$
    final ObjectOutputStream oos = new ObjectOutputStream(zip);
    oos.writeObject(model);
    oos.flush();

    zip.putNextEntry(new ZipEntry("project.xml")); //$NON-NLS-1$
    final Writer w = new OutputStreamWriter(zip);
    w.write(toXML(model));
    w.flush();
}

From source file:org.deidentifier.arx.gui.worker.WorkerSave.java

/**
 * Writes the configuration to the file.
 *
 * @param config/*from www.  jav a 2s.c  o m*/
 * @param prefix
 * @param zip
 * @throws IOException
 */
private void writeConfiguration(final ModelConfiguration config, final String prefix, final ZipOutputStream zip)
        throws IOException {

    zip.putNextEntry(new ZipEntry(prefix + "config.dat")); //$NON-NLS-1$
    final ObjectOutputStream oos = new ObjectOutputStream(zip);
    oos.writeObject(config);
    oos.flush();

    zip.putNextEntry(new ZipEntry(prefix + "config.xml")); //$NON-NLS-1$
    final Writer w = new OutputStreamWriter(zip);
    w.write(toXML(config));
    w.flush();

    writeDefinition(config, prefix, zip);
    writeHierarchies(config, prefix, zip);
}

From source file:org.deidentifier.arx.gui.worker.WorkerSave.java

/**
 * Writes the current filter to the file.
 *
 * @param model// ww w. j  a  v  a2  s.c  o m
 * @param zip
 * @throws IOException
 */
private void writeFilter(final Model model, final ZipOutputStream zip) throws IOException {
    if ((model.getAnonymizer() == null) || (model.getResult() == null)) {
        return;
    }
    zip.putNextEntry(new ZipEntry("filter.dat")); //$NON-NLS-1$
    final ObjectOutputStream oos = new ObjectOutputStream(zip);
    oos.writeObject(model.getNodeFilter());
    oos.flush();
}

From source file:org.eobjects.datacleaner.user.UserPreferencesImpl.java

@Override
public void save() {
    if (_userPreferencesFile == null) {
        logger.debug("Not saving user preferences, since no user preferences file has been provided");
        return;// w  w  w.  ja  va2 s.co  m
    }

    logger.info("Saving user preferences to {}", _userPreferencesFile.getName().getPath());
    ObjectOutputStream outputStream = null;
    try {
        outputStream = new ObjectOutputStream(_userPreferencesFile.getContent().getOutputStream());
        outputStream.writeObject(this);
        outputStream.flush();
    } catch (Exception e) {
        logger.warn("Unexpected error while saving user preferences", e);
        throw new IllegalStateException(e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
    }
}

From source file:org.ejbca.core.ejb.approval.ApprovalSessionBean.java

private final void setApprovalRequest(final ApprovalData approvalData, final ApprovalRequest approvalRequest) {
    try {/*from  w  ww. ja  v a2 s.c om*/
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(approvalRequest);
        oos.flush();
        approvalData.setRequestdata(new String(Base64.encode(baos.toByteArray(), false)));
    } catch (IOException e) {
        log.error("Error building approval request.", e);
        throw new RuntimeException(e);
    }
}

From source file:no.simule.actions.QueryListener.java

void beanInStack() {
    try {//from  w  w w .  j av  a2 s  .c  om
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(this);
        oos.flush();
        oos.close();
        bos.close();
        byte[] byteData = bos.toByteArray();

        beanStack.push(byteData);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.joliciel.talismane.lexicon.LexiconSerializer.java

public void serializeLexicons(String[] args) {
    try {/*from  w  w  w . j a  v  a2 s  .  co  m*/
        String lexiconDirPath = "";
        String outDirPath = "";
        String posTagSetPath = "";
        String lexiconPatternPath = "";

        for (String arg : args) {
            int equalsPos = arg.indexOf('=');
            String argName = arg.substring(0, equalsPos);
            String argValue = arg.substring(equalsPos + 1);
            if (argName.equals("lexiconDir"))
                lexiconDirPath = argValue;
            else if (argName.equals("outDir"))
                outDirPath = argValue;
            else if (argName.equals("posTagSet"))
                posTagSetPath = argValue;
            else if (argName.equals("lexiconPattern"))
                lexiconPatternPath = argValue;
            else
                throw new RuntimeException("Unknown argument: " + argName);
        }

        if (lexiconDirPath.length() == 0)
            throw new RuntimeException("Missing argument: lexiconDir");
        if (outDirPath.length() == 0)
            throw new RuntimeException("Missing argument: outDir");
        if (posTagSetPath.length() == 0)
            throw new RuntimeException("Missing argument: posTagSet");
        if (lexiconPatternPath.length() == 0)
            throw new RuntimeException("Missing argument: lexiconPattern");

        File outDir = new File(outDirPath);
        outDir.mkdirs();

        TalismaneServiceLocator talismaneServiceLocator = TalismaneServiceLocator.getInstance();

        PosTaggerService posTaggerService = talismaneServiceLocator.getPosTaggerServiceLocator()
                .getPosTaggerService();
        File posTagSetFile = new File(posTagSetPath);
        PosTagSet posTagSet = posTaggerService.getPosTagSet(posTagSetFile);

        TalismaneSession.setPosTagSet(posTagSet);

        File lexiconDir = new File(lexiconDirPath);
        File[] lexiconFiles = lexiconDir.listFiles();

        File lexiconPatternFile = new File(lexiconPatternPath);
        Scanner lexiconPatternScanner = new Scanner(lexiconPatternFile);
        String regex = null;
        if (lexiconPatternScanner.hasNextLine()) {
            regex = lexiconPatternScanner.nextLine();
        }
        RegexLexicalEntryReader lexicalEntryReader = new RegexLexicalEntryReader(this.getMorphologyReader());
        lexicalEntryReader.setRegex(regex);
        for (File inFile : lexiconFiles) {
            LOG.debug("Serializing: " + inFile.getName());
            LexiconFile lexiconFile = new LexiconFile(lexicalEntryReader, inFile);
            lexiconFile.setPosTagSet(posTagSet);

            FileOutputStream fos = null;
            ObjectOutputStream out = null;
            String fileNameBase = inFile.getName();
            if (fileNameBase.indexOf('.') >= 0) {
                fileNameBase = fileNameBase.substring(0, fileNameBase.lastIndexOf('.'));

                File outFile = new File(outDir, fileNameBase + ".obj");
                try {
                    fos = new FileOutputStream(outFile);
                    out = new ObjectOutputStream(fos);

                    try {
                        out.writeObject(lexiconFile);
                    } finally {
                        out.flush();
                        out.close();
                    }
                } catch (IOException ioe) {
                    throw new RuntimeException(ioe);
                }
            }
        }
    } catch (IOException ioe) {
        LogUtils.logError(LOG, ioe);
        throw new RuntimeException(ioe);
    }
}

From source file:com.tremolosecurity.proxy.SessionManagerImpl.java

@Override
public void writeSession(UrlHolder holder, TremoloHttpSession session, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    /*/*from w  ww.  j  av  a  2s . co m*/
     * Enumeration enumer = session.getAttributeNames(); while
     * (enumer.hasMoreElements()) { String name = (String)
     * enumer.nextElement(); String value =
     * session.getAttribute(name).toString(); logger.debug(name + "='" +
     * value + "'"); }
     */

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(bos);
    ObjectOutputStream oos = new ObjectOutputStream(gzip);
    oos.writeObject(session);
    oos.flush();
    oos.close();

    byte[] encSession = new byte[0];

    try {
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE,
                holder.getConfig().getSecretKey(holder.getApp().getCookieConfig().getKeyAlias()));
        encSession = cipher.doFinal(bos.toByteArray());
    } catch (Exception e) {
        e.printStackTrace();
    }
    Cookie sessionCookie;
    sessionCookie = new Cookie(holder.getApp().getCookieConfig().getSessionCookieName(),
            new String(Base64.encodeBase64(encSession)));

    // logger.debug("session size : " +
    // org.apache.directory.shared.ldap.util.Base64.encode(encSession).length);

    String domain = ProxyTools.getInstance().getCookieDomain(holder.getApp().getCookieConfig(), request);
    if (domain != null) {
        sessionCookie.setDomain(domain);
    }
    sessionCookie.setPath("/");
    sessionCookie.setSecure(false);
    sessionCookie.setMaxAge(-1);
    response.addCookie(sessionCookie);
}