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


Java ZipArchiveOutputStream.write方法代碼示例

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


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

示例1: writeArchivedLogTailToStream

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
    if (!logFile.exists()) {
        throw new FileNotFoundException();
    }

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream);
    zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
    zipOutputStream.setEncoding(ZIP_ENCODING);

    byte[] content = getTailBytes(logFile);

    ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content);
    zipOutputStream.putArchiveEntry(archiveEntry);
    zipOutputStream.write(content);

    zipOutputStream.closeArchiveEntry();
    zipOutputStream.close();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:19,代碼來源:LogArchiver.java

示例2: exportFolder

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
@Override
public byte[] exportFolder(Folder folder) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
    zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
    zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
    String xml = createXStream().toXML(folder);
    byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
    ArchiveEntry zipEntryDesign = newStoredEntry("folder.xml", xmlBytes);
    zipOutputStream.putArchiveEntry(zipEntryDesign);
    zipOutputStream.write(xmlBytes);
    try {
        zipOutputStream.closeArchiveEntry();
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Exception occurred while exporting folder %s.",  folder.getName()));
    }

    zipOutputStream.close();
    return byteArrayOutputStream.toByteArray();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:22,代碼來源:FoldersServiceBean.java

示例3: exportEntitiesToZIP

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
@Override
public byte[] exportEntitiesToZIP(Collection<? extends Entity> entities) {
    String json = entitySerialization.toJson(entities, null, EntitySerializationOption.COMPACT_REPEATED_ENTITIES);
    byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
    zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
    zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
    ArchiveEntry singleDesignEntry = newStoredEntry("entities.json", jsonBytes);
    try {
        zipOutputStream.putArchiveEntry(singleDesignEntry);
        zipOutputStream.write(jsonBytes);
        zipOutputStream.closeArchiveEntry();
    } catch (Exception e) {
        throw new RuntimeException("Error on creating zip archive during entities export", e);
    } finally {
        IOUtils.closeQuietly(zipOutputStream);
    }
    return byteArrayOutputStream.toByteArray();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:22,代碼來源:EntityImportExport.java

示例4: makeSourceZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
/**
 * Creates a zip file with random content.
 *
 * @author S3460
 * @param source the source
 * @return the zip file
 * @throws Exception the exception
 */
private ZipFile makeSourceZipFile(File source) throws Exception {
  ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(source));
  int size = randomSize(entryMaxSize);
  for (int i = 0; i < size; i++) {
    out.putArchiveEntry(new ZipArchiveEntry("zipentry" + i));
    int anz = randomSize(10);
    for (int j = 0; j < anz; j++) {
      byte[] bytes = getRandomBytes();
      out.write(bytes, 0, bytes.length);
    }
    out.flush();
    out.closeArchiveEntry();
  }
  //add leeres Entry
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + size));
  out.flush();
  out.closeArchiveEntry();
  out.flush();
  out.finish();
  out.close();
  return new ZipFile(source);
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:31,代碼來源:JarDeltaJarPatcherTest.java

示例5: makeTargetZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
/**
 * Writes a modified version of zip_Source into target.
 *
 * @author S3460
 * @param zipSource the zip source
 * @param target the target
 * @return the zip file
 * @throws Exception the exception
 */
private ZipFile makeTargetZipFile(ZipFile zipSource, File target) throws Exception {
  ZipArchiveOutputStream out = new ZipArchiveOutputStream(new FileOutputStream(target));
  for (Enumeration<ZipArchiveEntry> enumer = zipSource.getEntries(); enumer.hasMoreElements();) {
    ZipArchiveEntry sourceEntry = enumer.nextElement();
    out.putArchiveEntry(new ZipArchiveEntry(sourceEntry.getName()));
    byte[] oldBytes = toBytes(zipSource, sourceEntry);
    byte[] newBytes = getRandomBytes();
    byte[] mixedBytes = mixBytes(oldBytes, newBytes);
    out.write(mixedBytes, 0, mixedBytes.length);
    out.flush();
    out.closeArchiveEntry();
  }
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + entryMaxSize + 1));
  byte[] bytes = getRandomBytes();
  out.write(bytes, 0, bytes.length);
  out.flush();
  out.closeArchiveEntry();
  out.putArchiveEntry(new ZipArchiveEntry("zipentry" + (entryMaxSize + 2)));
  out.closeArchiveEntry();
  out.flush();
  out.finish();
  out.close();
  return new ZipFile(targetFile);
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:34,代碼來源:JarDeltaJarPatcherTest.java

示例6: zip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
/**
 * Add one file to the open zip archive stream. Drops the file if it is a directory
 * 
 * @param fileToZip
 * @param baseDir
 * @param os
 * @throws Throwable
 */
