org.apache.tools.zip.ZipOutputStream.putNextEntry()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(201)

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

ZipOutputStream.putNextEntry介绍

暂无

代码示例

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

@Override
  public void putNextEntry(ZipEntry ze) throws IOException {
    ze.setTime(dirTime+1999);   // roundup
    super.putNextEntry(ze);
  }
}) {

代码示例来源: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: jenkinsci/jenkins

if (mode!=-1)   dirZipEntry.setUnixMode(mode);
  dirZipEntry.setTime(f.lastModified());
  zip.putNextEntry(dirZipEntry);
  zip.closeEntry();
} else {
  if (mode!=-1)   fileZipEntry.setUnixMode(mode);
  fileZipEntry.setTime(f.lastModified());
  zip.putNextEntry(fileZipEntry);
  try (InputStream in = Files.newInputStream(f.toPath())) {
    int len;

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

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

zOut.putNextEntry(ze);

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

zOut.putNextEntry(ze);

代码示例来源: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: 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: 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: 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.tianjing/tgtools.core

/**
 * @param p_EntryName
 * @throws APPErrorException
 */
private void addZipEntry(String p_EntryName) throws APPErrorException {
  ZipEntry zipEntry = new ZipEntry(p_EntryName);
  try {
    m_ZipOutputStream.putNextEntry(zipEntry);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
  public void putNextEntry(ZipEntry ze) throws IOException {
    ze.setTime(dirTime+1999);   // roundup
    super.putNextEntry(ze);
  }
}) {

代码示例来源:origin: com.github.tianjing/tgtools.core

private static void writeRecursive(ZipOutputStream zos,
    BufferedOutputStream bo,String p_FileName,byte[] p_FileData)
    throws IOException, FileNotFoundException {
  ZipEntry zipEntry = new ZipEntry(p_FileName);
  zos.putNextEntry(zipEntry);
  bo.write(p_FileData);
  bo.flush();
}
/**

代码示例来源: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.apache.hive/hive-common

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: 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: hudson/hudson-2.x

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: hyperic/hq

private void addFile (org.apache.tools.zip.ZipEntry entry,
             ZipOutputStream zip_out,
             InputStream in,
             long size,
             byte[] buf) throws IOException {

    entry.setTime(System.currentTimeMillis());
    entry.setSize(size);
    zip_out.putNextEntry(entry);
    FileUtil.copyStream(in, zip_out, buf);
    zip_out.closeEntry();
  }
}

代码示例来源: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: org.gradle/gradle-core

private void visitFile(FileCopyDetails fileDetails) {
  try {
    ZipEntry archiveEntry = new ZipEntry(fileDetails.getRelativePath().getPathString());
    archiveEntry.setTime(getArchiveTimeFor(fileDetails));
    archiveEntry.setUnixMode(UnixStat.FILE_FLAG | fileDetails.getMode());
    zipOutStr.putNextEntry(archiveEntry);
    fileDetails.copyTo(zipOutStr);
    zipOutStr.closeEntry();
  } catch (Exception e) {
    throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile), e);
  }
}

相关文章