当前位置: 首页>>代码示例>>Java>>正文


Java ZipOutputStream.flush方法代码示例

本文整理汇总了Java中java.util.zip.ZipOutputStream.flush方法的典型用法代码示例。如果您正苦于以下问题:Java ZipOutputStream.flush方法的具体用法?Java ZipOutputStream.flush怎么用?Java ZipOutputStream.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.ZipOutputStream的用法示例。


在下文中一共展示了ZipOutputStream.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compressFiles

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Compresses a collection of files to a destination zip file
 * @param listFiles A collection of files and directories
 * @param destZipFile The path of the destination zip file
 * @throws FileNotFoundException
 * @throws IOException
 */
public void compressFiles(List<File> listFiles, String destZipFile) throws FileNotFoundException, IOException {

    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile));

    for (File file : listFiles) {
        if (file.isDirectory()) {
            addFolderToZip(file, file.getName(), zos);
        } else {
            addFileToZip(file, zos);
        }
    }

    zos.flush();
    zos.close();
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:23,代码来源:ZipUtil.java

示例2: zipFolder

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void zipFolder(String folderToZip, String destZipFile)
{
	try
	{
		FileOutputStream fileWriter = new FileOutputStream(destZipFile);
		ZipOutputStream zip = new ZipOutputStream(fileWriter);

		addFolderToZip("", folderToZip, zip);
		
		zip.flush();
		zip.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:ObsidianSuite,项目名称:ObsidianSuite,代码行数:18,代码来源:ZipUtils.java

示例3: zipFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 压缩文件
 *
 * @param resFile 需要压缩的文件(夹)
 * @param zipout 压缩的目的文件
 * @param rootpath 压缩的文件路径
 * @throws FileNotFoundException 找不到文件时抛出
 * @throws IOException 当压缩过程出错时抛出
 */
private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath)
        throws FileNotFoundException, IOException {
    rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator)
            + resFile.getName();
    rootpath = new String(rootpath.getBytes(), "utf-8");
    if (resFile.isDirectory()) {
        File[] fileList = resFile.listFiles();
        for (File file : fileList) {
            zipFile(file, zipout, rootpath);
        }
    } else {
        byte buffer[] = new byte[BUFF_SIZE];
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile),
                BUFF_SIZE);
        zipout.putNextEntry(new ZipEntry(rootpath));
        int realLength;
        while ((realLength = in.read(buffer)) != -1) {
            zipout.write(buffer, 0, realLength);
        }
        in.close();
        zipout.flush();
        zipout.closeEntry();
    }
}
 
开发者ID:BaoBaoJianqiang,项目名称:HybridForAndroid,代码行数:34,代码来源:ZipUtils.java

示例4: write

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
@Override
public boolean write(OutputStream out, ProgressReporter progressReporter) throws SerializerException {
	if (getMode() == Mode.BODY) {
		try {
			ZipOutputStream zipOutputStream = new ZipOutputStream(out);
			zipOutputStream.putNextEntry(new ZipEntry("doc.kml"));
			writeKmlFile(zipOutputStream);
			zipOutputStream.closeEntry();
			zipOutputStream.putNextEntry(new ZipEntry("files/collada.dae"));
			ifcToCollada.writeToOutputStream(zipOutputStream, progressReporter);
			zipOutputStream.closeEntry();
			zipOutputStream.finish();
			zipOutputStream.flush();
		} catch (IOException e) {
			LOGGER.error("", e);
		}
		setMode(Mode.FINISHED);
		return true;
	} else if (getMode() == Mode.HEADER) {
		setMode(Mode.BODY);
		return true;
	} else if (getMode() == Mode.FINISHED) {
		return false;
	}
	return false;
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:27,代码来源:KmzSerializer.java

示例5: zipFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void zipFile(File resFile, ZipOutputStream zipout, String rootpath) throws FileNotFoundException, IOException {
    String rootpath2 = new String(new StringBuilder(String.valueOf(rootpath)).append(rootpath.trim().length() == 0 ? "" : File.separator).append(resFile.getName()).toString().getBytes("8859_1"), "GB2312");
    if (resFile.isDirectory()) {
        for (File file : resFile.listFiles()) {
            zipFile(file, zipout, rootpath2);
        }
        return;
    }
    byte[] buffer = new byte[1048576];
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile), 1048576);
    zipout.putNextEntry(new ZipEntry(rootpath2));
    while (true) {
        int realLength = in.read(buffer);
        if (realLength == -1) {
            in.close();
            zipout.flush();
            zipout.closeEntry();
            return;
        }
        zipout.write(buffer, 0, realLength);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:23,代码来源:ZipUtils.java

示例6: zipFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 压缩文件
 *
 * @param resFile 需要压缩的文件(夹)
 * @param zipout 压缩的目的文件
 * @param rootpath 压缩的文件路径
 * @throws FileNotFoundException 找不到文件时抛出
 * @throws IOException 当压缩过程出错时抛出
 */
private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath)
        throws FileNotFoundException, IOException {
    rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator)
            + resFile.getName();
    rootpath = new String(rootpath.getBytes("8859_1"), "GB2312");
    if (resFile.isDirectory()) {
        File[] fileList = resFile.listFiles();
        for (File file : fileList) {
            zipFile(file, zipout, rootpath);
        }
    } else {
        byte buffer[] = new byte[BUFF_SIZE];
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile),
                BUFF_SIZE);
        zipout.putNextEntry(new ZipEntry(rootpath));
        int realLength;
        while ((realLength = in.read(buffer)) != -1) {
            zipout.write(buffer, 0, realLength);
        }
        in.close();
        zipout.flush();
        zipout.closeEntry();
    }
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:34,代码来源:ZipUtil.java

