org.apache.commons.compress.harmony.unpack200

## Class Segment

- java.lang.Object
- - org.apache.commons.compress.harmony.unpack200.Segment

-     public class Segment
      extends Object

  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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `LOG_LEVEL_QUIET`
    `static int` | `LOG_LEVEL_STANDARD`
    `static int` | `LOG_LEVEL_VERBOSE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Segment()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected AttrDefinitionBands` | `getAttrDefinitionBands()`
    `protected ClassBands` | `getClassBands()`
    `SegmentConstantPool` | `getConstantPool()`
    `protected CpBands` | `getCpBands()`
    `protected IcBands` | `getIcBands()`
    `SegmentHeader` | `getSegmentHeader()`
    `void` | `log(int logLevel, String message)`
    `void` | `overrideDeflateHint(boolean deflateHint)` Override the archive's deflate hint with the given boolean
    `void` | `setLogLevel(int logLevel)`
    `void` | `setLogStream(OutputStream logStream)`
    `void` | `setPreRead(boolean value)`
    `void` | `unpack(InputStream in, JarOutputStream out)` Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding JarOuputStream.
    `void` | `writeJar(JarOutputStream out)` Writes the segment to an output stream.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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

  - ### Constructor Detail

    - #### Segment

          public Segment()

  - ### Method Detail

    - #### unpack

          public void unpack(InputStream in,
                             JarOutputStream out)
                      throws IOException,
                             Pack200Exception

      Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding JarOuputStream.
      Parameters:
        `in` - a packed stream.
        `out` - output stream.
      Throws:
        `Pack200Exception` - if there is a problem unpacking
        `IOException` - if there is a problem with I/O during unpacking

    - #### writeJar

          public void writeJar(JarOutputStream out)
                        throws IOException,
                               Pack200Exception

      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` - the JarOutputStream to write data to
      Throws:
        `IOException` - if an error occurs while reading or writing to the streams
        `Pack200Exception` - if an error occurs while processing data

    - #### getConstantPool

          public SegmentConstantPool getConstantPool()

    - #### getSegmentHeader

          public SegmentHeader getSegmentHeader()

    - #### setPreRead

          public void setPreRead(boolean value)

    - #### getAttrDefinitionBands

          protected AttrDefinitionBands getAttrDefinitionBands()

    - #### getClassBands

          protected ClassBands getClassBands()

    - #### getCpBands

          protected CpBands getCpBands()

    - #### getIcBands

          protected IcBands getIcBands()

    - #### setLogLevel

          public void setLogLevel(int logLevel)

    - #### setLogStream

          public void setLogStream(OutputStream logStream)

    - #### log

          public void log(int logLevel,
                          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

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.