Package org.apache.commons.compress.harmony.unpack200.bytecode

# Class ByteCode

java.lang.Object
org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry
org.apache.commons.compress.harmony.unpack200.bytecode.ByteCode

public class ByteCode extends ClassFileEntry
A bytecode class file entry.

- ## Field Summary

  ### Fields inherited from class org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry

  `NONE`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `ByteCode(int opcode)`
  `protected`
  `ByteCode(int opcode, ClassFileEntry[] nested)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `applyByteCodeTargetFixup(CodeAttribute codeAttribute)`
  Some ByteCodes (in particular, those with labels need to be fixed up after all the bytecodes in the CodeAttribute have been added.
  `protected void`
  `doWrite(DataOutputStream dos)`
  Writes this instance to the output stream.
  `boolean`
  `equals(Object obj)`
  `void`
  `extractOperands(OperandManager operandManager, Segment segment, int codeLength)`
  `static ByteCode`
  `getByteCode(int opcode)`
  `protected ByteCodeForm`
  `getByteCodeForm()`
  `int`
  `getByteCodeIndex()`
  `int[]`
  `getByteCodeTargets()`
  `int`
  `getLength()`
  `String`
  `getName()`
  `ClassFileEntry[]`
  `getNestedClassFileEntries()`
  Returns an empty array.
  `int[]`
  `getNestedPosition(int index)`
  `int[][]`
  `getNestedPositions()`
  `int`
  `getOpcode()`
  `int[]`
  `getRewrite()`
  Some bytecodes (the ones with variable lengths) can't have a static rewrite array - they need the ability to update the array.
  `int`
  `hashCode()`
  `boolean`
  `hasMultipleByteCodes()`
  This method will answer true if the receiver is a multi-bytecode instruction (such as aload0_putfield_super); otherwise, it will answer false.
  `boolean`
  `nestedMustStartClassPool()`
  `protected void`
  `resolve(ClassConstantPool pool)`
  Allows the constant pool entries to resolve their nested entries.
  `void`
  `setByteCodeIndex(int byteCodeOffset)`
  ByteCodes may need to know their position in the code array (in particular, label byte codes need to know where they are in order to calculate their targets).
  `void`
  `setByteCodeTargets(int[] byteCodeTargets)`
  Some ByteCodes (in particular, those with labels) have to keep track of byteCodeTargets.
  `void`
  `setNested(ClassFileEntry[] nested)`
  `void`
  `setNestedPositions(int[][] nestedPositions)`
  nestedPositions is an array of arrays of ints.
  `void`
  `setOperand2Bytes(int operand, int position)`
  Given an int operand, set the rewrite bytes for that position and the one immediately following it to a high-byte, low-byte encoding of the operand.
  `void`
  `setOperandByte(int operand, int position)`
  Given an int operand, treat it as a byte and set the rewrite byte for that position to that value.
  `void`
  `setOperandBytes(int[] operands)`
  Given an array of ints which correspond to bytes in the operand of the bytecode, set the rewrite bytes of the operand to be the appropriate values.
  `void`
  `setOperandSigned2Bytes(int operand, int position)`
  This is just like setOperandInt, but takes special care when the operand is less than 0 to make sure it's written correctly.
  `void`
  `setRewrite(int[] rewrite)`
  Some bytecodes (the ones with variable lengths) can't have a static rewrite array - they need the ability to update the array.
  `String`
  `toString()`

  ### Methods inherited from class org.apache.commons.compress.harmony.unpack200.bytecode.ClassFileEntry

  `objectHashCode, write`

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

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### ByteCode

    protected ByteCode(int opcode)

  - ### ByteCode

    protected ByteCode(int opcode, ClassFileEntry[] nested)

- ## Method Details

  - ### getByteCode

    public static ByteCode getByteCode(int opcode)

  - ### applyByteCodeTargetFixup

    public void applyByteCodeTargetFixup(CodeAttribute codeAttribute)
    Some ByteCodes (in particular, those with labels need to be fixed up after all the bytecodes in the CodeAttribute have been added. (This can't be done beforehand because the CodeAttribute needs to be complete before targets can be assigned.)
    Parameters:
      `codeAttribute` - the code attribute

  - ### doWrite

    protected void doWrite(DataOutputStream dos) throws IOException
    Description copied from class: `ClassFileEntry`
    Writes this instance to the output stream.
    Specified by:
      `doWrite` in class `ClassFileEntry`
    Parameters:
      `dos` - the output stream.
    Throws:
      `IOException` - if an I/O error occurs.

  - ### equals

    public boolean equals(Object obj)
    Specified by:
      `equals` in class `ClassFileEntry`

  - ### extractOperands

    public void extractOperands(OperandManager operandManager, Segment segment, int codeLength) throws Pack200Exception
    Throws:
      `Pack200Exception`

  - ### getByteCodeForm

    protected ByteCodeForm getByteCodeForm()

  - ### getByteCodeIndex

    public int getByteCodeIndex()

  - ### getByteCodeTargets

    public int[] getByteCodeTargets()

  - ### getLength

    public int getLength()

  - ### getName

    public String getName()

  - ### getNestedClassFileEntries

    public ClassFileEntry[] getNestedClassFileEntries()
    Description copied from class: `ClassFileEntry`
    Returns an empty array.
    Overrides:
      `getNestedClassFileEntries` in class `ClassFileEntry`
    Returns:
      an empty array.

  - ### getNestedPosition

    public int[] getNestedPosition(int index)

  - ### getNestedPositions

    public int[][] getNestedPositions()

  - ### getOpcode

    public int getOpcode()

  - ### getRewrite

    public int[] getRewrite()
    Some bytecodes (the ones with variable lengths) can't have a static rewrite array - they need the ability to update the array. This method permits their associated bytecode formst to query their rewrite array. Note that this should not be called from bytecodes which have a static rewrite; use the table in ByteCodeForm instead to specify those rewrites.
    Returns:
      Some bytecodes.

  - ### hashCode

    public int hashCode()
    Specified by:
      `hashCode` in class `ClassFileEntry`

  - ### hasMultipleByteCodes

    public boolean hasMultipleByteCodes()
    This method will answer true if the receiver is a multi-bytecode instruction (such as aload0_putfield_super); otherwise, it will answer false.
    Returns:
      boolean true if multibytecode, false otherwise

  - ### nestedMustStartClassPool

    public boolean nestedMustStartClassPool()

  - ### resolve

    protected void resolve(ClassConstantPool pool)
    Description copied from class: `ClassFileEntry`
    Allows the constant pool entries to resolve their nested entries.
    Overrides:
      `resolve` in class `ClassFileEntry`
    Parameters:
      `pool` - The class constant pool.

  - ### setByteCodeIndex

    public void setByteCodeIndex(int byteCodeOffset)
    ByteCodes may need to know their position in the code array (in particular, label byte codes need to know where they are in order to calculate their targets). This method lets the CodeAttribute specify where the byte code is. Since there are no aload0+label instructions, this method doesn't worry about multioperation bytecodes.
    Parameters:
      `byteCodeOffset` - int position in code array.

  - ### setByteCodeTargets

    public void setByteCodeTargets(int[] byteCodeTargets)
    Some ByteCodes (in particular, those with labels) have to keep track of byteCodeTargets. These are initially offsets in the CodeAttribute array relative to the byteCodeOffset, but later get fixed up to point to the absolute position in the CodeAttribute array. This method sets the targets.
    Parameters:
      `byteCodeTargets` - int index in array

  - ### setNested

    public void setNested(ClassFileEntry[] nested)

  - ### setNestedPositions

    public void setNestedPositions(int[][] nestedPositions)
    nestedPositions is an array of arrays of ints. Each subarray specifies a position of a nested element (from the nested[] array) and the length of that element. For instance, one might have a nested of: {CPClass java/lang/Foo, CPFloat 3.14} The nestedPositions would then be: {{0,2},{2,2}} In other words, when the bytecode is resolved, the CPClass will be resolved to an int and inserted at position 0 and 1 of the rewrite arguments (the first occurrences of -1). The CPFloat will be resolved to an int position and inserted at positions 2 and 3 of the rewrite arguments.
    Parameters:
      `nestedPositions` - Each subarray specifies a position of a nested element (from the nested[] array) and the length of that element.

  - ### setOperand2Bytes

    public void setOperand2Bytes(int operand, int position)
    Given an int operand, set the rewrite bytes for that position and the one immediately following it to a high-byte, low-byte encoding of the operand.
    Parameters:
      `operand` - int to set the rewrite bytes to
      `position` - int position in the operands of the rewrite bytes. For a rewrite array of {100, -1, -1, -1} position 0 is the first -1, position 1 is the second -1, etc.

  - ### setOperandByte

    public void setOperandByte(int operand, int position)
    Given an int operand, treat it as a byte and set the rewrite byte for that position to that value. Mask of anything beyond 0xFF.
    Parameters:
      `operand` - int to set the rewrite byte to (unsigned)
      `position` - int position in the operands of the rewrite bytes. For a rewrite array of {100, -1, -1, -1} position 0 is the first -1, position 1 is the second -1, etc.

  - ### setOperandBytes

    public void setOperandBytes(int[] operands)
    Given an array of ints which correspond to bytes in the operand of the bytecode, set the rewrite bytes of the operand to be the appropriate values. All values in operands[] will be masked with 0xFF so they fit into a byte.
    Parameters:
      `operands` - int[] rewrite operand bytes

  - ### setOperandSigned2Bytes

    public void setOperandSigned2Bytes(int operand, int position)
    This is just like setOperandInt, but takes special care when the operand is less than 0 to make sure it's written correctly.
    Parameters:
      `operand` - int to set the rewrite bytes to
      `position` - int position of the operands in the rewrite bytes

  - ### setRewrite

    public void setRewrite(int[] rewrite)
    Some bytecodes (the ones with variable lengths) can't have a static rewrite array - they need the ability to update the array. This method permits that. Note that this should not be called from bytecodes which have a static rewrite; use the table in ByteCodeForm instead to specify those rewrites.
    Parameters:
      `rewrite` - Some bytecodes.

  - ### toString

    public String toString()
    Specified by:
      `toString` in class `ClassFileEntry`