gpt4 book ai didi

org.apache.tools.zip.ZipEntry类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 21:30:40 28 4
gpt4 key购买 nike

本文整理了Java中org.apache.tools.zip.ZipEntry类的一些代码示例,展示了ZipEntry类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipEntry类的具体详情如下:
包路径:org.apache.tools.zip.ZipEntry
类名称:ZipEntry

ZipEntry介绍

[英]Extension that adds better handling of extra fields and provides access to the internal and external file attributes.

The extra data is expected to follow the recommendation of APPNOTE.txt:

  • the extra byte array consists of a sequence of extra fields
  • each extra fields starts by a two byte header id followed by a two byte sequence holding the length of the remainder of data.

Any extra data that cannot be parsed by the rules above will be consumed as "unparseable" extra data and treated differently by the methods of this class. Older versions would have thrown an exception if any attempt was made to read or write extra data not conforming to the recommendation.
[中]扩展名,可以更好地处理额外字段,并提供对内部和外部文件属性的访问。
预计额外数据将遵循APPNOTE.txt的建议:
*额外字节数组由一系列额外字段组成
*每个额外字段的开头是一个两字节的头id,后面是一个两字节的序列,其中包含剩余数据的长度。
上述规则无法解析的任何额外数据都将作为“不可解析”的额外数据使用,并由此类的方法进行不同的处理。如果试图读取或写入不符合建议的额外数据,旧版本会引发异常。

代码示例

代码示例来源:origin: jenkinsci/jenkins