public static void zip(File fileToZip, ZipArchiveOutputStream os) throws Throwable {
	if (fileToZip.isDirectory()) return;

	byte buffer[] = new byte[BUFFER_SIZE];
	String name = fileToZip.getName();
	ZipArchiveEntry entry = new ZipArchiveEntry(fileToZip, name);
	entry.setSize(fileToZip.length());
	os.putArchiveEntry(entry);
	BufferedInputStream is = new BufferedInputStream(new FileInputStream(fileToZip), BUFFER_SIZE);
	int count;
	try {
		while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
			os.write(buffer, 0, count);
		}
	} finally {
		is.close();
	}
	os.closeArchiveEntry();
}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:28,代碼來源:ZipUtil.java

示例7: sendMetadataCompressed

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
@Override
protected void sendMetadataCompressed(String fileName, byte[] content, long lastModified,
    ZipArchiveOutputStream container) throws IOException {
    ZipArchiveEntry entry = new ZipArchiveEntry(fileName);
    entry.setSize(content.length);
    entry.setTime(lastModified);
    container.putArchiveEntry(entry);
    container.write(content);
    container.closeArchiveEntry();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:11,代碼來源:MCRZipServlet.java

示例8: zipRepository

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
/**
 * <p>
 * Recursively browses the given {@code root} repository elements to populate the given {@code zipOutputStream} with
 * corresponding files.
 * </p>
 * <p>
 * If a referenced file cannot be found in the storage folder, it will be ignored (a {@code WARN} log is generated).
 * </p>
 * 
 * @param root
 *          The root repository element.
 * @param zipOutputStream
 *          The stream to populate with files hierarchy.
 * @param actualPath
 *          The current repository path.
 */
private void zipRepository(final RepositoryElement root, final ZipArchiveOutputStream zipOutputStream, final String actualPath) {

	final String path = (actualPath.equals("") ? root.getName() : actualPath + "/" + root.getName());

	if (root instanceof FileElement) {

		final FileElement file = (FileElement) root;
		final String fileStorageId = file.getStorageId();
		
		if(fileStorageProvider.exists(fileStorageId)) {
			try (final InputStream is = new BufferedInputStream(fileStorageProvider.open(fileStorageId), ResponseHelper.BUFFER_SIZE)) {

				zipOutputStream.putArchiveEntry(new ZipArchiveEntry(path));

				final byte data[] = new byte[ResponseHelper.BUFFER_SIZE];

				while ((is.read(data)) != -1) {
					zipOutputStream.write(data);
				}

				zipOutputStream.closeArchiveEntry();

			} catch (final IOException e) {
				LOG.warn("File '" + fileStorageId + "' cannot be found ; continuing with next file.", e);
			}
		} else {
			LOG.warn("File '{0}' does not exists on the server ; continuing with next file.", fileStorageId);
		}

	} else if (root instanceof FolderElement) {

		final FolderElement folder = (FolderElement) root;

		for (final RepositoryElement element : folder.getChildren()) {
			zipRepository(element, zipOutputStream, path);
		}
	}
}
 
開發者ID:sigmah-dev,項目名稱:sigmah,代碼行數:55,代碼來源:BackupArchiveJob.java

示例9: writeToZip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
public void writeToZip(ZipArchiveOutputStream zipOutput) throws IOException {
	if (contentInputStream == null)
		return;
	String[] domainParts = StringUtils.split(uri.getHost(), '.');
	StringBuilder path = new StringBuilder();
	for (int i = domainParts.length - 1; i >= 0; i--) {
		path.append(domainParts[i]);
		path.append('/');
	}
	String[] pathParts = StringUtils.split(uri.getPath(), '/');
	for (int i = 0; i < pathParts.length - 1; i++) {
		if (StringUtils.isEmpty(pathParts[i]))
			continue;
		path.append(pathParts[i]);
		path.append('/');
	}
	if (contentDispositionFilename != null)
		path.append(contentDispositionFilename);
	else {
		String lastPart = pathParts == null || pathParts.length == 0 ? null : pathParts[pathParts.length - 1];
		if (StringUtils.isEmpty(lastPart))
			path.append("index");
		else
			path.append(lastPart);
	}
	if (uri.getPath().endsWith("/"))
		path.append("/_index");
	String query = uri.getQuery();
	String fragment = uri.getFragment();
	if (!StringUtils.isEmpty(query) || !StringUtils.isEmpty(fragment)) {
		CRC32 crc32 = new CRC32();
		if (!StringUtils.isEmpty(query))
			crc32.update(query.getBytes());
		if (!StringUtils.isEmpty(fragment))
			crc32.update(fragment.getBytes());
		path.append('.');
		path.append(crc32.getValue());
	}
	ZipArchiveEntry zipEntry = new ZipArchiveEntry(path.toString());
	zipOutput.putArchiveEntry(zipEntry);
	BufferedInputStream bis = null;
	byte[] buffer = new byte[65536];
	try {
		bis = new BufferedInputStream(contentInputStream);
		int l;
		while ((l = bis.read(buffer)) != -1)
			zipOutput.write(buffer, 0, l);
		zipOutput.closeArchiveEntry();
	} finally {
		IOUtils.close(bis);
	}
}
 
開發者ID:jaeksoft,項目名稱:opensearchserver,代碼行數:53,代碼來源:DownloadItem.java

示例10: addToZip

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
public void addToZip(NodeRef node, ZipArchiveOutputStream out, boolean noaccent, String path) throws IOException {
	QName nodeQnameType = this.nodeService.getType(node);

	// Special case : links
	if (this.dictionaryService.isSubClass(nodeQnameType, ApplicationModel.TYPE_FILELINK)) {
		NodeRef linkDestinationNode = (NodeRef) nodeService.getProperty(node, ContentModel.PROP_LINK_DESTINATION);
		if (linkDestinationNode == null) {
			return;
		}

		// Duplicate entry: check if link is not in the same space of the link destination
		if (nodeService.getPrimaryParent(node).getParentRef().equals(nodeService.getPrimaryParent(linkDestinationNode).getParentRef())) {
			return;
		}

		nodeQnameType = this.nodeService.getType(linkDestinationNode);
		node = linkDestinationNode;
	}

	String nodeName = (String) nodeService.getProperty(node, ContentModel.PROP_NAME);
	nodeName = noaccent ? unAccent(nodeName) : nodeName;

	if (this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_CONTENT)) {
		ContentReader reader = contentService.getReader(node, ContentModel.PROP_CONTENT);
		if (reader != null) {
			InputStream is = reader.getContentInputStream();

			String filename = path.isEmpty() ? nodeName : path + '/' + nodeName;

			ZipArchiveEntry entry = new ZipArchiveEntry(filename);
			entry.setTime(((Date) nodeService.getProperty(node, ContentModel.PROP_MODIFIED)).getTime());

			entry.setSize(reader.getSize());
			out.putArchiveEntry(entry);

			byte buffer[] = new byte[BUFFER_SIZE];
			while (true) {
				int nRead = is.read(buffer, 0, buffer.length);
				if (nRead <= 0) {
					break;
				}

				out.write(buffer, 0, nRead);
			}
			is.close();
			out.closeArchiveEntry();
		}
		else {
			logger.warn("Could not read : "	+ nodeName + "content");
		}
	}
	else if(this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_FOLDER) 
			&& !this.dictionaryService.isSubClass(nodeQnameType, ContentModel.TYPE_SYSTEM_FOLDER)) {
		List<ChildAssociationRef> children = nodeService
				.getChildAssocs(node);
		if (children.isEmpty()) {
			String folderPath = path.isEmpty() ? nodeName + '/' : path + '/' + nodeName + '/';
			out.putArchiveEntry(new ZipArchiveEntry(new ZipEntry(folderPath)));
		} else {
			for (ChildAssociationRef childAssoc : children) {
				NodeRef childNodeRef = childAssoc.getChildRef();

				addToZip(childNodeRef, out, noaccent,
						path.isEmpty() ? nodeName : path + '/' + nodeName);
			}
		}
	} else {
		logger.info("Unmanaged type: "
				+ nodeQnameType.getPrefixedQName(this.namespaceService)
				+ ", filename: " + nodeName);
	}
}
 
