当前位置: 首页>>代码示例>>Java>>正文


Java JarEntry.setTime方法代码示例

本文整理汇总了Java中java.util.jar.JarEntry.setTime方法的典型用法代码示例。如果您正苦于以下问题:Java JarEntry.setTime方法的具体用法?Java JarEntry.setTime怎么用?Java JarEntry.setTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.JarEntry的用法示例。


在下文中一共展示了JarEntry.setTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeFile

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Writes a new {@link File} into the archive.
 *
 * @param inputFile the {@link File} to write.
 * @param jarPath   the filepath inside the archive.
 * @throws IOException
 */
public void writeFile(File inputFile, String jarPath) throws IOException {
    // Get an input stream on the file.
    FileInputStream fis = new FileInputStream(inputFile);
    try {

        // create the zip entry
        JarEntry entry = new JarEntry(jarPath);
        entry.setTime(inputFile.lastModified());

        writeEntry(fis, entry);
    } finally {
        // close the file stream used to read the file
        fis.close();
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:23,代码来源:LocalSignedJarBuilder.java

示例2: writeFile

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Writes a new {@link File} into the archive.
 * @param inputFile the {@link File} to write.
 * @param jarPath the filepath inside the archive.
 * @throws IOException
 */
public void writeFile(File inputFile, String jarPath) throws IOException {
    // Get an input stream on the file.
    FileInputStream fis = new FileInputStream(inputFile);
    try {

        // create the zip entry
        JarEntry entry = new JarEntry(jarPath);
        entry.setTime(inputFile.lastModified());

        writeEntry(fis, entry);
    } finally {
        // close the file stream used to read the file
        fis.close();
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:SignedJarBuilder.java

示例3: testJarMapping

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Check that jar: URLs are correctly mapped back into JarFileSystem resources.
 * @see "#39190"
 */
public void testJarMapping() throws Exception {
    clearWorkDir();
    File workdir = getWorkDir();
    File jar = new File(workdir, "test.jar");
    String textPath = "x.txt";
    OutputStream os = new FileOutputStream(jar);
    try {
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(ZipEntry.STORED);
        JarEntry entry = new JarEntry(textPath);
        entry.setSize(0L);
        entry.setTime(System.currentTimeMillis());
        entry.setCrc(new CRC32().getValue());
        jos.putNextEntry(entry);
        jos.flush();
        jos.close();
    } finally {
        os.close();
    }
    assertTrue("JAR was created", jar.isFile());
    assertTrue("JAR is not empty", jar.length() > 0L);
    JarFileSystem jfs = new JarFileSystem();
    jfs.setJarFile(jar);
    Repository.getDefault().addFileSystem(jfs);
    FileObject rootFO = jfs.getRoot();
    FileObject textFO = jfs.findResource(textPath);
    assertNotNull("JAR contains a/b.txt", textFO);
    String rootS = "jar:" + BaseUtilities.toURI(jar) + "!/";
    URL rootU = new URL(rootS);
    URL textU = new URL(rootS + textPath);
    assertEquals("correct FO -> URL for root", rootU, URLMapper.findURL(rootFO, URLMapper.EXTERNAL));
    assertEquals("correct FO -> URL for " + textPath, textU, URLMapper.findURL(textFO, URLMapper.EXTERNAL));
    assertTrue("correct URL -> FO for root", Arrays.asList(URLMapper.findFileObjects(rootU)).contains(rootFO));
    assertTrue("correct URL -> FO for " + textPath, Arrays.asList(URLMapper.findFileObjects(textU)).contains(textFO));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:URLMapperTest.java

示例4: buildJar

import java.util.jar.JarEntry; //导入方法依赖的package包/类
public static void buildJar(File[] files, File jarFile) throws IOException {
  JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile));
  for (File file : files) {
    // Only use the file name in the JAR entry (classes.dex, classes2.dex, ...)
    JarEntry entry = new JarEntry(file.getName());
    entry.setTime(file.lastModified());
    target.putNextEntry(entry);
    InputStream in = new BufferedInputStream(new FileInputStream(file));
    ByteStreams.copy(in, target);
    in.close();
    target.closeEntry();
  }
  target.close();
}
 
开发者ID:inferjay,项目名称:r8,代码行数:15,代码来源:JarBuilder.java

示例5: addClassToJar

import java.util.jar.JarEntry; //导入方法依赖的package包/类
private static void addClassToJar(final Class<?> type, final JarOutputStream jar) throws URISyntaxException, IOException {

        final URL resource_url = type.getResource(getResourceName(type));
        final File source = new File(resource_url.toURI());
        final String entry_name = type.getPackage().getName().replaceAll("\\.", "/") + "/" + source.getName();
        final JarEntry entry = new JarEntry(entry_name);
        entry.setTime(source.lastModified());
        jar.putNextEntry(entry);
        FileUtils.copyFile(source, jar);
        jar.closeEntry();
    }
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:12,代码来源:Platforms.java

示例6: addOTACert

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Add a copy of the public key to the archive; this should exactly match one
 * of the files in /system/etc/security/otacerts.zip on the device. (The same
 * cert can be extracted from the CERT.RSA file but this is much easier to get
 * at.)
 */
private static void addOTACert(
        JarOutputStream outputJar,
        long timestamp,
        Manifest manifest)
        throws IOException, GeneralSecurityException {
    InputStream input = new ByteArrayInputStream(readKeyContents(PUBLIC_KEY));
    
    BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    
    JarEntry je = new JarEntry(OTACERT_NAME);
    je.setTime(timestamp);
    outputJar.putNextEntry(je);
    
    byte[] b = new byte[4096];
    int read;
    
    System.out.print("\rGenerating OTA certificate...");
    
    while ((read = input.read(b)) != -1) {
        outputJar.write(b, 0, read);
        md.update(b, 0, read);
    }
    input.close();
    
    Attributes attr = new Attributes();
    attr.putValue("SHA1-Digest", base64.encode(md.digest()));
    manifest.getEntries().put(OTACERT_NAME, attr);
}
 
开发者ID:KuroroLucilfer,项目名称:PackageSigner2,代码行数:36,代码来源:Signer.java

示例7: createJarEntry

import java.util.jar.JarEntry; //导入方法依赖的package包/类
private JarEntry createJarEntry(Path source) throws IOException {
    String entryName = FilenameUtils.separatorsToUnix(mtaAssemblyDir.relativize(source).toString());
    if (Files.isDirectory(source) && !entryName.endsWith(Constants.UNIX_PATH_SEPARATOR)) {
        entryName += Constants.UNIX_PATH_SEPARATOR;
    }

    JarEntry entry = new JarEntry(entryName);
    entry.setTime(Files.getLastModifiedTime(source).toMillis());
    return entry;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:11,代码来源:MtaArchiveBuilder.java

示例8: addFile

import java.util.jar.JarEntry; //导入方法依赖的package包/类
protected static void addFile(File zFile, JarOutputStream zOut) throws IOException {
    //Check..
    if (!zFile.exists() || !zFile.canRead()) {
        return;
    }

    if (mVerbose) {
        System.out.println("Adding file : " + zFile.getPath());
    }

    //Add it..
    if (zFile.isDirectory()) {
        //Cycle through
        File[] files = zFile.listFiles();
        for (File ff : files) {
            addFile(ff, zOut);
        }

    } else {
        // Add archive entry
        JarEntry jarAdd = new JarEntry(zFile.getName());
        jarAdd.setTime(zFile.lastModified());
        zOut.putNextEntry(jarAdd);

        // Write file to archive
        FileInputStream in = new FileInputStream(zFile);
        while (true) {
            int nRead = in.read(mBuffer, 0, mBuffer.length);
            if (nRead <= 0)
                break;

            zOut.write(mBuffer, 0, nRead);
        }
        in.close();
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:37,代码来源:Jar.java

示例9: createJarFromFileContent

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Create a JAR using the given file contents and with the given file name.
 * 
 * @param fileName Name of the file to create
 * @param content Content of the created file
 * @return The JAR file content
 * @throws IOException If there is a problem creating the output stream for the JAR file.
 */
public byte[] createJarFromFileContent(final String fileName, final String content)
    throws IOException {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  JarOutputStream jarOutputStream = new JarOutputStream(byteArrayOutputStream);

  JarEntry entry = new JarEntry(fileName);
  entry.setTime(System.currentTimeMillis());
  jarOutputStream.putNextEntry(entry);
  jarOutputStream.write(content.getBytes());
  jarOutputStream.closeEntry();

  jarOutputStream.close();
  return byteArrayOutputStream.toByteArray();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:ClassBuilder.java

示例10: initNextEntry

import java.util.jar.JarEntry; //导入方法依赖的package包/类
private static void initNextEntry(String filePath, JarOutputStream jarFile) throws IOException {
  // ensure to close the previous entry if it exists
  jarFile.closeEntry();

  JarEntry entry = new JarEntry(filePath);
  // ensure the output is deterministic by always setting the same timestamp for all files.
  entry.setTime(FIXED_TIMESTAMP);
  jarFile.putNextEntry(entry);
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:10,代码来源:JarFileCreator.java

示例11: add

import java.util.jar.JarEntry; //导入方法依赖的package包/类
private static void add(Path path, Path source, JarOutputStream target) {
    try {
        String name = path.toString().replace(File.separatorChar, '/');
        JarEntry entry = new JarEntry(name);
        entry.setTime(source.toFile().lastModified());
        target.putNextEntry(entry);
        Files.copy(source, target);
        target.closeEntry();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:JdepsUtil.java

示例12: createJarArchive

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Jar a list of files into a jar archive.
 *
 * @param archiveFile the target jar archive
 * @param tobejared a list of files to be jared
 */
private static boolean createJarArchive(File archiveFile, File[] tobeJared) {
  try {
    byte buffer[] = new byte[BUFFER_SIZE];
    // Open archive file
    FileOutputStream stream = new FileOutputStream(archiveFile);
    JarOutputStream out = new JarOutputStream(stream, new Manifest());

    for (int i = 0; i < tobeJared.length; i++) {
      if (tobeJared[i] == null || !tobeJared[i].exists()
          || tobeJared[i].isDirectory()) {
        continue;
      }

      // Add archive entry
      JarEntry jarAdd = new JarEntry(tobeJared[i].getName());
      jarAdd.setTime(tobeJared[i].lastModified());
      out.putNextEntry(jarAdd);

      // Write file to archive
      FileInputStream in = new FileInputStream(tobeJared[i]);
      while (true) {
        int nRead = in.read(buffer, 0, buffer.length);
        if (nRead <= 0)
          break;
        out.write(buffer, 0, nRead);
      }
      in.close();
    }
    out.close();
    stream.close();
    LOG.info("Adding classes to jar file completed");
    return true;
  } catch (Exception ex) {
    LOG.error("Error: " + ex.getMessage());
    return false;
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:44,代码来源:ClassLoaderTestHelper.java

示例13: addJarFilesToJar

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Add a list of jar files to another jar file under a specific folder.
 * It is used to generated coprocessor jar files which can be loaded by
 * the coprocessor class loader.  It is for testing usage only so we
 * don't be so careful about stream closing in case any exception.
 *
 * @param targetJar the target jar file
 * @param libPrefix the folder where to put inner jar files
 * @param srcJars the source inner jar files to be added
 * @throws Exception if anything doesn't work as expected
 */
public static void addJarFilesToJar(File targetJar,
    String libPrefix, File... srcJars) throws Exception {
  FileOutputStream stream = new FileOutputStream(targetJar);
  JarOutputStream out = new JarOutputStream(stream, new Manifest());
  byte buffer[] = new byte[BUFFER_SIZE];

  for (File jarFile: srcJars) {
    // Add archive entry
    JarEntry jarAdd = new JarEntry(libPrefix + jarFile.getName());
    jarAdd.setTime(jarFile.lastModified());
    out.putNextEntry(jarAdd);

    // Write file to archive
    FileInputStream in = new FileInputStream(jarFile);
    while (true) {
      int nRead = in.read(buffer, 0, buffer.length);
      if (nRead <= 0)
        break;
      out.write(buffer, 0, nRead);
    }
    in.close();
  }
  out.close();
  stream.close();
  LOG.info("Adding jar file to outer jar file completed");
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:38,代码来源:ClassLoaderTestHelper.java

示例14: createJarArchive

import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
 * Creates the jar archive.
 *
 * @param archiveFile the archive file
 * @param toBeJared the files that has to be packed
 */
public void createJarArchive(File archiveFile, File[] toBeJared) {

	try {
		
		byte buffer[] = new byte[BUFFER_SIZE];
		
		// --- Open archive file ----------------------
		FileOutputStream stream = new FileOutputStream(archiveFile);
		JarOutputStream out = new JarOutputStream(stream, new Manifest());

		for (int i = 0; i < toBeJared.length; i++) {
			
			if (toBeJared[i] == null || !toBeJared[i].exists() || toBeJared[i].isDirectory()) {
				continue; // --- Just in case...
			}
				
			String subfolder = "";
			if (baseDir!=null) {
				String elementFolder = toBeJared[i].getParent();
				subfolder = elementFolder.substring(baseDir.length(), elementFolder.length());
				subfolder = subfolder.replace(File.separator, "/");
				if (subfolder.startsWith("/")) {
					subfolder = subfolder.substring(1);
				}
				if (subfolder.endsWith("/")==false) {
					subfolder += "/";
				}					
			}
			
			// --- Add archive entry ------------------
			String jarEntryName = subfolder + toBeJared[i].getName();
			JarEntry jarAdd = new JarEntry(jarEntryName);
			jarAdd.setTime(toBeJared[i].lastModified());
			out.putNextEntry(jarAdd);

			// --- Write file to archive --------------
			FileInputStream in = new FileInputStream(toBeJared[i]);
			while (true) {
				int nRead = in.read(buffer, 0, buffer.length);
				if (nRead <= 0)
					break;
				out.write(buffer, 0, nRead);
			}
			in.close();
		}

		out.close();
		stream.close();
		System.out.println("Creating '" + archiveFile.getAbsoluteFile().getName() + "' completed!");
		
	} catch (Exception ex) {
		ex.printStackTrace();
		System.out.println("Error: " + ex.getMessage());
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:62,代码来源:JarFileCreator.java

示例15: unpackSegment

import java.util.jar.JarEntry; //导入方法依赖的package包/类
private void unpackSegment(InputStream in, JarOutputStream out) throws IOException {
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"0");
    // Process the output directory or jar output.
    new PackageReader(pkg, in).read();

    if (props.getBoolean("unpack.strip.debug"))    pkg.stripAttributeKind("Debug");
    if (props.getBoolean("unpack.strip.compile"))  pkg.stripAttributeKind("Compile");
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"50");
    pkg.ensureAllClassFiles();
    // Now write out the files.
    Set<Package.Class> classesToWrite = new HashSet<>(pkg.getClasses());
    for (Package.File file : pkg.getFiles()) {
        String name = file.nameString;
        JarEntry je = new JarEntry(Utils.getJarEntryName(name));
        boolean deflate;

        deflate = (keepDeflateHint)
                  ? (((file.options & Constants.FO_DEFLATE_HINT) != 0) ||
                    ((pkg.default_options & Constants.AO_DEFLATE_HINT) != 0))
                  : deflateHint;

        boolean needCRC = !deflate;  // STORE mode requires CRC

        if (needCRC)  crc.reset();
        bufOut.reset();
        if (file.isClassStub()) {
            Package.Class cls = file.getStubClass();
            assert(cls != null);
            new ClassWriter(cls, needCRC ? crcOut : bufOut).write();
            classesToWrite.remove(cls);  // for an error check
        } else {
            // collect data & maybe CRC
            file.writeTo(needCRC ? crcOut : bufOut);
        }
        je.setMethod(deflate ? JarEntry.DEFLATED : JarEntry.STORED);
        if (needCRC) {
            if (verbose > 0)
                Utils.log.info("stored size="+bufOut.size()+" and crc="+crc.getValue());

            je.setMethod(JarEntry.STORED);
            je.setSize(bufOut.size());
            je.setCrc(crc.getValue());
        }
        if (keepModtime) {
            je.setTime(file.modtime);
            // Convert back to milliseconds
            je.setTime((long)file.modtime * 1000);
        } else {
            je.setTime((long)modtime * 1000);
        }
        out.putNextEntry(je);
        bufOut.writeTo(out);
        out.closeEntry();
        if (verbose > 0)
            Utils.log.info("Writing "+Utils.zeString((ZipEntry)je));
    }
    assert(classesToWrite.isEmpty());
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"100");
    pkg.reset();  // reset for the next segment, if any
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:61,代码来源:UnpackerImpl.java


注:本文中的java.util.jar.JarEntry.setTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。