APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.tools.jar

public Class Main

extends Object
Class Inheritance
Imports
java.io.*, java.lang.module.Configuration, .FindException, .InvalidModuleDescriptorException, .ModuleDescriptor, .ModuleDescriptor.Exports, .ModuleDescriptor.Opens, .ModuleDescriptor.Provides, .ModuleDescriptor.Version, .ModuleFinder, .ModuleReader, .ModuleReference, .ResolvedModule, java.net.URI, java.nio.ByteBuffer, java.nio.file.Files, .Path, .Paths, .StandardCopyOption, java.nio.file.attribute.FileTime, java.text.MessageFormat, java.time.LocalDateTime, java.util.*, java.util.function.Consumer, java.util.jar.Attributes, .JarFile, .JarOutputStream, .Manifest, java.util.regex.Pattern, java.util.stream.Collectors, .Stream, java.util.zip.CRC32, .ZipEntry, .ZipFile, .ZipInputStream, .ZipOutputStream, jdk.internal.module.Checks, .ModuleHashes, .ModuleHashesBuilder, .ModuleInfo, .ModuleInfoExtender, .ModuleResolution, .ModuleTarget, jdk.internal.opt.CommandLine

This class implements a simple utility for creating files in the JAR (Java Archive) file format. The JAR format is based on the ZIP file format, with optional meta-information stored in a MANIFEST entry.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Main.CRC32OutputStream

An OutputStream that doesn't send its output anywhere, (but could).

private static class
private class
Main.Hasher

Compute and record hashes

pack-priv static interface
Main.ModuleInfoEntry

Associates a module descriptor's zip entry name along with its bytes and an optional URI.

pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv boolean
private byte[]
copyBuf

A buffer for use only by copy(InputStream, OutputStream).

pack-priv LocalDateTime
pack-priv boolean
pack-priv String
pack-priv Set<Main.Entry>
pack-priv static Comparator<ZipEntry>
pack-priv Map<String, Main.Entry>
pack-priv static Comparator<String>
pack-priv PrintWriter
pack-priv Map<Integer, String[]>
pack-priv boolean
pack-priv String
pack-priv boolean
pack-priv Consumer<PrintWriter>
pack-priv boolean
private HashSet<String>
pack-priv boolean
pack-priv static final String
pack-priv boolean
pack-priv String
pack-priv static final String
pack-priv ModuleFinder
pack-priv Map<String, Main.ModuleInfoEntry>
pack-priv ModuleResolution
pack-priv Pattern
pack-priv ModuleDescriptor.Version
private boolean
pack-priv PrintWriter
pack-priv Map<Integer, Set<String>>
pack-priv boolean
pack-priv String
pack-priv int
pack-priv String
private static ResourceBundle
pack-priv boolean
pack-priv boolean
pack-priv boolean
private static final boolean
useExtractionTime

If true, maintain compatibility with JDK releases prior to 6.0 by timestamping extracted files with the time at which they are extracted.

pack-priv boolean
pack-priv static final String
pack-priv static final String
pack-priv static final int
pack-priv boolean
pack-priv String
pack-priv boolean
pack-priv String

Constructor Summary

AccessConstructor and Description
public
Main(PrintStream out, PrintStream err, String program)

public
Main(PrintWriter out, PrintWriter err, String program)

Method Summary

Modifier and TypeMethod and Description
private void
private void
addExtendedModuleAttributes(Map<String, Main.ModuleInfoEntry> moduleInfos, Set<String> packages)

Adds extended modules attributes to the given module-info's.

pack-priv void
addFile(ZipOutputStream zos, Main.Entry entry)

Adds a new file entry to the ZIP output stream.

private void
private void
private void
pack-priv void
private void
private boolean
checkModuleInfo(Main.ModuleInfoEntry moduleInfoEntry, Set<String> entries)

private void
copy(InputStream
the input stream to read from
from
,
OutputStream
the output stream to write to
to
)

Copies all bytes from the input stream to the output stream.

private void
copy(File
the input file to read from
from
,
OutputStream
the output stream to write to
to
)

Copies all bytes from the input file to the output stream.

private void
copy(InputStream
the input stream to read from
from
,
File
the output file to write to
to
)

