public static void expandIkvmClasses(object _zipFile, object _entries) { #if !FIRST_PASS java.util.zip.ZipFile zipFile = (java.util.zip.ZipFile)_zipFile; java.util.LinkedHashMap entries = (java.util.LinkedHashMap)_entries; try { string path = zipFile.getName(); java.util.zip.ZipEntry entry = (java.util.zip.ZipEntry)entries.get(JVM.JarClassList); if (entry != null && VirtualFileSystem.IsVirtualFS(path)) { using (VirtualFileSystem.ZipEntryStream stream = new VirtualFileSystem.ZipEntryStream(zipFile, entry)) { entries.remove(entry.name); BinaryReader br = new BinaryReader(stream); int count = br.ReadInt32(); for (int i = 0; i < count; i++) { java.util.zip.ClassStubZipEntry classEntry = new java.util.zip.ClassStubZipEntry(path, br.ReadString()); classEntry.setMethod(java.util.zip.ClassStubZipEntry.STORED); classEntry.setTime(entry.getTime()); entries.put(classEntry.name, classEntry); } } } } catch (java.io.IOException) { } catch (IOException) { } #endif }
private static void AddEntries(java.util.zip.ZipFile file, string rootDirectory, string[] newFiles, bool flattenHierarchy) { string destFileName = file.getName(); string tempFileName = Path.GetTempFileName(); ZipOutputStream destination = new ZipOutputStream(new FileOutputStream(tempFileName)); try { CopyEntries(file, destination); if (newFiles != null) { foreach (string str3 in newFiles) { string directoryName; if (flattenHierarchy) { directoryName = Path.GetDirectoryName(str3); } else if (rootDirectory == null) { directoryName = Path.GetPathRoot(str3); } else { directoryName = rootDirectory; } directoryName = directoryName + @"\"; ZipEntry ze = new ZipEntry(str3.Remove(0, directoryName.Length)); ze.setMethod(8); destination.putNextEntry(ze); try { FileInputStream source = new FileInputStream(str3); try { CopyStream(source, destination); } finally { source.close(); } } finally { destination.closeEntry(); } } } } finally { destination.close(); } file.close(); System.IO.File.Copy(tempFileName, destFileName, true); System.IO.File.Delete(tempFileName); }
public static string[] getMetaInfEntryNames(object thisJarFile) { #if FIRST_PASS return(null); #else java.util.zip.ZipFile zf = (java.util.zip.ZipFile)thisJarFile; java.util.Enumeration entries = zf.entries(); List <string> list = null; while (entries.hasMoreElements()) { java.util.zip.ZipEntry entry = (java.util.zip.ZipEntry)entries.nextElement(); if (entry.getName().StartsWith("META-INF/", StringComparison.OrdinalIgnoreCase)) { if (list == null) { list = new List <string>(); } list.Add(entry.getName()); } } return(list == null ? null : list.ToArray()); #endif }
private void ExtractFile(ZipFile zipFile, ZipEntry zipEntry, string tempFileName) { InputStream s = zipFile.getInputStream(zipEntry); try { FileOutputStream dest = new FileOutputStream(tempFileName); try { int len = 0; sbyte[] buffer = new sbyte[7168]; while ((len = s.read(buffer)) >= 0) { dest.write(buffer, 0, len); } } finally { dest.close(); } } finally { s.close(); } }
private void addEntry(ZipOutputStream zipStream, String root, File file) { if (file.isHidden()) { return; } var name = root + file.getName(); var zipEntry = new ZipEntry(name); zipStream.putNextEntry(zipEntry); var buffer = new byte[4096]; var inputStream = new FileInputStream(file); int read; while ((read = inputStream.read(buffer)) != -1) { zipStream.write(buffer, 0, read); } }
public int run(String[] arguments) { sourceFiles.clear(); if (!handleArguments(arguments)) { return 1; } var t0 = System.nanoTime(); try { var results = new Compiler().compileFromFiles(parameters, sourceFiles.toArray(new File[sourceFiles.size()])); var hasErrors = false; foreach (var error in results.Errors) { var filename = error.Filename; if (filename != null) { System.out.print(new File(error.Filename).getAbsolutePath()); } else { System.out.print("Unknown source"); } if (error.Line > 0) { System.out.print(" ("); System.out.print(error.Line); if (error.Column > 0) { System.out.print(", "); System.out.print(error.Column); } System.out.print(")"); } if (error.Level == 0) { hasErrors = true; System.out.print(" error "); } else { System.out.print(" warning "); } System.out.print(error.Id); System.out.print(": "); System.out.println(error.Message); } if (!hasErrors) { var outputFile = new File(outputPath); if (outputFile.isDirectory() || outputPath.endsWith("\\") || outputPath.endsWith("/")) { foreach (var e in results.ClassFiles.entrySet()) { var file = new File(outputFile, e.Key.replace('.', '/') + ".class"); var dir = file.getParentFile(); if (!dir.exists()) { dir.mkdirs(); } using (var s = new FileOutputStream(file)) { s.write(e.Value); } } } else { var destination = outputPath; if (PathHelper.getExtension(destination).length() == 0) { destination += ".jar"; } using (var zipStream = new ZipOutputStream(new FileOutputStream(destination))) { if (manifestPath != null) { var zipEntry = new ZipEntry("META-INF/MANIFEST.MF"); zipStream.putNextEntry(zipEntry); var buffer = new byte[4096]; var inputStream = new FileInputStream(manifestPath); int read; while ((read = inputStream.read(buffer)) != -1) { zipStream.write(buffer, 0, read); } inputStream.close(); } if (resourcesPath != null) { var rootDir = new File(resourcesPath); foreach (var content in rootDir.list()) { var file = new File(rootDir, content); if (file.isDirectory()) { exploreDirectory(zipStream, "", file); } else { addEntry(zipStream, "", file); } } } foreach (var e in results.ClassFiles.entrySet()) { var zipEntry = new ZipEntry(e.Key.replace('.', '/') + ".class"); zipStream.putNextEntry(zipEntry); zipStream.write(e.Value); } } } System.out.println(); System.out.println(String.format("%d class(es) successfully generated in %.2fs", results.classFiles.size(), (System.nanoTime() - t0) / 1e9)); return 0; } else { System.out.println(); System.out.println("Compilation failed"); return 1; } } catch (TypeLoadException e) { System.out.println("Cannot find type " + e.TypeName + ". The class is missing from the classpath."); System.out.println("Compilation failed"); return 1; } }