開發者ID:atolcd,項目名稱:alfresco-zip-and-download,代碼行數:73,代碼來源:ZipContents.java

示例11: computeDelta

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //導入方法依賴的package包/類
/**
 * Computes the binary differences of two zip files. For all files contained in source and target which
 * are not equal, the binary difference is caluclated by using
 * {@link com.nothome.delta.Delta#compute(byte[], InputStream, DiffWriter)}.
 * If the files are equal, nothing is written to the output for them.
 * Files contained only in target and files to small for {@link com.nothome.delta.Delta} are copied to output.
 * Files contained only in source are ignored.
 * At last a list of all files contained in target is written to <code>META-INF/file.list</code> in output.
 *
 * @param sourceName the original zip file
 * @param targetName a modification of the original zip file
 * @param source the original zip file
 * @param target a modification of the original zip file
 * @param output the zip file where the patches have to be written to
 * @throws IOException if an error occurs reading or writing any entry in a zip file
 */
public void computeDelta(String sourceName, String targetName, ZipFile source, ZipFile target, ZipArchiveOutputStream output) throws IOException {
  ByteArrayOutputStream listBytes = new ByteArrayOutputStream();
  PrintWriter list = new PrintWriter(new OutputStreamWriter(listBytes));
  list.println(sourceName);
  list.println(targetName);
  computeDelta(source, target, output, list, "");
  list.close();
  ZipArchiveEntry listEntry = new ZipArchiveEntry("META-INF/file.list");
  output.putArchiveEntry(listEntry);
  output.write(listBytes.toByteArray());
  output.closeArchiveEntry();
  output.finish();
  output.flush();
}
 
開發者ID:NitorCreations,項目名稱:javaxdelta,代碼行數:31,代碼來源:JarDelta.java


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