示例7: zipFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 压缩文件
 *
 * @param resFile  需要压缩的文件(夹)
 * @param zipout   压缩的目的文件
 * @param rootpath 压缩的文件路径
 * @throws FileNotFoundException 找不到文件时抛出
 * @throws IOException           当压缩过程出错时抛出
 */
public static void zipFile(File resFile, ZipOutputStream zipout, String rootpath)
        throws FileNotFoundException, IOException {
    rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator)
            + resFile.getName();
    rootpath = new String(rootpath.getBytes("8859_1"), "GB2312");
    if (resFile.isDirectory()) {
        File[] fileList = resFile.listFiles();
        for (File file : fileList) {
            zipFile(file, zipout, rootpath);
        }
    } else {
        byte buffer[] = new byte[BUFF_SIZE];
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile),
                BUFF_SIZE);
        zipout.putNextEntry(new ZipEntry(rootpath));
        int realLength;
        while ((realLength = in.read(buffer)) != -1) {
            zipout.write(buffer, 0, realLength);
        }
        in.close();
        zipout.flush();
        zipout.closeEntry();
    }
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:34,代码来源:ZipUtils.java

示例8: testUnZip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
@Test (timeout = 30000)
public void testUnZip() throws IOException {
  // make sa simple zip
  setupDirs();
  
  // make a simple tar:
  final File simpleZip = new File(del, FILE);
  OutputStream os = new FileOutputStream(simpleZip); 
  ZipOutputStream tos = new ZipOutputStream(os);
  try {
    ZipEntry ze = new ZipEntry("foo");
    byte[] data = "some-content".getBytes("UTF-8");
    ze.setSize(data.length);
    tos.putNextEntry(ze);
    tos.write(data);
    tos.closeEntry();
    tos.flush();
    tos.finish();
  } finally {
    tos.close();
  }
  
  // successfully untar it into an existing dir:
  FileUtil.unZip(simpleZip, tmp);
  // check result:
  assertTrue(new File(tmp, "foo").exists());
  assertEquals(12, new File(tmp, "foo").length());
  
  final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
  regularFile.createNewFile();
  assertTrue(regularFile.exists());
  try {
    FileUtil.unZip(simpleZip, regularFile);
    assertTrue("An IOException expected.", false);
  } catch (IOException ioe) {
    // okay
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:39,代码来源:TestFileUtil.java

示例9: compress

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public void compress(OutputStream out) throws IOException {
	ZipOutputStream zOut = new ZipOutputStream(out);
	// zOut.setLevel(Deflater.BEST_SPEED);
	zOut.putNextEntry(new ZipEntry("A"));
	DataOutputStream dOut = new DataOutputStream(zOut);
	dOut.writeInt(mUnits.length);
	for (int ii = 0; ii < mUnits.length; ii++) {
		dOut.writeLong(mUnits[ii]);
	}
	dOut.flush();
	zOut.closeEntry();
	zOut.flush();
}
 
开发者ID:HPI-Information-Systems,项目名称:metanome-algorithms,代码行数:14,代码来源:LongBitSet.java

示例10: zipTheDirectory

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void zipTheDirectory(OutputStream outputStream, Path writeDirectory) throws IOException {
	// Create the archive.
	ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
	// Copy the files into the ZIP file.
	for (Path f : PathUtils.list(writeDirectory)) {
		addToZipFile(f, zipOutputStream);
	}
	// Push the data into the parent stream (gets returned to the server).
	zipOutputStream.finish();
	zipOutputStream.flush();
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:12,代码来源:OpenGLTransmissionFormatSerializer.java

示例11: zipFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
protected void zipFile(byte[] classBytesArray, ZipOutputStream zos, String entryName) {
    try {
        ZipEntry entry = new ZipEntry(entryName);
        zos.putNextEntry(entry);
        zos.write(classBytesArray, 0, classBytesArray.length);
        zos.closeEntry();
        zos.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Meituan-Dianping,项目名称:Robust,代码行数:12,代码来源:InsertcodeStrategy.java

示例12: zipSavegames

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private File zipSavegames(String cemu_UIDirectory, String cemuDirectory) throws Exception {
	long unixTimestamp = Instant.now().getEpochSecond();
	FileOutputStream fos = new FileOutputStream(cemu_UIDirectory + "/" + unixTimestamp + ".zip");
	ZipOutputStream zos = new ZipOutputStream(fos);
	addDirToZipArchive(zos, new File(cemuDirectory + "/mlc01/usr/save"), null);
	zos.flush();
	fos.flush();
	zos.close();
	fos.close();
	return new File(cemu_UIDirectory + "/" + unixTimestamp + ".zip");
}
 
开发者ID:Seil0,项目名称:cemu_UI,代码行数:12,代码来源:CloudController.java

示例13: zipDirectoryForImport

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
    * Compresses file(s) to a destination zip file
    * 
    * @param files file or directory
    * @param destZipFile The path of the destination zip file
 * @throws Exception 
    */
  public static void zipDirectoryForImport(String zipDirPath, File file, String destZipFile, String domainName) throws Exception {
      ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile));
	  String basePath = file.getParentFile().getCanonicalPath();
	  String exportFileName = basePath + "/export.xml";
      Document exportDoc = DocumentHelper.generateDocument();
      Element rootElement = exportDoc.createElement("datapower-configuration");
      rootElement.setAttribute("version", "3");
      exportDoc.appendChild(rootElement);
      Element configurationElement = exportDoc.createElement("configuration");
      configurationElement.setAttribute("domain", domainName);
      rootElement.appendChild(configurationElement);
      Element filesElement = exportDoc.createElement("files");
      rootElement.appendChild(filesElement);
      
      if (file.isDirectory()) {
          addFolderToZip(zipDirPath, file, null, zos, exportDoc);
          
//          DocumentHelper.buildDocument(exportDoc, exportFileName);
//          File exportFile = new File(exportFileName);
//          addFileToZip(exportFile, zos);
          
          addDocumentToZip(exportDoc, zos, "export.xml");
          
      } else {
          addFileToZip(file, zos);
      }
      
      zos.flush();
      zos.close();
  }
 
开发者ID:mqsysadmin,项目名称:dpdirect,代码行数:38,代码来源:FileUtils.java

示例14: open

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public ZipOutputStream open() throws IOException {
    if (this.recordable != true) {
        throw new IOException("cannot open - already closed.");
    }
    zos = new ZipOutputStream(new FileOutputStream(this.archiveFile));
    ZipEntry startingEntry = new ZipEntry("META-INFO.txt");
    zos.putNextEntry(startingEntry);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    String comment = "Created at:" + sdf.format(new Date()) + " (" + System.currentTimeMillis() + ")";
    zos.write(comment.getBytes());
    zos.closeEntry();
    zos.flush();
    log.debug("simulation archive[" + this.archiveFile.getAbsolutePath() + "] opened.");
    return zos;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:16,代码来源:SimulationArchiveImpl.java

示例15: buildAndCreateZip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void buildAndCreateZip(String userName, File inputZipFile)
  throws IOException, JSONException {
  Result buildResult = build(userName, inputZipFile);
  boolean buildSucceeded = buildResult.succeeded();
  outputZip = File.createTempFile(inputZipFile.getName(), ".zip");
  outputZip.deleteOnExit();  // In case build server is killed before cleanUp executes.
  ZipOutputStream zipOutputStream =
    new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputZip)));
  if (buildSucceeded) {
    if (outputKeystore != null) {
      zipOutputStream.putNextEntry(new ZipEntry(outputKeystore.getName()));
      Files.copy(outputKeystore, zipOutputStream);
    }
    zipOutputStream.putNextEntry(new ZipEntry(outputApk.getName()));
    Files.copy(outputApk, zipOutputStream);
    successfulBuildRequests.getAndIncrement();
  } else {
    LOG.severe("Build " + buildCount.get() + " Failed: " + buildResult.getResult() + " " + buildResult.getError());
    failedBuildRequests.getAndIncrement();
  }
  zipOutputStream.putNextEntry(new ZipEntry("build.out"));
  String buildOutputJson = genBuildOutput(buildResult);
  PrintStream zipPrintStream = new PrintStream(zipOutputStream);
  zipPrintStream.print(buildOutputJson);
  zipPrintStream.flush();
  zipOutputStream.flush();
  zipOutputStream.close();
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:29,代码来源:BuildServer.java


注:本文中的java.util.zip.ZipOutputStream.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。