private static void zip(StaplerResponse rsp, VirtualFile root, VirtualFile dir, String glob) throws IOException, InterruptedException {
  OutputStream outputStream = rsp.getOutputStream();
  try (ZipOutputStream zos = new ZipOutputStream(outputStream)) {
    zos.setEncoding(System.getProperty("file.encoding")); // TODO JENKINS-20663 make this overridable via query parameter
        ZipEntry e = new ZipEntry(relativePath.replace('\\', '/'));
        VirtualFile f = dir.child(n);
        e.setTime(f.lastModified());
        zos.putNextEntry(e);
        try (InputStream in = f.open()) {
          IOUtils.copy(in, zos);

代码示例来源:origin: org.apache.ant/ant

Set<String> dirSet = new HashSet<>();
StreamUtils.enumerationAsStream(zf.getEntries()).forEach(ze -> {
  String name = ze.getName();
  if (ze.isDirectory()) {
    dirSet.add(name);
  } else if (!name.contains("/")) {

代码示例来源:origin: jenkinsci/jenkins

ZipEntry dirZipEntry = new ZipEntry(relativePath+'/');
  dirZipEntry.setExternalAttributes(BITMASK_IS_DIRECTORY);
  if (mode!=-1)   dirZipEntry.setUnixMode(mode);
  dirZipEntry.setTime(f.lastModified());
  zip.putNextEntry(dirZipEntry);
  zip.closeEntry();
} else {
  ZipEntry fileZipEntry = new ZipEntry(relativePath);
  if (mode!=-1)   fileZipEntry.setUnixMode(mode);
  fileZipEntry.setTime(f.lastModified());
  zip.putNextEntry(fileZipEntry);
  try (InputStream in = Files.newInputStream(f.toPath())) {
    int len;

代码示例来源:origin: org.apache.ant/ant

/**
 * Provides default values for compression method and last
 * modification time.
 *
 * @param entry ZipEntry
 */
private void setDefaults(ZipEntry entry) {
  if (entry.getMethod() == -1) { // not specified
    entry.setMethod(method);
  }
  if (entry.getTime() == -1) { // not specified
    entry.setTime(System.currentTimeMillis());
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Sets Unix permissions in a way that is understood by Info-Zip's
 * unzip command.
 *
 * @param mode an <code>int</code> value
 * @since Ant 1.5.2
 */
public void setUnixMode(final int mode) {
  // CheckStyle:MagicNumberCheck OFF - no point
  setExternalAttributes((mode << SHORT_SHIFT)
             // MS-DOS read-only attribute
             | ((mode & 0200) == 0 ? 1 : 0)
             // MS-DOS directory flag
             | (isDirectory() ? 0x10 : 0));
  // CheckStyle:MagicNumberCheck ON
  platform = PLATFORM_UNIX;
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Overwrite clone.
 *
 * @return a cloned copy of this ZipEntry
 * @since 1.1
 */
@Override
public Object clone() {
  final ZipEntry e = (ZipEntry) super.clone();
  e.setInternalAttributes(getInternalAttributes());
  e.setExternalAttributes(getExternalAttributes());
  e.setExtraFields(getAllExtraFieldsNoCopy());
  return e;
}

代码示例来源:origin: gradle.plugin.com.bettycc.umengauto/core

private static void writePack(Map<ZipEntry, byte[]> readZipAllEntry, ZipFile file, String path, String channel)
    throws Exception {
  ZipOutputStream zot = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(path)));
  Iterator<ZipEntry> iterator = readZipAllEntry.keySet().iterator();
  while (iterator.hasNext()) {
    ZipEntry entry = iterator.next();
    zot.putNextEntry(entry);
    byte[] data = readZipAllEntry.get(entry);
    zot.write(data, 0, data.length);
    // System.out.println(entry);
    // System.out.println(entry.getSize() + " ," +
    // entry.getCompressedSize() + "," + data.length);
    zot.closeEntry();
  }
  zot.putNextEntry(new ZipEntry("META-INF/channel_" + channel));
  zot.closeEntry();
  zot.close();
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

public void visit(File f, String relativePath) throws IOException {
  if(f.isDirectory()) {
    ZipEntry dirZipEntry = new ZipEntry(relativePath+'/');
    // Setting this bit explicitly is needed by some unzipping applications (see HUDSON-3294).
    dirZipEntry.setExternalAttributes(BITMASK_IS_DIRECTORY);
    zip.putNextEntry(dirZipEntry);
    zip.closeEntry();
  } else {
    zip.putNextEntry(new ZipEntry(relativePath));
    FileInputStream in = new FileInputStream(f);
    int len;
    while((len=in.read(buf))>0)
      zip.write(buf,0,len);
    in.close();
    zip.closeEntry();
  }
  entriesWritten++;
}

代码示例来源:origin: com.github.javahaohao/utils

if (folderObject.exists()) {
  ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(
      objFileName));
  zos.setEncoding("GBK");
  ZipEntry ze = null;
  int readLen = 0;
  if (null != file) {// 指定了某个文件
    ze = new ZipEntry(getAbsFileName(baseDir, file));
    ze.setSize(file.length());
    ze.setTime(file.lastModified());
    zos.putNextEntry(ze);
    InputStream is = new BufferedInputStream(new FileInputStream(
        file));
      ze = new ZipEntry(getAbsFileName(baseDir, f));
      ze.setSize(f.length());
      ze.setTime(f.lastModified());
      zos.putNextEntry(ze);

代码示例来源:origin: org.apache.ant/ant

final ZipEntry ze = new ZipEntry(vPath);
  ze.setTime(modTimeMillis);
} else if (dir != null && dir.isExists()) {
  ze.setTime(dir.getLastModified() + millisToAdd);
} else {
  ze.setTime(System.currentTimeMillis() + millisToAdd);
ze.setSize(0);
ze.setMethod(ZipEntry.STORED);
ze.setCrc(EMPTY_CRC);
ze.setUnixMode(mode);
  ze.setExtraFields(extra);
zOut.putNextEntry(ze);

代码示例来源:origin: hyperic/hq

zip_out = new ZipOutputStream(new BufferedOutputStream(file_out));
zip_out.setLevel(Deflater.BEST_COMPRESSION);
zip_out.setMethod(Deflater.DEFLATED);
  outEntry = new org.apache.tools.zip.ZipEntry(inEntry);
  outEntry.setMethod(Deflater.DEFLATED);
  if (!didReplacement && 
    matches(outEntry.getName(), pathToReplace)) {
  outEntry = new org.apache.tools.zip.ZipEntry(pathToReplace);
  addFile(outEntry, zip_out, replacement, rsize, buf);

代码示例来源:origin: org.gradle/gradle-core

private void visitDir(FileCopyDetails dirDetails) {
    try {
      // Trailing slash in name indicates that entry is a directory
      ZipEntry archiveEntry = new ZipEntry(dirDetails.getRelativePath().getPathString() + '/');
      archiveEntry.setTime(getArchiveTimeFor(dirDetails));
      archiveEntry.setUnixMode(UnixStat.DIR_FLAG | dirDetails.getMode());
      zipOutStr.putNextEntry(archiveEntry);
      zipOutStr.closeEntry();
    } catch (Exception e) {
      throw new GradleException(String.format("Could not add %s to ZIP '%s'.", dirDetails, zipFile), e);
    }
  }
}

代码示例来源:origin: apache/hive

public static void zip(String parentDir, String[] inputFiles, String outputFile)
  throws IOException {
 ZipOutputStream output = null;
 try {
  output = new ZipOutputStream(new FileOutputStream(new File(parentDir, outputFile)));
  for (int i = 0; i < inputFiles.length; i++) {
   File f = new File(parentDir, inputFiles[i]);
   FileInputStream input = new FileInputStream(f);
   output.putNextEntry(new ZipEntry(inputFiles[i]));
   try {
    IOUtils.copy(input, output);
   } finally {
    input.close();
   }
  }
 } finally {
  org.apache.hadoop.io.IOUtils.closeStream(output);
 }
}

代码示例来源:origin: com.github.javahaohao/utils

ZipEntry zipe = new ZipEntry(oppositePath + srcFile.getName());
try {
  zipOut.setEncoding("GBK");
  zipOut.putNextEntry(zipe);
  FileInputStream fileIn = new FileInputStream(srcFile);
  while ((readedBytes = fileIn.read(buf)) > 0) {
    zipOut.write(buf, 0, readedBytes);
  zipOut.flush();

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param file
 * @param out
 * @param basedir
 * @throws IOException
 */
private static void compress(Path sourceFilePath, ZipOutputStream out, String basedir) throws IOException {
  if (Files.isDirectory(sourceFilePath)) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(sourceFilePath);) {
      for (Path entry : stream) {
        BasicFileAttributes attrs = Files.readAttributes(entry, BasicFileAttributes.class);
        String fullName = Constants.BLANK.equals(basedir) ? entry.toFile().getName()
            : basedir + Constants.SEPARATOR + entry.toFile().getName();
        if (attrs.isDirectory()) {
          ZipEntry zipEntry = new ZipEntry(fullName + Constants.SEPARATOR);
          out.putNextEntry(zipEntry);
          compress(entry, out, fullName);
        } else {
          compressFile(entry.toFile(), out, fullName);
        }
      }
    } catch (IOException e) {
    }
  } else {
    compressFile(sourceFilePath.toFile(), out, sourceFilePath.toFile().getName());
  }
}

代码示例来源:origin: org.jvnet.hudson.plugins/cvs

zos.putNextEntry(new ZipEntry(name));
FileInputStream fis = new FileInputStream(f);
Util.copyStream(fis, zos);
fis.close();
zos.closeEntry();

代码示例来源:origin: sanluan/PublicCMS

/**
 * @param file
 * @param out
 * @param basedir
 * @throws IOException
 */
private static void compressFile(File file, ZipOutputStream out, String fullName) throws IOException {
  if (CommonUtils.notEmpty(file)) {
    ZipEntry entry = new ZipEntry(fullName);
    entry.setTime(file.lastModified());
    out.putNextEntry(entry);
    try (FileInputStream fis = new FileInputStream(file);) {
      StreamUtils.copy(fis, out);
    }
  }
}

代码示例来源:origin: com.github.javahaohao/utils

if (file.isDirectory()) {
  fileName = fileName + "/";
  ZipEntry entry = new ZipEntry(fileName);
  entry.setTime(file.lastModified());
  zipOutput.putNextEntry(entry);
  String fileNames[] = file.list();
  if (ObjectUtils.isNotEmpty(fileNames)) {
  ZipEntry jarEntry = new ZipEntry(fileName);
  BufferedInputStream in = new BufferedInputStream(
      new FileInputStream(file));
  zipOutput.putNextEntry(jarEntry);
    zipOutput.write(buf, 0, len);
  in.close();

代码示例来源:origin: org.apache.ant/ant

private void setEntry(ZipEntry e) {
  if (e == null) {
    setExists(false);
    return;
  }
  setName(e.getName());
  setExists(true);
  setLastModified(e.getTime());
  setDirectory(e.isDirectory());
  setSize(e.getSize());
  setMode(e.getUnixMode());
  extras = e.getExtraFields(true);
  method = e.getMethod();
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Helper to format "entry too big" messages.
 */
static String getEntryTooBigMessage(ZipEntry ze) {
  return ze.getName() + "'s size exceeds the limit of 4GByte.";
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com