Copies all bytes from the input stream to the output file.

private void
crc32File(ZipEntry e, File f)

Computes the crc32 of a File.

private void
crc32Manifest(ZipEntry e, Manifest m)

Computes the crc32 of a Manifest.

private void
crc32ModuleInfo(ZipEntry e, byte[] bytes)

Computes the crc32 of a module-info.class.

pack-priv void
create(OutputStream out, Manifest manifest)

Creates a new JAR file.

private static File
createTempFileInSameDirectoryAs(File file)

Creates a new empty temporary file in the same directory as the specified file.

private File
createTemporaryFile(String tmpbase, String suffix)

Attempt to create temporary file in the system-provided temporary folder, if failed attempts to create it in the same folder as the file in parameter (if any)

private boolean
describeModule(ZipFile zipFile)

Describes a module from a given zip file.

private void
describeModule(InputStream entryInputStream, String uriString)

private void
private boolean
describeModuleFromEntries(Main.ModuleInfoEntry[] infos)

Describes a single module descriptor, determined by the specified --release, if any, from the given ordered entries.

private boolean
pack-priv void
dumpIndex(String rootjar, JarIndex index)

Outputs the class index table to the INDEX.LIST file of the root jar file.

private boolean
equalsIgnoreCase(String s, String upper)

Compares two strings for equality, ignoring case.

pack-priv void
error(String s)

Print an error message; like something is broken

private void
private void
expand(File
parent directory
dir
,
String[]
list of files to expand
files
,
Set<String>
set of directories specified by -C option for the files
cpaths
,
int version)

Expands list of files to process into full list of all files that can be found by recursively descending directories.

private byte[]
extendedInfoBytes(ModuleDescriptor md, byte[] miBytes, Set<String> packages)

Returns a byte array containing the given module-info.class plus any extended attributes.

pack-priv void
extract(InputStream in, String[] files)

Extracts specified entries from JAR file.

pack-priv void
extract(String fname, String[] files)

Extracts specified entries from JAR file, via ZipFile.

pack-priv ZipEntry
extractFile(InputStream is, ZipEntry e)

Extracts next entry from JAR file, creating directories as needed.

pack-priv void
fatalError(Exception e)

A fatal exception has been caught.

pack-priv void
fatalError(String s)

A fatal condition has been detected; message is "s".

private String[]
pack-priv Stream<String>
pack-priv static String
formatMsg(String key, String... args)

pack-priv void
genIndex(String rootjar, String[] files)

Generates class index file for the specified root jar file.

pack-priv List<String>
getJarPath(String jar)

Generates the transitive closure of the Class-Path attribute for the specified jar file.

pack-priv static String
private static int
private boolean
pack-priv static boolean
private static final boolean
private boolean
pack-priv void
list(InputStream in, String[] files)

Lists contents of JAR file.

pack-priv void
list(String fname, String[] files)

Lists contents of JAR file, via ZipFile.

public static void
main(String[] args)

Main routine to start program.

pack-priv Set<ZipEntry>
protected void
output(String s)

Print an output message; like verbose output and the like

pack-priv boolean
parseArgs(String[] args)

Parses command line arguments.

pack-priv void
printEntry(ZipEntry e, String[] files)

Prints entry information, if requested.

pack-priv void
printEntry(ZipEntry e)

Prints entry information.

pack-priv void
replaceFSC(Map<Integer, String[]> filesMap)

public synchronized boolean
run(String[] args)

Starts main program with the specified arguments.

private String
private void
private void
setZipEntryTime(ZipEntry e, long origTime)

pack-priv static String
toBinaryName(String classname)

private String
toEntryName(String name, Set<String> cpaths, boolean isDir)

private static String
toHex(byte[] ba)

pack-priv static <T> String
private static String
pack-priv static <T> String
private char
private static String
toVersionedName(String name, int version)

pack-priv boolean
update(InputStream in, OutputStream out, InputStream newManifest, Map<String, Main.ModuleInfoEntry> moduleInfos, JarIndex jarIndex)

Updates an existing jar file.

pack-priv void
private boolean
private void
pack-priv void
usageError(String s)

Prints usage message.

private void
private boolean
private static String
pack-priv void
warn(String s)

Print a warning message

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait