Example usage for java.util.zip CheckedOutputStream CheckedOutputStream

List of usage examples for java.util.zip CheckedOutputStream CheckedOutputStream

Introduction

In this page you can find the example usage for java.util.zip CheckedOutputStream CheckedOutputStream.

Prototype

public CheckedOutputStream(OutputStream out, Checksum cksum) 

Source Link

Document

Creates an output stream with the specified Checksum.

Usage

From source file:io.milton.cloud.server.apps.calendar.CalendarManager.java

private void updateCtag(CalEvent event) {
    OutputStream nulOut = new NullOutputStream();
    CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32());
    appendLine(event.getDescription(), cout);
    appendLine(event.getSummary(), cout);
    appendLine(event.getTimezone(), cout);
    appendLine(event.getStartDate(), cout);
    appendLine(event.getEndDate(), cout);
    Checksum check = cout.getChecksum();
    long crc = check.getValue();
    event.setCtag(crc);/*from   ww w  .j av  a  2 s . com*/
    updateCtag(event.getCalendar());
}

From source file:org.spliffy.server.apps.calendar.CalendarManager.java

private void updateCtag(Calendar sourceCal) {
    OutputStream nulOut = new NullOutputStream();
    CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32());

    HashUtils.appendLine(sourceCal.getColor(), cout);
    if (sourceCal.getEvents() != null) {
        for (CalEvent r : sourceCal.getEvents()) {
            String name = r.getName();
            String line = HashUtils.toHashableText(name, r.getCtag(), "");
            HashUtils.appendLine(line, cout);
        }//from   w w w. j ava2s  .  com
    }
    Checksum check = cout.getChecksum();
    long crc = check.getValue();
    sourceCal.setCtag(crc);
}

From source file:io.milton.cloud.server.apps.calendar.CalendarManager.java

private void updateCtag(Calendar sourceCal) {
    OutputStream nulOut = new NullOutputStream();
    CheckedOutputStream cout = new CheckedOutputStream(nulOut, new Adler32());

    appendLine(sourceCal.getColor(), cout);
    if (sourceCal.getEvents() != null) {
        for (CalEvent r : sourceCal.getEvents()) {
            String name = r.getName();
            String line = HashCalc.getInstance().toHashableText(name, r.getCtag() + "", "");
            appendLine(line, cout);//from   w w  w .  ja v a 2  s.c o m
        }
    }
    Checksum check = cout.getChecksum();
    long crc = check.getValue();
    sourceCal.setCtag(crc);
}

From source file:org.theospi.portfolio.guidance.impl.GuidanceManagerImpl.java

public void packageGuidanceForExport(List guidanceIds, OutputStream os) throws IOException {
    CheckedOutputStream checksum = new CheckedOutputStream(os, new Adler32());
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum));
    List exportedRefs = new ArrayList();
    for (Iterator i = guidanceIds.iterator(); i.hasNext();) {
        String id = (String) i.next();
        processGuidance(id, zos, exportedRefs);
    }/*w  ww  .  j  a v a2s .c o m*/

    zos.finish();
    zos.flush();
}

From source file:com.ibm.amc.FileManager.java

public static File compress(File pathToCompress) {
    try {/*from w  w w.  j a va 2 s.  co m*/
        File zipFile = new File(pathToCompress.getCanonicalPath() + ZIP_EXTENSION);
        FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
        CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32());
        ZipOutputStream out = new ZipOutputStream(cos);
        String basedir = "";
        compress(pathToCompress, out, basedir);
        out.close();
        return zipFile;
    } catch (Exception e) {
        throw new AmcRuntimeException(e);
    }
}

From source file:org.apache.isis.objectstore.nosql.db.file.server.FileServer.java

