本文整理汇总了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();
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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
}
}
示例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();
}
示例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();
}
示例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();
}
}
示例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");
}
示例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();
}
示例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;
}
示例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();
}