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

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

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

ZipOutputStream.write介绍

[英]Writes bytes to ZIP entry.
[中]将字节写入ZIP条目。

代码示例

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

private void preClose() throws IOException {
  if (finished) {
    throw new IOException("Stream has already been finished");
  }
  if (entry == null) {
    throw new IOException("No current entry to close");
  }
  if (!entry.hasWritten) {
    write(EMPTY, 0, 0);
  }
}

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

int len;
  while((len=in.read(buf))>=0)
    zip.write(buf,0,len);
} catch (InvalidPathException e) {
  throw new IOException(e);

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

do {
  if (count != 0) {
    zOut.write(buffer, 0, count);

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

/**
 * 通过HTTP下载多个文件到客户机
 * 
 * @param response
 * @param zipName
 * @param pathnames
 * @throws IOException
 */
public void downloadFiles(HttpServletResponse response, String zipName, String... pathnames) throws IOException {
  response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(zipName, UTF_8));
  byte[] buf = new byte[1024];
  try {
    ZipOutputStream zipStream = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
    for (String pathname : pathnames) {
      ZipEntry entry = new ZipEntry(pathname.substring(pathname.lastIndexOf("/") + 1));
      zipStream.putNextEntry(entry);
      InputStream is = ftp.retrieveFileStream(pathname);
      if (is != null) {
        int readLen = -1;
        while ((readLen = is.read(buf, 0, 1024)) != -1) {
          zipStream.write(buf, 0, readLen);
        }
        is.close();
      }
    }
    zipStream.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: GaoFeiGit/xutils

int readLen = -1;
while ((readLen = is.read(buf, 0, 1024)) != -1) {
  zipStream.write(buf, 0, readLen);

代码示例来源:origin: GaoFeiGit/xutils

/**
 * 下载多个文件到本地压缩包
 * 
 * @param localZipPathName
 * @param pathnames
 * @throws IOException
 */
public void downloadFiles(String localZipPathName, String... pathnames) throws IOException {
  byte[] buf = new byte[1024];
  FileOutputStream fos = new FileOutputStream(localZipPathName);
  try {
    ZipOutputStream zipStream = new ZipOutputStream(new BufferedOutputStream(fos));
    for (String pathname : pathnames) {
      ZipEntry entry = new ZipEntry(pathname.substring(pathname.lastIndexOf("/") + 1));
      zipStream.putNextEntry(entry);
      InputStream is = cs.get(pathname);
      if (is != null) {
        int readLen = -1;
        while ((readLen = is.read(buf, 0, 1024)) != -1) {
          zipStream.write(buf, 0, readLen);
        }
        is.close();
      }
    }
    zipStream.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: GaoFeiGit/xutils

/**
 * 下载多个文件到本地压缩包
 * 
 * @param localZipPathName
 * @param pathnames
 * @throws IOException
 */
public void downloadFiles(String localZipPathName, String... pathnames) throws IOException {
  byte[] buf = new byte[1024];
  FileOutputStream fos = new FileOutputStream(localZipPathName);
  try {
    ZipOutputStream zipStream = new ZipOutputStream(new BufferedOutputStream(fos));
    for (String pathname : pathnames) {
      ZipEntry entry = new ZipEntry(pathname.substring(pathname.lastIndexOf("/") + 1));
      zipStream.putNextEntry(entry);
      InputStream is = ftp.retrieveFileStream(pathname);
      if (is != null) {
        int readLen = -1;
        while ((readLen = is.read(buf, 0, 1024)) != -1) {
          zipStream.write(buf, 0, readLen);
        }
        is.close();
      }
    }
    zipStream.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}

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

FileInputStream fileIn = new FileInputStream(file);
while ((readedBytes = fileIn.read(buf)) > 0) {
  zipOut.write(buf, 0, readedBytes);

代码示例来源: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: com.github.javahaohao/utils

int len;
while ((len = in.read(buf)) >= 0)
  zipOutput.write(buf, 0, len);
in.close();

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

FileInputStream fileIn = new FileInputStream(srcFile);
while ((readedBytes = fileIn.read(buf)) > 0) {
  zipOut.write(buf, 0, readedBytes);

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

int readLen = -1;
while ((readLen = is.read(buf, 0, 1024)) != -1) {
  zipStream.write(buf, 0, readLen);

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

int len;
  while((len=in.read(buf))>=0)
    zip.write(buf,0,len);
} catch (InvalidPathException e) {
  throw new IOException(e);

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

@Override
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 = null;
    try {
      in = new FileInputStream(f);
      int len;
      while ((len = in.read(buf)) > 0) {
        zip.write(buf, 0, len);
      }
    } finally {
      IOUtils.closeQuietly(in);
    }
    zip.closeEntry();
  }
  entriesWritten++;
}

代码示例来源:origin: GaoFeiGit/xutils

int readLen = -1;
while ((readLen = is.read(buf, 0, 1024)) != -1) {
  zipStream.write(buf, 0, readLen);

相关文章