Java Code Examples for java.util.zip.ZipEntry#setCreationTime()

The following examples show how to use java.util.zip.ZipEntry#setCreationTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 6 votes vote down vote up
/**
 * Write model jar file with nullability model at DEFAULT_ASTUBX_LOCATION
 *
 * @param outPath Path of output model jar file.
 */
private void writeModelJAR(String outPath) throws IOException {
  Preconditions.checkArgument(
      outPath.endsWith(ASTUBX_JAR_SUFFIX), "invalid model file path! " + outPath);
  ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outPath));
  if (!nonnullParams.isEmpty()) {
    ZipEntry entry = new ZipEntry(DEFAULT_ASTUBX_LOCATION);
    // Set the modification/creation time to 0 to ensure that this jars always have the same
    // checksum
    entry.setTime(0);
    entry.setCreationTime(FileTime.fromMillis(0));
    zos.putNextEntry(entry);
    writeModel(new DataOutputStream(zos));
    zos.closeEntry();
  }
  zos.close();
  LOG(VERBOSE, "Info", "wrote model to: " + outPath);
}
 
Example 2
Source File: NonIncrementalJarDexArchiveHook.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public void addFile(@NonNull String relativePath, byte[] bytes, int offset, int end)
        throws IOException {
    Preconditions.checkNotNull(jarOutputStream, "Archive is not writeable : %s", targetPath);
    // Need to pre-compute checksum for STORED (uncompressed) entries)
    CRC32 checksum = new CRC32();
    checksum.update(bytes, offset, end);

    ZipEntry zipEntry = new ZipEntry(relativePath);
    zipEntry.setLastModifiedTime(ZERO_TIME);
    zipEntry.setLastAccessTime(ZERO_TIME);
    zipEntry.setCreationTime(ZERO_TIME);
    zipEntry.setCrc(checksum.getValue());
    zipEntry.setSize(end - offset);
    zipEntry.setCompressedSize(end - offset);
    zipEntry.setMethod(ZipEntry.STORED);

    jarOutputStream.putNextEntry(zipEntry);
    jarOutputStream.write(bytes, offset, end);
    jarOutputStream.flush();
    jarOutputStream.closeEntry();
}
 
Example 3
Source File: ArchiveBleach.java    From DocBleach with MIT License 6 votes vote down vote up
private ZipEntry cloneEntry(ZipEntry entry) {
  ZipEntry newEntry = new ZipEntry(entry.getName());

  newEntry.setTime(entry.getTime());
  if (entry.getCreationTime() != null) {
    newEntry.setCreationTime(entry.getCreationTime());
  }
  if (entry.getLastModifiedTime() != null) {
    newEntry.setLastModifiedTime(entry.getLastModifiedTime());
  }
  if (entry.getLastAccessTime() != null) {
    newEntry.setLastAccessTime(entry.getLastAccessTime());
  }
  newEntry.setComment(entry.getComment());
  newEntry.setExtra(entry.getExtra());

  return newEntry;
}
 
Example 4
Source File: ImmortalDappModule.java    From AVM with MIT License 5 votes vote down vote up
/**
 * Create the in-memory JAR containing all the classes in this module.
 */
public byte[] createJar(long blockTimeStamp) throws IOException {
    // set jar file timestamp to block timestamp so the whole network is in agreement over this.
    FileTime timestamp = FileTime.fromMillis(blockTimeStamp);

    // manifest, we explicitly write it so that can can control its timestamps.
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, this.mainClass);

    ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
    manifestEntry.setLastModifiedTime(timestamp);
    manifestEntry.setLastAccessTime(timestamp);
    manifestEntry.setCreationTime(timestamp);

    // Create a temporary memory location for this JAR.
    ByteArrayOutputStream tempJarStream = new ByteArrayOutputStream(MAX_JAR_BYTES);

    // create the jar file
    try (JarOutputStream target = new JarOutputStream(tempJarStream)) {
        // first, write the manifest file
        target.putNextEntry(manifestEntry);
        manifest.write(target);
        target.closeEntry();

        // add the classes
        for (String clazz : this.classes.keySet()) {
            JarEntry entry = new JarEntry(clazz.replace('.', '/') + ".class");
            entry.setLastModifiedTime(timestamp);
            entry.setLastAccessTime(timestamp);
            entry.setCreationTime(timestamp);
            target.putNextEntry(entry);
            target.write(this.classes.get(clazz));
            target.closeEntry();
        }
    }
    return tempJarStream.toByteArray();
}
 
