本文整理匯總了Java中java.util.zip.ZipOutputStream.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipOutputStream.flush方法的具體用法?Java ZipOutputStream.flush怎麽用?Java ZipOutputStream.flush使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.zip.ZipOutputStream的用法示例。
在下文中一共展示了ZipOutputStream.flush方法的19個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: compressFiles
點讚 4
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 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,
示例2: zipFolder
點讚 3
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,
示例3: zipFile
點讚 3
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,
示例4: write
點讚 3
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,
示例5: zipFile
點讚 3
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,
示例6: zipFile
點讚 3
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,
示例7: zipFile
點讚 3
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,
示例8: testUnZip
點讚 2
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,
示例9: compress
點讚 2
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,
示例10: zipTheDirectory
點讚 2
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,
示例11: zipFile
點讚 2
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,
示例12: zipSavegames
點讚 2
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,
示例13: zipDirectoryForImport
點讚 2
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,
示例14: open
點讚 2
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,
示例15: buildAndCreateZip
點讚 2
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,
示例16: compressDirectory
點讚 2
import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
/**
Compresses given directory recursively to given output stream
*/
public static void compressDirectory(File directory, OutputStream output) throws IOException {
logger.debug("Compressing directory {}", directory.getAbsolutePath());
ZipOutputStream zipOut = new ZipOutputStream(output);
LinkedList fileStack = new LinkedList<>();
fileStack.push(directory);
while (!fileStack.isEmpty()) {
File f = fileStack.pop();
if (f.isDirectory()) {
for (File file : f.listFiles()) {
fileStack.push(file);
}
} else {
FileInputStream in = new FileInputStream(f);
//Get the relative path
String relative = directory.toPath().relativize(f.toPath()).toString();
logger.trace("Compressing {}", relative);
//create the zip entry
ZipEntry entry = new ZipEntry(relative);
zipOut.putNextEntry(entry);
//Write the data
byte[] buffer = new byte[BUFFER_SIZE];
int read;
while ((read = in.read(buffer)) != -1) {
zipOut.write(buffer, 0, read);
}
//Close the zip entry
zipOut.closeEntry();
zipOut.flush();
//close the input stream
in.close();
}
}
//close zip output
zipOut.close();
logger.debug("Closing stream");
}
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:46,
示例17: execute0
點讚 2
import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
@Override
protected Object execute0() throws Exception {
X509CRL crl = X509Util.parseCrl(crlFile);
String oidExtnCerts = ObjectIdentifiers.id_xipki_ext_crlCertset.getId();
byte[] extnValue = crl.getExtensionValue(oidExtnCerts);
if (extnValue == null) {
throw new IllegalCmdParamException("no certificate is contained in " + crlFile);
}
extnValue = removingTagAndLenFromExtensionValue(extnValue);
ASN1Set asn1Set = DERSet.getInstance(extnValue);
final int n = asn1Set.size();
if (n == 0) {
throw new CmdFailure("no certificate is contained in " + crlFile);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(out);
for (int i = 0; i < n; i++) {
ASN1Encodable asn1 = asn1Set.getObjectAt(i);
Certificate cert;
try {
ASN1Sequence seq = ASN1Sequence.getInstance(asn1);
cert = Certificate.getInstance(seq.getObjectAt(0));
} catch (IllegalArgumentException ex) {
// backwards compatibility
cert = Certificate.getInstance(asn1);
}
byte[] certBytes = cert.getEncoded();
String sha1FpCert = HashAlgoType.SHA1.hexHash(certBytes);
ZipEntry certZipEntry = new ZipEntry(sha1FpCert + ".der");
zip.putNextEntry(certZipEntry);
try {
zip.write(certBytes);
} finally {
zip.closeEntry();
}
}
zip.flush();
zip.close();
saveVerbose("extracted " + n + " certificates to", new File(outFile), out.toByteArray());
return null;
}
開發者ID:xipki,項目名稱:xitk,代碼行數:48,
示例18: process
點讚 2
import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
public void process(File folderToZip, OutputStream output) throws Exception {
ZipOutputStream zip = new ZipOutputStream(output);
addFolderToZip("", folderToZip.getPath(), zip);
zip.flush();
}
開發者ID:vindell,項目名稱:docx4j-template,代碼行數:6,
示例19: run
點讚 2
import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
@Override
public void run() {
super.run();
try {
mZipListener.zipStart();
//獲得要壓縮文件夾下麵的文件List
File sourceFile = new File(mSourceDir);
if (!sourceFile.exists()) {
mZipListener.zipFail();
return;
}
File outPathFile = new File(mOutPath);
if (!outPathFile.exists()) {
outPathFile.mkdirs();
}
if (sourceFile.isDirectory()) {
File[] imgFiles = sourceFile.listFiles();
File zipFile = new File(mOutPath + File.separator + mZipName);
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(zipFile));
ZipOutputStream zipOutputStream = new ZipOutputStream(bos);
//表示處理進度
int index = 1;
int imgFilesSize = imgFiles.length;
for (File anImgFile : imgFiles) {
index++;
ZipEntry zipEntry = new ZipEntry(anImgFile.getName());
zipOutputStream.putNextEntry(zipEntry);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(anImgFile));
byte[] b = new byte[1024];
while (bis.read(b, 0, 1024) != -1) {
zipOutputStream.write(b, 0, 1024);
}
bis.close();
zipOutputStream.closeEntry();
mZipListener.zipProgress(index / imgFilesSize * 100);
}
zipOutputStream.flush();
zipOutputStream.close();
mZipListener.zipSuccess();
}
} catch (Exception e) {
mZipListener.zipFail();
}
}
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:49,
注:本文中的java.util.zip.ZipOutputStream.flush方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。