當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipOutputStream.write方法代碼示例

本文整理匯總了Java中java.util.zip.ZipOutputStream.write方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipOutputStream.write方法的具體用法?Java ZipOutputStream.write怎麽用?Java ZipOutputStream.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.zip.ZipOutputStream的用法示例。


在下文中一共展示了ZipOutputStream.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compressFile

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
private static void compressFile(String currentDir, ZipOutputStream zout, File[] files) throws Exception {
    byte[] buffer = new byte[1024];
    for (File fi : files) {
        if (fi.isDirectory()) {
            compressFile(currentDir + "/" + fi.getName(), zout, fi.listFiles());
            continue;
        }
        ZipEntry ze = new ZipEntry(currentDir + "/" + fi.getName());
        FileInputStream fin = new FileInputStream(fi.getPath());
        zout.putNextEntry(ze);
        int length;
        while ((length = fin.read(buffer)) > 0) {
            zout.write(buffer, 0, length);
        }
        zout.closeEntry();
        fin.close();
    }
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:19,代碼來源:FileUtils.java

示例2: 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

示例3: addManifest

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
private void addManifest(ByteArrayOutputStream manifest, ZipOutputStream zipout) throws IOException {

		if (manifest.size() > 0) {
			zipout.putNextEntry(new ZipEntry(MANIFEST_FILE_NAME));
			byte[] manifestBytes = manifest.toByteArray();
			if (images != null && images.size() > 0) {
				StringBuilder manifestBuilder = new StringBuilder(new String(manifestBytes, UTF8));
				for (Map.Entry<String, Image> img : images.entrySet()) {
					int p = manifestBuilder.indexOf(MANIFEST_END_TAG);
					StringBuilder sb = new StringBuilder(MANIFEST_ENTRY_1);
					sb.append(img.getValue().getFormat().toString().toLowerCase());
					sb.append(MANIFEST_ENTRY_2).append(img.getKey()).append(MANIFEST_ENTRY_3);
					manifestBuilder.insert(p, sb.toString());
				}
				manifestBytes = manifestBuilder.toString().getBytes(UTF8);
			}
			zipout.write(manifestBytes);
		}
	}
 
開發者ID:dvbern,項目名稱:doctemplate,代碼行數:20,代碼來源:ODTMergeEngine.java

示例4: zipIt

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
/**
 * Zip it
 */
public void zipIt(){
    byte[] buffer = new byte[1024];
    try{
        FileOutputStream fos = new FileOutputStream(OUTPUT_ZIP_FILE);
        ZipOutputStream zos = new ZipOutputStream(fos);
        //System.out.println("Output to Zip : " + zipFile);
        for(String file : this.fileList){
            //System.out.println("File Added : " + file);
            ZipEntry ze= new ZipEntry(file);
            zos.putNextEntry(ze);
            FileInputStream in = new FileInputStream(SOURCE_FOLDER.getAbsolutePath() + File.separator + file);
            int len;
            while ((len = in.read(buffer)) > 0) {
                zos.write(buffer, 0, len);
            }
            in.close();
       }
       zos.closeEntry();
       zos.close();
       //System.out.println("Done");
    } catch (IOException ex) {
        ex.printStackTrace();   
    }
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:28,代碼來源:JAppZip.java

示例5: compress

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
/**
 *
 * @param map key壓縮條目路徑 value重命名
 * @param zipPath 壓縮文件路徑
 * @return
 * @throws IOException
 */
public static boolean compress(Map<String, String> map, String zipPath) throws IOException {
    ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipPath));
    for (Map.Entry<String, String> entry : map.entrySet()) {
        File file = new File(entry.getKey());
        if (file.exists()) {
            InputStream inputStream = new FileInputStream(file);
            ZipEntry zipEntry = new ZipEntry(entry.getValue());
            zipOutputStream.putNextEntry(zipEntry);
            int len = inputStream.read();
            while (len != -1) {
                zipOutputStream.write(len);
                len = inputStream.read();
            }
            inputStream.close();
        }
    }
    zipOutputStream.close();
    return true;
}
 
開發者ID:Topview-us,項目名稱:school-website,代碼行數:27,代碼來源:OperateFileUtils.java

