本文整理汇总了Java中java.util.zip.ZipOutputStream.closeEntry方法的典型用法代码示例。如果您正苦于以下问题:Java ZipOutputStream.closeEntry方法的具体用法?Java ZipOutputStream.closeEntry怎么用?Java ZipOutputStream.closeEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.ZipOutputStream
的用法示例。
在下文中一共展示了ZipOutputStream.closeEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateZip
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
* Generates a zip file.
*
* @param source source file or directory to compress.
* @param destination destination of zipped file.
* @return the zipped file.
*/
private void generateZip (File source, File destination) throws IOException
{
if (source == null || !source.exists ())
{
throw new IllegalArgumentException ("source file should exist");
}
if (destination == null)
{
throw new IllegalArgumentException (
"destination file should be not null");
}
FileOutputStream output = new FileOutputStream (destination);
ZipOutputStream zip_out = new ZipOutputStream (output);
zip_out.setLevel (
cfgManager.getDownloadConfiguration ().getCompressionLevel ());
List<QualifiedFile> file_list = getFileList (source);
byte[] buffer = new byte[BUFFER_SIZE];
for (QualifiedFile qualified_file : file_list)
{
ZipEntry entry = new ZipEntry (qualified_file.getQualifier ());
InputStream input = new FileInputStream (qualified_file.getFile ());
int read;
zip_out.putNextEntry (entry);
while ((read = input.read (buffer)) != -1)
{
zip_out.write (buffer, 0, read);
}
input.close ();
zip_out.closeEntry ();
}
zip_out.close ();
output.close ();
}
示例2: zipfiles
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
* Zip all the files in our
* @param dest
* @throws IOException
*/
private void zipfiles(File dest) throws IOException
{
FileOutputStream fos = new FileOutputStream(dest);
ZipOutputStream zos = new ZipOutputStream(fos);
for (Path p : files) {
try {
Path file = p.getFileName();
if (file != null) {
zos.putNextEntry(new ZipEntry(file.toString()));
Files.copy(p, zos);
}
} catch (IOException ioe) {
log.warning("\bUnable to archive " + p);
}
zos.closeEntry();
}
zos.close();
fos.close();
}
示例3: createZipFile
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
static LocalResource createZipFile(FileContext files, Path p, int len,
Random r, LocalResourceVisibility vis) throws IOException,
URISyntaxException {
byte[] bytes = new byte[len];
r.nextBytes(bytes);
File archiveFile = new File(p.toUri().getPath() + ".ZIP");
archiveFile.createNewFile();
ZipOutputStream out = new ZipOutputStream(
new FileOutputStream(archiveFile));
out.putNextEntry(new ZipEntry(p.getName()));
out.write(bytes);
out.closeEntry();
out.close();
LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
ret.setResource(ConverterUtils.getYarnUrlFromPath(new Path(p.toString()
+ ".ZIP")));
ret.setSize(len);
ret.setType(LocalResourceType.ARCHIVE);
ret.setVisibility(vis);
ret.setTimestamp(files.getFileStatus(new Path(p.toString() + ".ZIP"))
.getModificationTime());
return ret;
}
示例4: 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();
}
}
}
示例5: createProductInfo
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/** Adds build.info file with product, os, java version to zip file. */
private static void createProductInfo(ZipOutputStream out) throws IOException {
String productVersion = MessageFormat.format(
NbBundle.getBundle("org.netbeans.core.startup.Bundle").getString("currentVersion"), //NOI18N
new Object[]{System.getProperty("netbeans.buildnumber")}); //NOI18N
String os = System.getProperty("os.name", "unknown") + ", " + //NOI18N
System.getProperty("os.version", "unknown") + ", " + //NOI18N
System.getProperty("os.arch", "unknown"); //NOI18N
String java = System.getProperty("java.version", "unknown") + ", " + //NOI18N
System.getProperty("java.vm.name", "unknown") + ", " + //NOI18N
System.getProperty("java.vm.version", ""); //NOI18N
out.putNextEntry(new ZipEntry("build.info")); //NOI18N
PrintWriter writer = new PrintWriter(out);
writer.println("NetbeansBuildnumber=" + System.getProperty("netbeans.buildnumber")); //NOI18N
writer.println("ProductVersion=" + productVersion); //NOI18N
writer.println("OS=" + os); //NOI18N
writer.println("Java=" + java); //NOI18Nv
writer.println("Userdir=" + System.getProperty("netbeans.user")); //NOI18N
writer.flush();
// Complete the entry
out.closeEntry();
}
示例6: addDirToZipArchive
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private static void addDirToZipArchive(ZipOutputStream zos, File fileToZip, String parrentDirectoryName) throws Exception {
if (fileToZip == null || !fileToZip.exists()) {
return;
}
String zipEntryName = fileToZip.getName();
if (parrentDirectoryName!=null && !parrentDirectoryName.isEmpty()) {
zipEntryName = parrentDirectoryName + "/" + fileToZip.getName();
}
if (fileToZip.isDirectory()) {
for (File file : fileToZip.listFiles()) {
addDirToZipArchive(zos, file, zipEntryName);
}
} else {
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(fileToZip);
zos.putNextEntry(new ZipEntry(zipEntryName));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
fis.close();
}
}
示例7: main
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
int len = conn.getContentLength();
byte[] data = new byte[len];
InputStream is = conn.getInputStream();
is.read(data);
is.close();
conn.setDefaultUseCaches(false);
File jar = File.createTempFile("B7050028", ".jar");
jar.deleteOnExit();
OutputStream os = new FileOutputStream(jar);
ZipOutputStream zos = new ZipOutputStream(os);
ZipEntry ze = new ZipEntry("B7050028.class");
ze.setMethod(ZipEntry.STORED);
ze.setSize(len);
CRC32 crc = new CRC32();
crc.update(data);
ze.setCrc(crc.getValue());
zos.putNextEntry(ze);
zos.write(data, 0, len);
zos.closeEntry();
zos.finish();
zos.close();
os.close();
System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
}
示例8: zipIt
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
* Zip it
*
* @param zipFile output ZIP file location
* @param filesToZip file or folder to zip
* @param sourceFolder folder of file(s)
*/
public void zipIt(String zipFile, File filesToZip, String sourceFolder) {
this.sourceFolder = sourceFolder + File.separator;
generateFileList(filesToZip);
byte[] buffer = new byte[1048576]; // 2^20
try {
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);
System.out.println("Output to Zip : " + zipFile);
for (String file : this.fileList) {
System.out.println("\t" + file);
ZipEntry ze = new ZipEntry(file);
zos.putNextEntry(ze);
FileInputStream in = new FileInputStream(this.sourceFolder + file);
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
}
zos.closeEntry();
//remember close it
zos.close();
System.out.println("Zipping Done");
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例9: save
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public File save() throws IOException {
if (isSave) {
throw new IllegalStateException("Archive is saved already");
}
ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(zipFile));
for (ArchiveEntry file : entries) {
String name = file.getName();
byte[] byteArray = file.getByteArray();
stream.putNextEntry(new ZipEntry(name));
stream.write(byteArray, 0, byteArray.length);
stream.closeEntry();
log("[INFO] archive: " + name);
}
stream.close();
isSave = true;
return zipFile;
}
示例10: PackDirectory
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
* Packs all files in the given directory into the given ZIP stream.
* Also recurses down into subdirectories.
*/
public static void PackDirectory( String startingDirectory,
File theDirectory,
ZipOutputStream theZIPStream )
throws java.io.IOException
{
File[] theFiles = theDirectory.listFiles();
File stDirectory = new File(startingDirectory);
System.out.println("Path="+stDirectory.getPath()+";length="+stDirectory.getPath().length() + "==>"+theFiles[0]);
int j = stDirectory.getPath().length();
for ( int i=0 ; i<theFiles.length ; i++ )
{
String sRelPath = theFiles[i].getPath().substring(j);
if ( theFiles[i].isDirectory() )
{
// create a directory entry.
// directory entries must be terminated by a slash!
ZipEntry theEntry = new ZipEntry("."+sRelPath+"/" );
theZIPStream.putNextEntry(theEntry);
theZIPStream.closeEntry();
// recurse down
PackDirectory( startingDirectory, theFiles[i], theZIPStream );
}
else // regular file
{
File f = theFiles[i];
ZipEntry ze = new ZipEntry("."+sRelPath);
FileInputStream in = new FileInputStream(f);
byte[] data = new byte[(int) f.length()];
in.read(data);
in.close();
theZIPStream.putNextEntry(ze);
theZIPStream.write(data);
theZIPStream.closeEntry();
}
}
}
示例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();
}
示例12: 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();
}
}
示例13: saveMatrixData
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void saveMatrixData(Observation[] obs, VariableNumber[] var, ZipOutputStream zos) {
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();
} catch (IOException e) {
e.printStackTrace();
}
}
示例14: saveToZip
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public static boolean saveToZip(PackItem item, ZipOutputStream zos) {
try {
zos.putNextEntry(new ZipEntry(item.getFileName()));
save(zos, item.getUrl());
zos.closeEntry();
return true;
} catch (IOException e) {
return false;
}
}
示例15: zip
import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
* @source http://stackoverflow.com/a/1399432
*/
public static void zip(File directory, File zipfile) throws Exception {
if (directory.listFiles() == null || directory.listFiles().length == 0) {
return;
}
URI base = directory.toURI();
Deque<File> queue = new LinkedList<File>();
queue.push(directory);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipfile)));
try {
while (!queue.isEmpty()) {
directory = queue.pop();
for (File path : directory.listFiles()) {
String name = base.relativize(path.toURI()).getPath();
if (path.isDirectory()) {
queue.push(path);
name = name.endsWith("/") ? name : name + "/";
out.putNextEntry(new ZipEntry(name));
} else {
out.putNextEntry(new ZipEntry(name));
copy(path, out);
out.closeEntry();
}
}
}
} finally {
out.close();
}
}