Top Description Fields Constructors Methods
org.apache.commons.compress.harmony.unpack200

public Class Segment

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .ByteArrayInputStream, .ByteArrayOutputStream, .DataOutputStream, .IOException, .InputStream, .OutputStream, .OutputStreamWriter, .PrintWriter, java.nio.charset.Charset, java.util.ArrayList, .HashSet, .List, .Set, .TimeZone, java.util.jar.JarEntry, .JarOutputStream, java.util.zip.CRC32, .GZIPInputStream, .ZipEntry, org.apache.commons.compress.harmony.pack200.Codec, .Pack200Exception, org.apache.commons.compress.harmony.unpack200.bytecode.Attribute, .CPClass, .CPField, .CPMethod, .CPUTF8, .ClassConstantPool, .ClassFile, .ClassFileEntry, .InnerClassesAttribute, .SourceFileAttribute, org.apache.commons.io.input.BoundedInputStream

A 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 (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.

Field Summary

Modifier and TypeField and Description
private AttrDefinitionBands
private BcBands
private ClassBands
private byte[][]
private CpBands
private boolean
private boolean
private FileBands
private boolean[]
private boolean[]
private SegmentHeader
private IcBands
private InputStream
public static final int
public static final int
public static final int
private int
private PrintWriter
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private ClassFile
buildClassFile(final int classNum)

private List<IcTuple>

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.
computeIcStored
(final IcTuple[]
IcTuple[] array of local transmitted tuples
icLocal
,
final IcTuple[]
IcTuple[] array of relevant tuples
icRelevant
)

Given an ic_local and an ic_relevant, use them to calculate what should be added as ic_stored.

protected AttrDefinitionBands
protected ClassBands
public SegmentConstantPool
protected CpBands
protected IcBands
public SegmentHeader
public void
log(final int logLevel, final String message)

public void
overrideDeflateHint(final boolean
- the deflate hint to use
deflateHint
)

Override the archive's deflate hint with the given boolean

private void
parseSegment()

This performs the actual work of parsing against a non-static instance of Segment.

private void
readSegment(final InputStream
the input stream to read from
in
)

This performs reading the data from the stream into non-static instance of Segment.

public void
setLogLevel(final int logLevel)

public void
setLogStream(final OutputStream logStream)

public void
setPreRead(final boolean value)

public void
unpack(final InputStream
a packed input stream, preferably a BoundedInputStream.
inputStream
,
final JarOutputStream
output stream.
out
)

Unpacks a packed stream (either .pack.

pack-priv void
pack-priv void
unpackRead(final InputStream inputStream)

pack-priv void
public void
writeJar(final JarOutputStream
the JarOutputStream to write data to
out
)

Writes the segment to an output stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attrDefinitionBandsback to summary
private AttrDefinitionBands attrDefinitionBands
bcBandsback to summary
private BcBands bcBands
classBandsback to summary
private ClassBands classBands
classFilesContentsback to summary
private byte[][] classFilesContents
cpBandsback to summary
private CpBands cpBands
deflateHintback to summary
private boolean deflateHint
doPreReadback to summary
private boolean doPreRead
fileBandsback to summary
private FileBands fileBands
fileDeflateback to summary
private boolean[] fileDeflate
fileIsClassback to summary
private boolean[] fileIsClass
icBandsback to summary
private IcBands icBands
internalBufferback to summary
private InputStream internalBuffer
LOG_LEVEL_QUIETback to summary
public static final int LOG_LEVEL_QUIET
LOG_LEVEL_STANDARDback to summary
public static final int LOG_LEVEL_STANDARD
LOG_LEVEL_VERBOSEback to summary
public static final int LOG_LEVEL_VERBOSE
logLevelback to summary
private int logLevel
logStreamback to summary
private PrintWriter logStream
overrideDeflateHintback to summary
private boolean overrideDeflateHint

Constructor Detail

Segmentback to summary
public Segment()

Method Detail

buildClassFileback to summary
private ClassFile buildClassFile(final int classNum)
computeIcStoredback to summary
private List<IcTuple> computeIcStored(final IcTuple[] icLocal, final IcTuple[] icRelevant)

Given an ic_local and an ic_relevant, use them to calculate what should be added as ic_stored.

Parameters
icLocal:IcTuple[]

IcTuple[] array of local transmitted tuples

icRelevant:IcTuple[]

IcTuple[] array of relevant tuples

Returns:List<IcTuple>

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.

getAttrDefinitionBandsback to summary
protected AttrDefinitionBands getAttrDefinitionBands()
getClassBandsback to summary
protected ClassBands getClassBands()
getConstantPoolback to summary
public SegmentConstantPool getConstantPool()
getCpBandsback to summary
protected CpBands getCpBands()
getIcBandsback to summary
protected IcBands getIcBands()
getSegmentHeaderback to summary
public SegmentHeader getSegmentHeader()
logback to summary
public void log(final int logLevel, final String message)
overrideDeflateHintback to summary
public void overrideDeflateHint(final boolean deflateHint)

Override the archive's deflate hint with the given boolean

Parameters
deflateHint:boolean

- the deflate hint to use

parseSegmentback to summary
private void parseSegment() throws IOException, Pack200Exception

This performs the actual work of parsing against a non-static instance of Segment. This method is intended to run concurrently for multiple segments.

Exceptions
IOException:
if a problem occurs during reading from the underlying stream
Pack200Exception:
if a problem occurs with an unexpected value or unsupported codec
readSegmentback to summary
private void readSegment(final InputStream in) throws IOException, Pack200Exception

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:InputStream

the input stream to read from

Exceptions
IOException:
if a problem occurs during reading from the underlying stream
Pack200Exception:
if a problem occurs with an unexpected value or unsupported codec
setLogLevelback to summary
public void setLogLevel(final int logLevel)
setLogStreamback to summary
public void setLogStream(final OutputStream logStream)
setPreReadback to summary
public void setPreRead(final boolean value)
unpackback to summary
public void unpack(final InputStream inputStream, final JarOutputStream out) throws IOException, Pack200Exception

Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding JarOuputStream.

Parameters
inputStream:InputStream

a packed input stream, preferably a BoundedInputStream.

out:JarOutputStream

output stream.

Exceptions
IOException:
if there is a problem with I/O during unpacking
Pack200Exception:
if there is a problem unpacking
unpackProcessback to summary
pack-priv void unpackProcess() throws IOException, Pack200Exception
unpackReadback to summary
pack-priv void unpackRead(final InputStream inputStream) throws IOException, Pack200Exception
unpackWriteback to summary
pack-priv void unpackWrite(final JarOutputStream out) throws IOException
writeJarback to summary
public void writeJar(final JarOutputStream out) throws IOException

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 (e.g. further segments) to be written.

Parameters
out:JarOutputStream

the JarOutputStream to write data to

Exceptions
IOException:
if an error occurs while reading or writing to the streams