示例6: compressFile

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
private void compressFile(String currentDir, ZipOutputStream zout, File[] files) throws Exception {
    byte[] buffer = new byte[1024];
    for (File fi : files) {
        if (fi.isDirectory()) {
            compressFile(currentDir + "/" + fi.getName(), zout, fi.listFiles());
            continue;
        }
        publishProgress(fi.getName());
        publishProgress("+0");
        ZipEntry ze = new ZipEntry(currentDir + "/" + fi.getName());
        FileInputStream fin = new FileInputStream(fi.getPath());
        zout.putNextEntry(ze);
        int length;
        long readData=0;
        final long totalFileLength=fi.length();
        while ((length = fin.read(buffer)) > 0) {
            zout.write(buffer, 0, length);
             readData+=length;
            doProgress(totalFileLength,readData);
        }
        zout.closeEntry();
        fin.close();
    }
}
 
開發者ID:mosamabinomar,項目名稱:RootPGPExplorer,代碼行數:25,代碼來源:CompressTask.java

示例7: addToArchive

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
/**
 * @param inputDir Input Directory
 * @param zos      Zip Output Stream
 * @throws IOException
 */
private static void addToArchive(File inputDir, ZipOutputStream zos) throws IOException {
    File[] fileList = FileUtil.getFileListFromDirectory(inputDir.getPath());
    byte[] buffer = new byte[BUFFER_SIZE];

    for (File element : fileList) {

        if (element.isDirectory()) {
            zos.putNextEntry(new ZipEntry(element.getName()));
            addToArchive(element, zos);
            continue;
        }

        try (FileInputStream fis = new FileInputStream(element.getPath())) {
            log.info("Adding: " + element.getPath() + " to log bundle");
            zos.putNextEntry(new ZipEntry(element.getPath()));
            int len;
            while ((len = fis.read(buffer)) > 0) {
                zos.write(buffer, 0, len);
            }
            zos.closeEntry();
        }
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:29,代碼來源:ArchiveUtil.java

示例8: 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

示例9: extract

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo, String extractedFilePrefix) throws IOException, FileNotFoundException {
    Throwable th;
    InputStream in = apk.getInputStream(dexFile);
    File tmp = File.createTempFile(extractedFilePrefix, EXTRACTED_SUFFIX, extractTo.getParentFile());
    Log.i(TAG, "Extracting " + tmp.getPath());
    try {
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmp)));
        try {
            ZipEntry classesDex = new ZipEntry("classes.dex");
            classesDex.setTime(dexFile.getTime());
            out.putNextEntry(classesDex);
            byte[] buffer = new byte[16384];
            for (int length = in.read(buffer); length != -1; length = in.read(buffer)) {
                out.write(buffer, 0, length);
            }
            out.closeEntry();
            out.close();
            Log.i(TAG, "Renaming to " + extractTo.getPath());
            if (tmp.renameTo(extractTo)) {
                closeQuietly(in);
                tmp.delete();
                return;
            }
            throw new IOException("Failed to rename \"" + tmp.getAbsolutePath() + "\" to \"" + extractTo.getAbsolutePath() + "\"");
        } catch (Throwable th2) {
            th = th2;
            ZipOutputStream zipOutputStream = out;
            closeQuietly(in);
            tmp.delete();
            throw th;
        }
    } catch (Throwable th3) {
        th = th3;
        closeQuietly(in);
        tmp.delete();
        throw th;
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:39,代碼來源:MultiDexExtractor.java

示例10: addEntry

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
public static void addEntry(ZipOutputStream os, String path, byte[] content) throws IOException {
    ZipEntry entry = new ZipEntry(path);
    entry.setSize(content.length);
    os.putNextEntry(entry);
    os.write(content);
    os.closeEntry();
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:8,代碼來源:IntegrationHandler.java

示例11: addEntry

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
private void addEntry(ZipOutputStream zos, String theClasspathPrefix, String theFileName) throws IOException {
    ourLog.info("Adding {} to test zip", theFileName);
    zos.putNextEntry(new ZipEntry("SnomedCT_Release_INT_20160131_Full/Terminology/" + theFileName));
    byte[] byteArray = IOUtils.toByteArray(getClass().getResourceAsStream(theClasspathPrefix + theFileName));
    Validate.notNull(byteArray);
    zos.write(byteArray);
    zos.closeEntry();
}
 
開發者ID:nhsconnect,項目名稱:careconnect-reference-implementation,代碼行數:9,代碼來源:TerminologyLoaderTestIT.java

示例12: encodeResponse

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
public static byte[] encodeResponse(Response response) {
    long sequence = response.getSequence();
    int resultCode = response.getResultCode();
    String dataJson = response.getData() == null ? "" : response.getData().toJSONString();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ZipOutputStream zipOutputStream = new ZipOutputStream(bos);

    try {
        zipOutputStream.putNextEntry(new ZipEntry("sequence"));
        zipOutputStream.write(Bytes.longToBytes(sequence));
        zipOutputStream.closeEntry();

        zipOutputStream.putNextEntry(new ZipEntry("resultCode"));
        zipOutputStream.write(Bytes.int2Bytes(resultCode));
        zipOutputStream.closeEntry();

        zipOutputStream.putNextEntry(new ZipEntry("data"));
        zipOutputStream.write(dataJson.getBytes("UTF-8"));
        zipOutputStream.closeEntry();

    } catch (IOException e) {
        throw new ServerException("Error encoding response", e);
    }

    return Base64.getEncoder().encode(bos.toByteArray());
}
 
開發者ID:yiding-he,項目名稱:java-nio-test,代碼行數:28,代碼來源:ByteBufferEncoder.java

示例13: shouldCreateValidZipContent

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
@Test
public void shouldCreateValidZipContent() throws Exception {

    byte[] f1 = newRandomBytes(10000);
    byte[] f2 = newRandomBytes(10000);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ZipOutputStream zipOutputStream = new ZipOutputStream(bos);
    zipOutputStream.putNextEntry(new UtcAdjustedZipEntry("a/b/c"));
    zipOutputStream.write(f1);
    zipOutputStream.closeEntry();
    zipOutputStream.putNextEntry(new UtcAdjustedZipEntry("a/b/c/d/"));
    zipOutputStream.closeEntry();
    zipOutputStream.putNextEntry(new UtcAdjustedZipEntry("d/e/f"));
    zipOutputStream.write(f2);
    zipOutputStream.closeEntry();
    zipOutputStream.flush();
    zipOutputStream.close();
    byte[] expected = bos.toByteArray();

    List<DynamicZipInputStream.Entry> entries = new ArrayList<DynamicZipInputStream.Entry>();
    entries.add(newEntry("a/b/c", f1));
    entries.add(newEntry("a/b/c/d/", null));
    entries.add(newEntry("d/e/f", f2));
    DynamicZipInputStream inputStream = new DynamicZipInputStream(entries);
    bos.reset();
    FileCopyUtils.copy(inputStream, bos);
    byte[] actual = bos.toByteArray();

    assertThat(actual, is(equalTo(expected)));
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:32,代碼來源:DynamicZipInputStreamTest.java

示例14: extract

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo, String extractedFilePrefix) throws IOException, FileNotFoundException {
    Throwable th;
    InputStream in = apk.getInputStream(dexFile);
    File tmp = File.createTempFile(extractedFilePrefix, EXTRACTED_SUFFIX, extractTo.getParentFile());
    Log.i(TAG, "Extracting " + tmp.getPath());
    try {
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmp)));
        try {
            ZipEntry classesDex = new ZipEntry("classes.dex");
            classesDex.setTime(dexFile.getTime());
            out.putNextEntry(classesDex);
            byte[] buffer = new byte[16384];
            for (int length = in.read(buffer); length != -1; length = in.read(buffer)) {
                out.write(buffer, 0, length);
            }
            out.closeEntry();
            out.close();
            Log.i(TAG, "Renaming to " + extractTo.getPath());
            if (tmp.renameTo(extractTo)) {
                closeQuietly(in);
                tmp.delete();
                return;
            }
            throw new IOException("Failed to rename \"" + tmp.getAbsolutePath() + "\" to \"" + extractTo.getAbsolutePath() + a.e);
        } catch (Throwable th2) {
            th = th2;
            ZipOutputStream zipOutputStream = out;
            closeQuietly(in);
            tmp.delete();
            throw th;
        }
    } catch (Throwable th3) {
        th = th3;
        closeQuietly(in);
        tmp.delete();
        throw th;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:39,代碼來源:MultiDexExtractor.java

示例15: writeZipStream

import java.util.zip.ZipOutputStream; //導入方法依賴的package包/類
private void writeZipStream(final ZipOutputStream stream, final String log) {
    if (stream == null) {
        return;
    }

    // write to zip output stream
    try {
        stream.write(log.getBytes());
        stream.write(Unix.LINE_SEPARATOR.getBytes());
    } catch (IOException e) {
        LOGGER.warn("Log cannot write : " + log);
    }
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:14,代碼來源:LogEventHandler.java


注:本文中的java.util.zip.ZipOutputStream.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。