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


Java ZipOutputStream.putNextEntry方法代码示例

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


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

示例1: zipFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void zipFile(String filePath, String zipPath) throws Exception{
    byte[] buffer = new byte[1024];
    FileOutputStream fos = new FileOutputStream(zipPath);
    ZipOutputStream zos = new ZipOutputStream(fos);
    ZipEntry ze= new ZipEntry("spy.log");
    zos.putNextEntry(ze);
    FileInputStream in = new FileInputStream(filePath);
    int len;
    while ((len = in.read(buffer)) > 0) {
        zos.write(buffer, 0, len);
    }
    in.close();
    zos.closeEntry();
    //remember close it
    zos.close();
}
 
开发者ID:ZHENFENG13,项目名称:My-Blog,代码行数:17,代码来源:ZipUtils.java

示例2: copyToZipStream

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private static void copyToZipStream(File file, ZipEntry entry,
                            ZipOutputStream zos) throws IOException {
  InputStream is = new FileInputStream(file);
  try {
    zos.putNextEntry(entry);
    byte[] arr = new byte[4096];
    int read = is.read(arr);
    while (read > -1) {
      zos.write(arr, 0, read);
      read = is.read(arr);
    }
  } finally {
    try {
      is.close();
    } finally {
      zos.closeEntry();
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:JarFinder.java

示例3: addFileToZip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
static private void addFileToZip(String path, String srcFile, ZipOutputStream zip)
        throws Exception {
    File folder = new File(srcFile);
    if (folder.isDirectory()) {
        addFolderToZip(path, srcFile, zip);
    } else {

        byte[] buf = new byte[1024];
        int len;
        FileInputStream in = new FileInputStream(srcFile);
        zip.putNextEntry(new ZipEntry(path + "/" + folder.getName()));
        while ((len = in.read(buf)) > 0) {
            zip.write(buf, 0, len);
        }
        in.close();

    }
}
 
开发者ID:cybershrapnel,项目名称:nanocheeze,代码行数:19,代码来源:Torrent2.java

示例4: initZipLogFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void initZipLogFile(final Cmd cmd) throws IOException {
    // init log directory
    try {
        Files.createDirectories(DEFAULT_LOG_PATH);
    } catch (FileAlreadyExistsException ignore) {
        LOGGER.warn("Log path %s already exist", DEFAULT_LOG_PATH);
    }

    // init zipped log file for tmp
    Path stdoutPath = Paths.get(DEFAULT_LOG_PATH.toString(), getLogFileName(cmd, Log.Type.STDOUT, true));
    Files.deleteIfExists(stdoutPath);

    stdoutLogPath = Files.createFile(stdoutPath);

    // init zip stream for stdout log
    stdoutLogStream = new FileOutputStream(stdoutLogPath.toFile());
    stdoutLogZipStream = new ZipOutputStream(stdoutLogStream);
    ZipEntry outEntry = new ZipEntry(cmd.getId() + ".out");
    stdoutLogZipStream.putNextEntry(outEntry);
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:21,代码来源:LogEventHandler.java

示例5: saveResultsFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
@Override
public void saveResultsFile(Document doc, Element root, ZipOutputStream zos) throws IOException {
	int algo, numRes = clusterOperation.size();
	String algoName;

	for (int i = 0; i < numRes; i++) {
		algo = clusterOperation.get(i).getClusteringType();
		algoName = String.valueOf(clusterOperation.get(i).getName());
		algoName += "_" + i;
		zos.putNextEntry(new ZipEntry(algoName + JwatSession.BINext));
		switch (algo) {
			case JWATConstants.KMEANS:
				saveKmeansData(zos, (KMean) clusterOperation.get(i));
				break;
			case JWATConstants.FUZZYK:
				saveFuzzyData(zos, (FuzzyKMean) clusterOperation.get(i));
				break;
		}
		zos.closeEntry();
	}

}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:23,代码来源:WorkloadAnalysisSession.java

示例6: zipDirectoryInternal

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Private helper function for zipping files. This one goes recursively
 * through the input directory and all of its subdirectories and adds the
 * single zip entries.
 *
 * @param inputFile the file or directory to be added to the zip file
 * @param directoryName the string-representation of the parent directory
 *     name. Might be an empty name, or a name containing multiple directory
 *     names separated by "/". The directory name must be a valid name
 *     according to the file system limitations. The directory name should be
 *     empty or should end in "/".
 * @param zos the zipstream to write to
 * @throws IOException the zipping failed, e.g. because the output was not
 *     writeable.
 */
private static void zipDirectoryInternal(
    File inputFile,
    String directoryName,
    ZipOutputStream zos) throws IOException {
  String entryName = directoryName + inputFile.getName();
  if (inputFile.isDirectory()) {
    entryName += "/";

    // We are hitting a sub-directory. Recursively add children to zip in deterministic,
    // sorted order.
    File[] childFiles = inputFile.listFiles();
    if (childFiles.length > 0) {
      Arrays.sort(childFiles);
      // loop through the directory content, and zip the files
      for (File file : childFiles) {
        zipDirectoryInternal(file, entryName, zos);
      }

      // Since this directory has children, exit now without creating a zipentry specific to
      // this directory. The entry for a non-entry directory is incompatible with certain
      // implementations of unzip.
      return;
    }
  }

  // Put the zip-entry for this file or empty directory into the zipoutputstream.
  ZipEntry entry = new ZipEntry(entryName);
  entry.setTime(inputFile.lastModified());
  zos.putNextEntry(entry);

  // Copy file contents into zipoutput stream.
  if (inputFile.isFile()) {
    Files.asByteSource(inputFile).copyTo(zos);
  }
}
 
开发者ID:spotify,项目名称:hype,代码行数:51,代码来源:ZipFiles.java

示例7: copyUnknownFiles

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files)
        throws IOException {
    File unknownFileDir = new File(appDir, UNK_DIRNAME);

    // loop through unknown files
    for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) {
        File inputFile = new File(unknownFileDir, unknownFileInfo.getKey());
        if (inputFile.isDirectory()) {
            continue;
        }

        ZipEntry newEntry = new ZipEntry(unknownFileInfo.getKey());
        int method = Integer.parseInt(unknownFileInfo.getValue());
        LOGGER.fine(String.format("Copying unknown file %s with method %d", unknownFileInfo.getKey(), method));
        if (method == ZipEntry.STORED) {
            newEntry.setMethod(ZipEntry.STORED);
            newEntry.setSize(inputFile.length());
            newEntry.setCompressedSize(-1);
            BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
            CRC32 crc = BrutIO.calculateCrc(unknownFile);
            newEntry.setCrc(crc.getValue());
        } else {
            newEntry.setMethod(ZipEntry.DEFLATED);
        }
        outputFile.putNextEntry(newEntry);

        BrutIO.copy(inputFile, outputFile);
        outputFile.closeEntry();
    }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:31,代码来源:Androlib.java

示例8: zip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void zip(File directory, File zipfile) throws IOException
{
    URI base = directory.toURI();
    Deque<File> queue = new LinkedList<File>();
    queue.push(directory);
    OutputStream out = new FileOutputStream(zipfile);
    Closeable res = null;
    try
    {
        ZipOutputStream zout = new ZipOutputStream(out);
        res = zout;
        while (!queue.isEmpty())
        {
            directory = queue.pop();
            for (File kid : directory.listFiles())
            {
                String name = base.relativize(kid.toURI()).getPath();
                if (kid.isDirectory())
                {
                    queue.push(kid);
                    name = name.endsWith("/") ? name : name + "/";
                    zout.putNextEntry(new ZipEntry(name));
                } else
                {
                    zout.putNextEntry(new ZipEntry(name));
                    Files.copy(kid, zout);
                    zout.closeEntry();
                }
            }
        }
    } finally
    {
        res.close();
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:36,代码来源:ZipperUtil.java

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

示例10: saveMatrixData

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void saveMatrixData(Observation[] obs, VariableNumber[] var, ZipOutputStream zos) {
	//System.out.println("Saving matrix");
	try {
		int i, j;
		int size;

		size = obs[0].getSize();

		//save varaible mapping in a separate file
		for (j = 0; j < size; j++) {
			if (var[j].getType() == JWATConstants.STRING) {
				saveVarMapping(var[j], zos);
			}
		}
		//save data
		zos.putNextEntry(new ZipEntry(filename + BINext));
		DataOutputStream dos = new DataOutputStream(zos);
		for (i = 0; i < obs.length; i++) {
			dos.writeInt(obs[i].getID());
			for (j = 0; j < size; j++) {
				dos.writeDouble(obs[i].getIndex(j));
			}
		}
		dos.flush();
		zos.closeEntry();

		//System.out.println("Save done");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:32,代码来源:JwatSession.java

示例11: putEntry

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Put a file represented as a path into an open ZipOutputStream.
 * @param zos ZipOutputStream to write to.
 * @param path Path representing a file to be written to the zip.
 */
private static void putEntry(ZipOutputStream zos, Path path, String target) throws IOException {
  // Make a new zipentry with the files at the top-level directory (instead of nested).
  final ZipEntry zipEntry = new ZipEntry(Paths.get(target).relativize(path).toString());
  zos.putNextEntry(zipEntry);
  Files.copy(path, zos);
  zos.closeEntry();
}
 
开发者ID:tsiq,项目名称:magic-beanstalk,代码行数:13,代码来源:ZipUtil.java

示例12: compressFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static boolean compressFile(File toCompress, File target) {
    if (target == null || toCompress == null) {
        return false;
    }
    try {
        final Uri uri = Uri.fromFile(toCompress);
        final String rootPath = Utils.getParentUrl(uri.toString());
        final int rootOffset = rootPath.length();

        ZipOutputStream zos = new ZipOutputStream(FileEditorFactory.getFileEditorForUrl(Uri.fromFile(target), null).getOutputStream());
        ZipEntry entry = new ZipEntry(uri.toString().substring(rootOffset));
        byte[] bytes = new byte[1024];
        InputStream fis = FileEditorFactory.getFileEditorForUrl(uri, null).getInputStream();
        entry.setSize(toCompress.length());
        entry.setTime(toCompress.lastModified());
        zos.putNextEntry(entry);
        int count;
        while ((count = fis.read(bytes)) > 0) {
            zos.write(bytes, 0, count);
        }
        zos.closeEntry();
        closeSilently(fis);
        closeSilently(zos);
        return true;
    }
    catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:31,代码来源:ZipUtils.java

示例13: transferIncrementalBackupData

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private int transferIncrementalBackupData(BackupDataInput backupDataInput)
        throws IOException, InvalidAlgorithmParameterException, InvalidKeyException {

    ZipOutputStream outputStream = backupState.getOutputStream();

    int bufferSize = INITIAL_BUFFER_SIZE;
    byte[] buffer = new byte[bufferSize];

    while (backupDataInput.readNextHeader()) {
        String chunkFileName = Base64.encodeToString(backupDataInput.getKey().getBytes(), Base64.DEFAULT);
        int dataSize = backupDataInput.getDataSize();

        if (dataSize >= 0) {
            ZipEntry zipEntry = new ZipEntry(configuration.getIncrementalBackupDirectory() +
                    backupState.getPackageName() + "/" + chunkFileName);
            outputStream.putNextEntry(zipEntry);

            if (dataSize > bufferSize) {
                bufferSize = dataSize;
                buffer = new byte[bufferSize];
            }

            backupDataInput.readEntityData(buffer, 0, dataSize);

            try {
                outputStream.write(buffer, 0, dataSize);

            } catch (Exception ex) {
                Log.e(TAG, "Error performing incremental backup for " + backupState.getPackageName() + ": ", ex);
                clearBackupState(true);
                return TRANSPORT_ERROR;
            }
        }
    }

    return TRANSPORT_OK;
}
 
开发者ID:stevesoltys,项目名称:backup,代码行数:38,代码来源:ContentProviderBackupComponent.java

示例14: writeZipFileEntry

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private static void writeZipFileEntry(ZipOutputStream zos, String zipEntryName, byte[] byteArray) throws IOException {
    int byteArraySize = byteArray.length;

    CRC32 crc = new CRC32();
    crc.update(byteArray, 0, byteArraySize);

    ZipEntry entry = new ZipEntry(zipEntryName);
    entry.setMethod(ZipEntry.STORED);
    entry.setSize(byteArraySize);
    entry.setCrc(crc.getValue());

    zos.putNextEntry(entry);
    zos.write(byteArray, 0, byteArraySize);
    zos.closeEntry();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ProjectLibraryProviderTest.java

示例15: zipFolder

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Zip a given folder
 * 
 * @param dirPath
 *            a given folder: must be all files (not sub-folders)
 * @param filePath
 *            zipped file
 * @throws Exception
 */
public static void zipFolder(String dirPath, String filePath) throws Exception {
	File outFile = new File(filePath);
	ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outFile));
	int bytesRead;
	byte[] buffer = new byte[1024];
	CRC32 crc = new CRC32();
	for (File file : listFiles(dirPath)) {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
		crc.reset();
		while ((bytesRead = bis.read(buffer)) != -1) {
			crc.update(buffer, 0, bytesRead);
		}
		bis.close();

		// Reset to beginning of input stream
		bis = new BufferedInputStream(new FileInputStream(file));
		ZipEntry entry = new ZipEntry(file.getName());
		entry.setMethod(ZipEntry.STORED);
		entry.setCompressedSize(file.length());
		entry.setSize(file.length());
		entry.setCrc(crc.getValue());
		zos.putNextEntry(entry);
		while ((bytesRead = bis.read(buffer)) != -1) {
			zos.write(buffer, 0, bytesRead);
		}
		bis.close();
	}
	zos.close();

	Logs.debug("A zip-file is created to: {}", outFile.getPath());
}
 
开发者ID:xiaojieliu7,项目名称:MicroServiceProject,代码行数:41,代码来源:FileIO.java


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