putNextEntry() public method

public putNextEntry ( java arg0 ) : void
arg0 java
return void
示例#1
0
 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);
 }
示例#2
0
 private static void CopyEntries(java.util.zip.ZipFile source, ZipOutputStream destination, string[] entryNames)
 {
     List<ZipEntry> zippedItems = GetZippedItems(source);
     for (int i = 0; i < entryNames.Length; i++)
     {
         foreach (ZipEntry entry in zippedItems)
         {
             if (entry.getName() == entryNames[i])
             {
                 destination.putNextEntry(entry);
                 InputStream stream = source.getInputStream(entry);
                 CopyStream(stream, destination);
                 destination.closeEntry();
                 stream.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);
     }
 }
示例#4
0
 private static void CopyEntries(java.util.zip.ZipFile source, ZipOutputStream destination)
 {
     foreach (ZipEntry entry in GetZippedItems(source))
     {
         destination.putNextEntry(entry);
         InputStream stream = source.getInputStream(entry);
         CopyStream(stream, destination);
         destination.closeEntry();
         stream.close();
     }
 }
        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;
			}
        }