- java.lang.Object
-
- kala.compress.harmony.unpack200.Segment
-
public class Segment extends java.lang.ObjectA Pack200 archive consists of one or more segments. Each segment is stand-alone, in the sense that every segment has the magic number header; thus, every segment is also a valid archive. However, it is possible to combine (non-GZipped) archives into a single large archive by concatenation alone. Thus, all the hard work in unpacking an archive falls to understanding a 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 (seeCodec), 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.
-
-
Field Summary
Fields Modifier and Type Field Description private AttrDefinitionBandsattrDefinitionBandsprivate BcBandsbcBandsprivate ClassBandsclassBandsprivate byte[][]classFilesContentsprivate CpBandscpBandsprivate booleandeflateHintprivate booleandoPreReadprivate FileBandsfileBandsprivate boolean[]fileDeflateprivate boolean[]fileIsClassprivate SegmentHeaderheaderprivate IcBandsicBandsprivate java.io.InputStreaminternalBufferstatic intLOG_LEVEL_QUIETstatic intLOG_LEVEL_STANDARDstatic intLOG_LEVEL_VERBOSEprivate intlogLevelprivate java.io.PrintWriterlogStreamprivate booleanoverrideDeflateHint
-
Constructor Summary
Constructors Constructor Description Segment()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ClassFilebuildClassFile(int classNum)private java.util.List<IcTuple>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 AttrDefinitionBandsgetAttrDefinitionBands()protected ClassBandsgetClassBands()SegmentConstantPoolgetConstantPool()protected CpBandsgetCpBands()protected IcBandsgetIcBands()SegmentHeadergetSegmentHeader()voidlog(int logLevel, java.lang.String message)voidoverrideDeflateHint(boolean deflateHint)Override the archive's deflate hint with the given booleanprivate voidparseSegment()This performs the actual work of parsing against a non-static instance of Segment.private voidreadSegment(java.io.InputStream in)This performs reading the data from the stream into non-static instance of Segment.voidsetLogLevel(int logLevel)voidsetLogStream(java.io.OutputStream logStream)voidsetPreRead(boolean value)voidunpack(java.io.InputStream inputStream, java.util.jar.JarOutputStream out)Unpacks a packed stream (either .pack.(package private) voidunpackProcess()(package private) voidunpackRead(java.io.InputStream inputStream)(package private) voidunpackWrite(java.util.jar.JarOutputStream out)voidwriteJar(java.util.jar.JarOutputStream out)Writes the segment to an output stream.
-
-
-
Field Detail
-
LOG_LEVEL_VERBOSE
public static final int LOG_LEVEL_VERBOSE
- See Also:
- Constant Field Values
-
LOG_LEVEL_STANDARD
public static final int LOG_LEVEL_STANDARD
- See Also:
- Constant Field Values
-
LOG_LEVEL_QUIET
public static final int LOG_LEVEL_QUIET
- See Also:
- Constant Field Values
-
header
private SegmentHeader header
-
cpBands
private CpBands cpBands
-
attrDefinitionBands
private AttrDefinitionBands attrDefinitionBands
-
icBands
private IcBands icBands
-
classBands
private ClassBands classBands
-
bcBands
private BcBands bcBands
-
fileBands
private FileBands fileBands
-
overrideDeflateHint
private boolean overrideDeflateHint
-
deflateHint
private boolean deflateHint
-
doPreRead
private boolean doPreRead
-
logLevel
private int logLevel
-
logStream
private java.io.PrintWriter logStream
-
classFilesContents
private byte[][] classFilesContents
-
fileDeflate
private boolean[] fileDeflate
-
fileIsClass
private boolean[] fileIsClass
-
internalBuffer
private java.io.InputStream internalBuffer
-
-
Method Detail
-
buildClassFile
private ClassFile buildClassFile(int classNum)
-
computeIcStored
private java.util.List<IcTuple> computeIcStored(IcTuple[] icLocal, IcTuple[] icRelevant)
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
protected AttrDefinitionBands getAttrDefinitionBands()
-
getClassBands
protected ClassBands getClassBands()
-
getConstantPool
public SegmentConstantPool getConstantPool()
-
getCpBands
protected CpBands getCpBands()
-
getIcBands
protected IcBands getIcBands()
-
getSegmentHeader
public SegmentHeader getSegmentHeader()
-
log
public void log(int logLevel, java.lang.String message)
-
overrideDeflateHint
public void overrideDeflateHint(boolean deflateHint)
Override the archive's deflate hint with the given boolean- Parameters:
deflateHint- the deflate hint to use
-
parseSegment
private void parseSegment() throws java.io.IOException, Pack200ExceptionThis performs the actual work of parsing against a non-static instance of Segment. This method is intended to run concurrently for multiple segments.- Throws:
java.io.IOException- if a problem occurs during reading from the underlying streamPack200Exception- if a problem occurs with an unexpected value or unsupported codec
-
readSegment
private void readSegment(java.io.InputStream in) throws java.io.IOException, Pack200ExceptionThis 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:
java.io.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)
-
setLogStream
public void setLogStream(java.io.OutputStream logStream)
-
setPreRead
public void setPreRead(boolean value)
-
unpack
public void unpack(java.io.InputStream inputStream, java.util.jar.JarOutputStream out) throws java.io.IOException, Pack200ExceptionUnpacks 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 unpackingjava.io.IOException- if there is a problem with I/O during unpacking
-
unpackProcess
void unpackProcess() throws java.io.IOException, Pack200Exception- Throws:
java.io.IOExceptionPack200Exception
-
unpackRead
void unpackRead(java.io.InputStream inputStream) throws java.io.IOException, Pack200Exception- Throws:
java.io.IOExceptionPack200Exception
-
unpackWrite
void unpackWrite(java.util.jar.JarOutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
writeJar
public void writeJar(java.util.jar.JarOutputStream out) throws java.io.IOExceptionWrites 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 (e.g. further segments) to be written.- Parameters:
out- the JarOutputStream to write data to- Throws:
java.io.IOException- if an error occurs while reading or writing to the streams
-
-