gpt4 book ai didi

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

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

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

ZipEntry.<init>介绍

暂无

代码示例

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

ZipEntry dirZipEntry = new ZipEntry(relativePath+'/');
  zip.closeEntry();
} else {
  ZipEntry fileZipEntry = new ZipEntry(relativePath);
  if (mode!=-1)   fileZipEntry.setUnixMode(mode);
  fileZipEntry.setTime(f.lastModified());

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

ZipEntry e = new ZipEntry(relativePath.replace('\\', '/'));
VirtualFile f = dir.child(n);
e.setTime(f.lastModified());

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

final ZipEntry ze = new ZipEntry(vPath);
ze.setTime(fixedModTime != null ? modTimeMillis : lastModified);
ze.setMethod(doCompress ? ZipEntry.DEFLATED : ZipEntry.STORED);

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

final ZipEntry ze = new ZipEntry(vPath);

代码示例来源: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: 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: com.bbossgroups.pdp/pdp-system

private static void jar(ZipOutputStream out, File f, String base)
    throws Exception {
  if (f.isDirectory()) {
    File[] fl = f.listFiles();
    base = base.length() == 0 ? "" : base + "/"; // 注意,这里用左斜杠
    out.putNextEntry(new ZipEntry(base));
    for (int i = 0; i < fl.length; i++) {
      jar(out, fl[i], base + fl[i].getName());
    }
  } else {
    out.putNextEntry(new ZipEntry(base));
    FileInputStream in = new FileInputStream(f);
    byte[] buffer = new byte[1024];
    int n = in.read(buffer);
    while (n != -1) {
      out.write(buffer, 0, n);
      n = in.read(buffer);
    }
    in.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: 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.jvnet.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.tianjing/tgtools.core

private void addZipEntry(InputStream p_InputStream, String p_EntryName) throws APPErrorException {
  try {
    BufferedInputStream bi = new BufferedInputStream(p_InputStream);
    // 开始写入新的ZIP文件条目并将流定位到条目数据的开始处
    ZipEntry zipEntry = new ZipEntry(p_EntryName);
    m_ZipOutputStream.putNextEntry(zipEntry);
    byte[] buffer = new byte[1024];
    int readCount = bi.read(buffer);
    while (readCount != -1) {
      m_ZipOutputStream.write(buffer, 0, readCount);
      readCount = bi.read(buffer);
    }
    // 注,在使用缓冲流写压缩文件时,一个条件完后一定要刷新一把,不
    // 然可能有的内容就会存入到后面条目中去了
    m_ZipOutputStream.flush();
  } catch (Exception ex) {
    throw new APPErrorException("压缩文件出错。文件名称:" + p_EntryName + ";原因:" + ex.getMessage(), ex);
  } finally {
    try {
      p_InputStream.close();
    } catch (IOException e) {
      LogHelper.error("", "输入流关闭错误", "ZipPackager.addFile", e);
    }
  }
}

代码示例来源: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);
  }
}

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