本文整理汇总了C#中ZipFile.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.Close方法的具体用法?C# ZipFile.Close怎么用?C# ZipFile.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipFile
的用法示例。
在下文中一共展示了ZipFile.Close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessFile
private static void ProcessFile(File effDocFile, File outFile)
{
if (!effDocFile.exists())
{
throw new RuntimeException("file '" + effDocFile.GetAbsolutePath() + "' does not exist");
}
OutputStream os;
try
{
os = new FileOutputStream(outFile);
}
catch (FileNotFoundException e)
{
throw new RuntimeException(e);
}
os = new SimpleAsciiOutputStream(os);
PrintStream ps;
try
{
ps = new PrintStream(os, true, "UTF-8");
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException(e);
}
outputLicenseHeader(ps);
Type genClass = typeof(ExcelFileFormatDocFunctionExtractor);
ps.println("# Created by (" + genClass.Name + ")");
// identify the source file
ps.print("# from source file '" + SOURCE_DOC_FILE_NAME + "'");
ps.println(" (size=" + effDocFile.Length + ", md5=" + GetFileMD5(effDocFile) + ")");
ps.println("#");
ps.println("#Columns: (index, name, minParams, maxParams, returnClass, paramClasses, isVolatile, hasFootnote )");
ps.println("");
try
{
ZipFile zf = new ZipFile(effDocFile);
InputStream is1 = zf.GetInputStream(zf.GetEntry("content.xml"));
extractFunctionData(new FunctionDataCollector(ps), is1);
zf.Close();
}
catch (ZipException e)
{
throw new RuntimeException(e);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
ps.Close();
String canonicalOutputFileName;
try
{
canonicalOutputFileName = outFile.GetCanonicalPath();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
Console.WriteLine("Successfully output to '" + canonicalOutputFileName + "'");
}
示例2: TestZipped
public static void TestZipped()
{
DateTime t1, t2;
TimeSpan dt;
Foo o = new Foo();
o.Fill(100000);
t1 = DateTime.Now;
XmlDocumentSerializationInfo info = new XmlDocumentSerializationInfo();
info.AddValue("FooNode",o);
System.IO.FileStream zipoutfile = System.IO.File.Create(@"C:\temp\xmltest03.xml.zip");
ZipOutputStream ZipStream = new ZipOutputStream(zipoutfile);
ZipEntry ZipEntry = new ZipEntry("Table/Table1.xml");
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(7);
info.Doc.Save(ZipStream);
ZipStream.Finish();
ZipStream.Close();
zipoutfile.Close();
t2 = DateTime.Now;
dt = t2-t1;
Console.WriteLine("Document saved, duration {0}.",dt);
t1 = DateTime.Now;
ZipFile zipfile = new ZipFile(@"C:\temp\xmltest03.xml.zip");
System.IO.Stream zipinpstream = zipfile.GetInputStream(new ZipEntry("Table/Table1.xml"));
XmlDocument doc3 = new XmlDocument();
doc3.Load(zipinpstream);
XmlDocumentSerializationInfo info3 = new XmlDocumentSerializationInfo(doc3);
Foo o3 = (Foo)info3.GetValue(null);
zipinpstream.Close();
zipfile.Close();
t2 = DateTime.Now;
dt = t2-t1;
Console.WriteLine("Document restored, duration {0}.",dt);
}
示例3: RestoreData
//.........这里部分代码省略.........
Log.Trace("Cleaning out voicemail directory...");
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_VOICEMAIL_PATH);
Log.Trace("Examining all content within uploaded zip file...");
foreach(sZippedFolder fold in zf.Folders)
{
if (fold.Name == "voicemail")
{
RestoreFiles(fold, Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_VOICEMAIL_PATH);
break;
}
}
foreach (ZipFile.sZippedFile file in zf.Files)
{
if (file.Name == "voicemail_restore.sql")
{
Utility.ExecuteCommandToFreeswitchDB(FileDownloader.VM_DB, System.Text.ASCIIEncoding.ASCII.GetString(file.Data));
break;
}
}
break;
case RestoreTypes.Recordings:
Log.Trace("Cleaning out recordings directory...");
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_RECORDINGS_DIRECTORY);
Log.Trace("Examining all content within uploaded zip file...");
foreach (sZippedFolder fold in zf.Folders)
{
if (fold.Name == "recordings")
{
RestoreFiles(fold, Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_RECORDINGS_DIRECTORY);
}
}
break;
case RestoreTypes.Script:
Log.Trace("Cleaning out scripts directory...");
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SCRIPTS_DIRECTORY);
Log.Trace("Examining all content within uploaded zip file...");
foreach (sZippedFolder fold in zf.Folders)
{
if (fold.Name == "scripts")
{
RestoreFiles(fold,Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SCRIPTS_DIRECTORY);
}
}
break;
case RestoreTypes.Sounds:
Log.Trace("Cleaning out sounds directory...");
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SOUNDS_DIRECTORY);
Log.Trace("Examining all content within uploaded zip file...");
foreach (sZippedFolder fold in zf.Folders)
{
if (fold.Name == "sounds")
{
RestoreFiles(fold, Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SOUNDS_DIRECTORY);
}
}
break;
case RestoreTypes.Complete:
Log.Trace("Cleaning out directories to perform complete restore...");
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_VOICEMAIL_PATH);
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_RECORDINGS_DIRECTORY);
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SCRIPTS_DIRECTORY);
CleanDirectory(Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SOUNDS_DIRECTORY);
Log.Trace("Restoring data from the zip file to the system...");
foreach (sZippedFolder fold in zf.Folders)
{
switch (fold.Name)
{
case "voicemail":
RestoreFiles(fold, Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_VOICEMAIL_PATH);
break;
case "recordings":
RestoreFiles(fold, Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_RECORDINGS_DIRECTORY);
break;
case "scripts":
RestoreFiles(fold, Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SCRIPTS_DIRECTORY);
break;
case "sounds":
RestoreFiles(fold, Settings.Current[Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Org.Reddragonit.FreeSwitchConfig.DataCore.Constants.DEFAULT_SOUNDS_DIRECTORY);
break;
}
}
foreach (ZipFile.sZippedFile zfi in zf.Files)
{
switch (zfi.Name)
{
case "database.rdpbk":
Stream ms = new MemoryStream(zfi.Data);
ret = BackupManager.RestoreDataFromStream(ConnectionPoolManager.GetPool(typeof(Extension)),
ref ms);
break;
case "voicemail_restore.sql":
Utility.ExecuteCommandToFreeswitchDB(FileDownloader.VM_DB, System.Text.ASCIIEncoding.ASCII.GetString(zfi.Data));
break;
}
}
break;
}
zf.Close();
return ret;
}
示例4: TestZippedStream
public static void TestZippedStream(int len, int ziplevel)
{
DateTime t1, t2;
TimeSpan dt;
Foo o = new Foo();
o.Fill(len);
System.IO.FileStream zipoutfile = System.IO.File.Create(@"C:\temp\xmlteststream01.xml.zip");
ZipOutputStream ZipStream = new ZipOutputStream(zipoutfile);
ZipEntry ZipEntry = new ZipEntry("Table/Table1.xml");
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(ziplevel);
XmlStreamSerializationInfo info = new XmlStreamSerializationInfo();
t1 = DateTime.Now;
info.BeginWriting(ZipStream);
info.AddValue("FooNode",o);
info.EndWriting();
ZipStream.Finish();
ZipStream.Close();
zipoutfile.Close();
t2 = DateTime.Now;
dt = t2-t1;
Console.WriteLine("Document saved, duration {0}.",dt);
t1 = DateTime.Now;
ZipFile zipfile = new ZipFile(@"C:\temp\xmlteststream01.xml.zip");
System.IO.Stream zipinpstream = zipfile.GetInputStream(new ZipEntry("Table/Table1.xml"));
XmlStreamDeserializationInfo info3 = new XmlStreamDeserializationInfo();
info3.BeginReading(zipinpstream);
Foo o3 = (Foo)info3.GetValue(null);
info3.EndReading();
zipinpstream.Close();
zipfile.Close();
t2 = DateTime.Now;
dt = t2-t1;
Console.WriteLine("Document restored, duration {0}.",dt);
o3.EnsureEquality(len);
}