Example usage for java.util.zip ZipEntry setCreationTime

List of usage examples for java.util.zip ZipEntry setCreationTime

Introduction

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

Prototype

public ZipEntry setCreationTime(FileTime time) 

Source Link

Document

Sets the creation time of the entry.

Usage

From source file:be.neutrinet.ispng.vpn.api.VPNClientConfig.java

protected Representation finalizeZip(List<String> config, ZipOutputStream zip, ByteArrayOutputStream baos)
        throws Exception {
    String file = "";
    for (String s : config) {
        file += s + '\n';
    }/*from   w ww . j  a v  a 2  s. com*/

    if (caCert == null) {
        caCert = IOUtils.toByteArray(new FileInputStream(VPN.cfg.getProperty("ca.crt")));
    }

    ZipEntry configFile = new ZipEntry("neutrinet.ovpn");
    configFile.setCreationTime(FileTime.from(Instant.now()));
    zip.putNextEntry(configFile);
    zip.write(file.getBytes());
    zip.putNextEntry(new ZipEntry("ca.crt"));
    zip.write(caCert);

    zip.close();

    ByteArrayRepresentation rep = new ByteArrayRepresentation(baos.toByteArray());
    rep.setMediaType(MediaType.APPLICATION_ZIP);
    rep.setSize(baos.size());
    rep.setCharacterSet(CharacterSet.UTF_8);
    rep.setDisposition(new Disposition(Disposition.TYPE_ATTACHMENT));
    return rep;
}

From source file:org.esa.snap.engine_utilities.util.ZipUtils.java

private static void addToZipFile(File file, ZipOutputStream zipStream) {

    try (FileInputStream inputStream = new FileInputStream(file.getPath())) {

        ZipEntry entry = new ZipEntry(file.getName());
        entry.setCreationTime(FileTime.fromMillis(file.lastModified()));
        zipStream.putNextEntry(entry);//w w w.  j ava  2s.c o m

        final byte[] readBuffer = new byte[2048];
        int amountRead;
        int written = 0;

        while ((amountRead = inputStream.read(readBuffer)) > 0) {
            zipStream.write(readBuffer, 0, amountRead);
            written += amountRead;
        }
    } catch (Exception e) {
        SystemUtils.LOG.severe("Unable to zip " + file);
    }
}