private void startSyncing() {
    final String syncHost = config.getString("fileserver.sync-host", DEFAULT_HOST);
    final int syncPort = config.getInt("fileserver.sync-port", DEFAULT_SYNC_PORT);
    final int connectionTimeout = config.getInt("fileserver.connection.timeout", 5000);

    LOG.info("preparing to sync to secondary server on " + syncHost + " port " + syncPort);

    final InetAddress address;
    try {/*from w w w  .  ja  va2  s  .  co m*/
        address = InetAddress.getByName(syncHost);
    } catch (final UnknownHostException e) {
        LOG.error("Unknown host " + syncHost, e);
        System.exit(0);
        return;
    }

    while (awaitConnections) {
        Socket socket = null;
        try {
            socket = new Socket(address, syncPort);
            LOG.info("sync connected to " + socket.getInetAddress().getHostAddress() + " port "
                    + socket.getLocalPort());

            final CRC32 crc32 = new CRC32();
            final DataOutput output = new DataOutputStream(
                    new CheckedOutputStream(socket.getOutputStream(), crc32));
            final DataInput input = new DataInputStream(socket.getInputStream());
            output.writeByte(INIT);
            long logId = input.readLong();
            do {
                final long nextLogId = logId + 1;
                final File file = Util.logFile(nextLogId);
                if (file.exists() && server.getLogger().isWritten(nextLogId)) {
                    logId++;

                    output.writeByte(RECOVERY_LOG);
                    crc32.reset();
                    output.writeLong(logId);

                    LOG.info("sending recovery file: " + file.getName());
                    final BufferedInputStream fileInput = new BufferedInputStream(new FileInputStream(file));

                    final byte[] buffer = new byte[8092];
                    int read;
                    while ((read = fileInput.read(buffer)) > 0) {
                        output.writeInt(read);
                        output.write(buffer, 0, read);
                    }
                    output.writeInt(0);

                    output.writeLong(crc32.getValue());
                }
                try {
                    Thread.sleep(300);
                } catch (final InterruptedException ignore) {
                }

                while (isQuiescent) {
                    try {
                        Thread.sleep(300);
                    } catch (final InterruptedException ignore) {
                    }
                }
            } while (awaitConnections);

        } catch (final ConnectException e) {
            LOG.warn("not yet connected to secondary server at " + syncHost + " port " + syncPort);
            try {
                Thread.sleep(connectionTimeout);
            } catch (final InterruptedException ignore) {
            }
        } catch (final IOException e) {
            LOG.error("start failure - networking not set up for " + syncHost, e);
            try {
                Thread.sleep(300);
            } catch (final InterruptedException ignore) {
            }
        } catch (final RuntimeException e) {
            LOG.error("start failure", e);
            try {
                Thread.sleep(300);
            } catch (final InterruptedException ignore) {
            }
        }
    }

}

From source file:fr.itldev.koya.alfservice.KoyaContentService.java

/**
 *
 * @param nodeRefs//w  w w  .  j  av a  2 s . c om
 * @return
 * @throws KoyaServiceException
 */
public File zip(List<String> nodeRefs) throws KoyaServiceException {
    File tmpZipFile = null;
    try {
        tmpZipFile = TempFileProvider.createTempFile("tmpDL", ".zip");
        FileOutputStream fos = new FileOutputStream(tmpZipFile);
        CheckedOutputStream checksum = new CheckedOutputStream(fos, new Adler32());
        BufferedOutputStream buff = new BufferedOutputStream(checksum);
        ZipArchiveOutputStream zipStream = new ZipArchiveOutputStream(buff);
        // NOTE: This encoding allows us to workaround bug...
        // http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
        zipStream.setEncoding("UTF-8");

        zipStream.setMethod(ZipArchiveOutputStream.DEFLATED);
        zipStream.setLevel(Deflater.BEST_COMPRESSION);

        zipStream.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
        zipStream.setUseLanguageEncodingFlag(true);
        zipStream.setFallbackToUTF8(true);

        try {
            for (String nodeRef : nodeRefs) {
                addToZip(koyaNodeService.getNodeRef(nodeRef), zipStream, "");
            }
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
        } finally {
            zipStream.close();
            buff.close();
            checksum.close();
            fos.close();

        }
    } catch (IOException | WebScriptException e) {
        logger.error(e.getMessage(), e);
        throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
    }

    return tmpZipFile;
}

From source file:org.theospi.portfolio.help.HelpManagerImpl.java

public void packageGlossaryForExport(Id worksiteId, OutputStream os) throws IOException {
    getAuthzManager().checkPermission(HelpFunctionConstants.EXPORT_TERMS, getToolId());

    CheckedOutputStream checksum = new CheckedOutputStream(os, new Adler32());
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum));

    putWorksiteTermsIntoZip(worksiteId, zos);

    zos.finish();/*from  www  .  j  a v a 2s.  c  om*/
    zos.flush();
}

From source file:it.cnr.icar.eric.server.query.CompressContentQueryFilterPlugin.java

private ZipOutputStream getZipOutputStream(File file) throws FileNotFoundException {
    //ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file));
    //zos.setMethod(ZipOutputStream.STORED);
    FileOutputStream dest = new FileOutputStream(file);
    CheckedOutputStream checksum = new CheckedOutputStream(dest, new Adler32());
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum));
    return zos;//from w w w . j a  v  a 2  s .c  om
}

From source file:PngEncoder.java

/**
 * Encodes the image./* ww w.j  a  v  a 2  s .  c  om*/
 *
 * @param out an OutputStream to which the encoded image will be
 *            written
 * @throws IOException if a problem is encountered writing the output
 */
public synchronized void encode(OutputStream out) throws IOException {
    Checksum csum = new CRC32();
    out = new CheckedOutputStream(out, csum);

    out.write(SIGNATURE);

    writeIhdrChunk(out, csum);

    if (outputBpp == 1) {
        writePlteChunk(out, csum);
    }

    writeIdatChunks(out, csum);

    writeIendChunk(out, csum);
}