Class Segment
The first component of a segment is the header; this contains (amongst other things) the expected counts of constant pool entries, which in turn defines how
many values need to be read from the stream. Because values are variable width (see Codec), it is not possible to calculate the start of the next
segment, although one of the header values does hint at the size of the segment if non-zero, which can be used for buffering purposes.
Note that this does not perform any buffering of the input stream; each value will be read on a byte-by-byte basis. It does not perform GZip decompression
automatically; both of these are expected to be done by the caller if the stream has the magic header for GZip streams (GZIPInputStream.GZIP_MAGIC).
In any case, if GZip decompression is being performed the input stream will be buffered at a higher level, and thus this can read on a byte-oriented basis.
Format:
pack200_archive:
(pack200_segment)+
pack200_segment:
segment_header
*band_headers :BYTE1
cp_bands
attr_definition_bands
ic_bands
class_bands
bc_bands
file_bands
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AttrDefinitionBandsprivate BcBandsprivate ClassBandsprivate byte[][]private CpBandsprivate booleanprivate booleanprivate FileBandsprivate boolean[]private boolean[]private SegmentHeaderprivate IcBandsprivate InputStreamstatic final intLog level quiet 0static final intLog level standard 1static final intLog level verbose 2private intprivate PrintWriterprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ClassFilebuildClassFile(int classNum) computeIcStored(IcTuple[] icLocal, IcTuple[] icRelevant) Given an ic_local and an ic_relevant, use them to calculate what should be added as ic_stored.protected AttrDefinitionBandsprotected ClassBandsGets the constant pool.protected CpBandsGets the constant pool bands.protected IcBandsGets the inner class bands.Gets the segment header.voidLogs a message.voidoverrideDeflateHint(boolean deflateHint) Overrides the archive's deflate hint with the given booleanprivate voidPerforms the actual work of parsing against a non-static instance of Segment.private voidThis performs reading the data from the stream into non-static instance of Segment.voidsetLogLevel(int logLevel) Sets the log level.voidsetLogStream(OutputStream logStream) Sets the log output stream.voidsetPreRead(boolean value) Sets whether unpacking buffers its input.voidunpack(InputStream inputStream, JarOutputStream out) Unpacks a packed stream (either .pack.(package private) void(package private) voidunpackRead(InputStream inputStream) (package private) voidvoidwriteJar(JarOutputStream out) Writes the segment to an output stream.
-
Field Details
-
LOG_LEVEL_VERBOSE
public static final int LOG_LEVEL_VERBOSELog level verbose 2- See Also:
-
LOG_LEVEL_STANDARD
public static final int LOG_LEVEL_STANDARDLog level standard 1- See Also:
-
LOG_LEVEL_QUIET
public static final int LOG_LEVEL_QUIETLog level quiet 0- See Also:
-
header
-
cpBands
-
attrDefinitionBands
-
icBands
-
classBands
-
bcBands
-
fileBands
-
overrideDeflateHint
private boolean overrideDeflateHint -
deflateHint
private boolean deflateHint -
doPreRead
private boolean doPreRead -
logLevel
private int logLevel -
logPrintWriter
-
classFilesContents
private byte[][] classFilesContents -
fileDeflate
private boolean[] fileDeflate -
fileIsClass
private boolean[] fileIsClass -
internalBuffer
-
-
Constructor Details
-
Segment
public Segment()
-
-
Method Details
-
buildClassFile
-
computeIcStored
Given an ic_local and an ic_relevant, use them to calculate what should be added as ic_stored.- Parameters:
icLocal- IcTuple[] array of local transmitted tuplesicRelevant- IcTuple[] array of relevant tuples- Returns:
- List of tuples to be stored. If ic_local is null or empty, the values returned may not be correct. The caller will have to determine if this is the case.
-
getAttrDefinitionBands
-
getClassBands
-
getConstantPool
Gets the constant pool.- Returns:
- the constant pool.
-
getCpBands
Gets the constant pool bands.- Returns:
- the constant pool bands.
-
getIcBands
Gets the inner class bands.- Returns:
- the inner class bands.
-
getSegmentHeader
Gets the segment header.- Returns:
- the segment header.
-
log
Logs a message.- Parameters:
messageLevel- the message level.message- the message.
-
overrideDeflateHint
public void overrideDeflateHint(boolean deflateHint) Overrides the archive's deflate hint with the given boolean- Parameters:
deflateHint- the deflate hint to use
-
parseSegment
Performs the actual work of parsing against a non-static instance of Segment. This method is intended to run concurrently for multiple segments.- Throws:
IOException- if a problem occurs during reading from the underlying streamPack200Exception- if a problem occurs with an unexpected value or unsupported codec
-
readSegment
This performs reading the data from the stream into non-static instance of Segment. After the completion of this method stream can be freed.- Parameters:
in- the input stream to read from- Throws:
IOException- if a problem occurs during reading from the underlying streamPack200Exception- if a problem occurs with an unexpected value or unsupported codec
-
setLogLevel
public void setLogLevel(int logLevel) Sets the log level.- Parameters:
logLevel- the log level.
-
setLogStream
Sets the log output stream.- Parameters:
logStream- log output stream.
-
setPreRead
public void setPreRead(boolean value) Sets whether unpacking buffers its input.- Parameters:
value- whether unpacking buffers its input.
-
unpack
public void unpack(InputStream inputStream, JarOutputStream out) throws IOException, Pack200Exception Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding JarOuputStream.- Parameters:
inputStream- a packed input stream, preferably aBoundedInputStream.out- output stream.- Throws:
Pack200Exception- if there is a problem unpackingIOException- if there is a problem with I/O during unpacking
-
unpackProcess
- Throws:
IOExceptionPack200Exception
-
unpackRead
- Throws:
IOExceptionPack200Exception
-
unpackWrite
- Throws:
IOException
-
writeJar
Writes the segment to an output stream. The output stream should be pre-buffered for efficiency. Also takes the same input stream for reading, since the file bits may not be loaded and thus just copied from one stream to another. Doesn't close the output stream when finished, in case there are more entries (for example further segments) to be written.- Parameters:
out- the JarOutputStream to write data to- Throws:
IOException- if an error occurs while reading or writing to the streams
-