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); } }
int len; while((len=in.read(buf))>=0) zip.write(buf,0,len); } catch (InvalidPathException e) { throw new IOException(e);
do { if (count != 0) { zOut.write(buffer, 0, count);
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(); }
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(); } }
/** * 通过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(); } }
int readLen = -1; while ((readLen = is.read(buf, 0, 1024)) != -1) { zipStream.write(buf, 0, readLen);
/** * 下载多个文件到本地压缩包 * * @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(); } }
/** * 下载多个文件到本地压缩包 * * @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(); } }
FileInputStream fileIn = new FileInputStream(file); while ((readedBytes = fileIn.read(buf)) > 0) { zipOut.write(buf, 0, readedBytes);
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); } } }
int len; while ((len = in.read(buf)) >= 0) zipOutput.write(buf, 0, len); in.close();
FileInputStream fileIn = new FileInputStream(srcFile); while ((readedBytes = fileIn.read(buf)) > 0) { zipOut.write(buf, 0, readedBytes);
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++; }
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++; }
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++; }
int readLen = -1; while ((readLen = is.read(buf, 0, 1024)) != -1) { zipStream.write(buf, 0, readLen);
int len; while((len=in.read(buf))>=0) zip.write(buf,0,len); } catch (InvalidPathException e) { throw new IOException(e);
@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++; }
int readLen = -1; while ((readLen = is.read(buf, 0, 1024)) != -1) { zipStream.write(buf, 0, readLen);