Example 5
Source File: AtlasFixStackFramesTransform.java    From atlas with Apache License 2.0 5 votes vote down vote up
@NonNull
private ExceptionRunnable createFile(
        @NonNull File input, @NonNull File output, @NonNull TransformInvocation invocation) {
    return () -> {
        try (ZipFile inputZip = new ZipFile(input);
             ZipOutputStream outputZip =
                     new ZipOutputStream(
                             new BufferedOutputStream(
                                     Files.newOutputStream(output.toPath())))) {
            Enumeration<? extends ZipEntry> inEntries = inputZip.entries();
            while (inEntries.hasMoreElements()) {
                ZipEntry entry = inEntries.nextElement();
                if (!entry.getName().endsWith(SdkConstants.DOT_CLASS)) {
                    continue;
                }
                InputStream originalFile =
                        new BufferedInputStream(inputZip.getInputStream(entry));
                ZipEntry outEntry = new ZipEntry(entry.getName());

                byte[] newEntryContent =
                        getFixedClass(originalFile, getClassLoader(invocation));
                CRC32 crc32 = new CRC32();
                crc32.update(newEntryContent);
                outEntry.setCrc(crc32.getValue());
                outEntry.setMethod(ZipEntry.STORED);
                outEntry.setSize(newEntryContent.length);
                outEntry.setCompressedSize(newEntryContent.length);
                outEntry.setLastAccessTime(ZERO);
                outEntry.setLastModifiedTime(ZERO);
                outEntry.setCreationTime(ZERO);

                outputZip.putNextEntry(outEntry);
                outputZip.write(newEntryContent);
                outputZip.closeEntry();
            }
        }
    };
}
 
Example 6
Source File: TransferServiceImpl.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void putArtifacts ( final ZipOutputStream zos, final String baseName, final ReadableChannel channel, final Collection<? extends ArtifactInformation> inputArtifacts, final boolean onlyRoot ) throws IOException
{
    final List<ArtifactInformation> artifacts = new ArrayList<> ( inputArtifacts ); // make new instance in order to sort them
    Collections.sort ( artifacts, Comparator.comparing ( ArtifactInformation::getId ) );

    for ( final ArtifactInformation art : artifacts )
    {
        if ( !art.is ( "stored" ) )
        {
            continue;
        }

        if ( onlyRoot && art.getParentId () != null )
        {
            // only root artifacts in this run
            continue;
        }

        final String name = String.format ( "%s%s/", baseName, art.getId () );

        // make a dir entry

        {
            final ZipEntry ze = new ZipEntry ( name );
            ze.setComment ( art.getName () );

            final FileTime timestamp = FileTime.fromMillis ( art.getCreationTimestamp ().getTime () );

            ze.setLastModifiedTime ( timestamp );
            ze.setCreationTime ( timestamp );
            ze.setLastAccessTime ( timestamp );

            zos.putNextEntry ( ze );
            zos.closeEntry ();
        }

        // put the provided properties

        putProperties ( zos, name + "properties.xml", art.getProvidedMetaData () );
        putDataEntry ( zos, name + "name", art.getName () );

        if ( art.is ( "generator" ) )
        {
            putDataEntry ( zos, name + "generator", art.getVirtualizerAspectId () );
        }

        // put the blob

        try
        {
            channel.getContext ().stream ( art.getId (), in -> {
                zos.putNextEntry ( new ZipEntry ( name + "data" ) );
                ByteStreams.copy ( in, zos );
                zos.closeEntry ();
            } );
        }
        catch ( final Exception e )
        {
            throw new IOException ( "Failed to export artifact", e );
        }

        // further calls will process all artifacts but only get a filtered list

        final List<? extends ArtifactInformation> childs = art.getChildIds ().stream ().map ( id -> channel.getArtifact ( id ) ).filter ( opt -> opt.isPresent () ).map ( opt -> opt.get () ).collect ( Collectors.toList () );

        // put children of this entry

        putArtifacts ( zos, name, channel, childs, false );
    }
}