static void WriteClassesToZip(List <JavaClass> classes, string outputPath) { using (var zipStream = new FileStream(outputPath, FileMode.OpenOrCreate)) { using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Update)) { foreach (var jclass in classes) { var path = jclass.FilePath(); var entry = archive.GetEntry(path); if (entry != null) { entry.Delete(); } try { entry = archive.CreateEntry(path, CompressionLevel.Optimal); using (var entryStream = entry.Open()) { JavaWriter.WriteClass(jclass, entryStream); } } catch (Exception e) { #if DEBUGDIAG Console.WriteLine(e); #endif throw new Exception(e.Message + " in entry '" + path + "'"); } } } } }
public void Instanciates() { var writer = new JavaWriter("./", "graph"); Assert.NotNull(writer); Assert.NotNull(writer.PathSegmenter); Assert.Throws <ArgumentNullException>(() => new JavaWriter(null, "graph")); Assert.Throws <ArgumentNullException>(() => new JavaWriter("./", null)); }
static void MainDotNet2(List <JavaClass> classes, string outputPath) { #if !DEBUG string outputType = ""; try { #endif if (IsDirectoryPath(outputPath)) { #if !DEBUG outputType = "directory"; #endif WriteClassesToDir(classes, outputPath); } else if (outputPath.ToLower().EndsWith(".class")) { #if !DEBUG outputType = "file"; #endif if (classes.Count != 1) { Console.WriteLine("warning: input contains more than one class"); } using (var fileStream = new FileStream(outputPath, FileMode.Create)) { JavaWriter.WriteClass(classes[0], fileStream); } } else { #if !DEBUG outputType = "ZIP file"; #endif WriteClassesToZip(classes, outputPath); } #if !DEBUG } catch (Exception e) { if (!(e is JavaException)) { e = new JavaException(e.Message + " in writing output " + outputType, new JavaException.Where()); } throw e; } #endif }
static void WriteClassesToDir(List <JavaClass> classes, string outputPath) { foreach (var jclass in classes) { var filePath = outputPath + "/" + jclass.FilePath(); var dirPath = Path.GetDirectoryName(filePath); if (dirPath != null) { Directory.CreateDirectory(dirPath); } using (var fileStream = new FileStream(filePath, FileMode.Create)) { JavaWriter.WriteClass(jclass, fileStream); } } }