Class BufWriterImpl

java.lang.Object
org.glavo.classfile.impl.BufWriterImpl
All Implemented Interfaces:
BufWriter

public final class BufWriterImpl extends Object implements BufWriter
  • Constructor Details

  • Method Details

    • constantPool

      public ConstantPoolBuilder constantPool()
      Description copied from interface: BufWriter
      Returns the constant pool builder associated with this buffer.
      Specified by:
      constantPool in interface BufWriter
      Returns:
      the constant pool builder associated with this buffer
    • labelContext

      public LabelContext labelContext()
    • setLabelContext

      public void setLabelContext(LabelContext labelContext)
    • canWriteDirect

      public boolean canWriteDirect(ConstantPool other)
      Description copied from interface: BufWriter
      Returns whether the provided constant pool is index-compatible with this one. This may be because they are the same constant pool, or because this constant pool was copied from the other.
      Specified by:
      canWriteDirect in interface BufWriter
      Parameters:
      other - the other constant pool
      Returns:
      whether the provided constant pool is index-compatible with this one
    • thisClass

      public ClassEntry thisClass()
    • setThisClass

      public void setThisClass(ClassEntry thisClass)
    • writeU1

      public void writeU1(int x)
      Description copied from interface: BufWriter
      Write an unsigned byte to the buffer
      Specified by:
      writeU1 in interface BufWriter
      Parameters:
      x - the byte value
    • writeU2

      public void writeU2(int x)
      Description copied from interface: BufWriter
      Write an unsigned short to the buffer
      Specified by:
      writeU2 in interface BufWriter
      Parameters:
      x - the short value
    • writeInt

      public void writeInt(int x)
      Description copied from interface: BufWriter
      Write a signed int to the buffer
      Specified by:
      writeInt in interface BufWriter
      Parameters:
      x - the int value
    • writeFloat

      public void writeFloat(float x)
      Description copied from interface: BufWriter
      Write a float value to the buffer
      Specified by:
      writeFloat in interface BufWriter
      Parameters:
      x - the float value
    • writeLong

      public void writeLong(long x)
      Description copied from interface: BufWriter
      Write a long value to the buffer
      Specified by:
      writeLong in interface BufWriter
      Parameters:
      x - the long value
    • writeDouble

      public void writeDouble(double x)
      Description copied from interface: BufWriter
      Write a double value to the buffer
      Specified by:
      writeDouble in interface BufWriter
      Parameters:
      x - the int value
    • writeBytes

      public void writeBytes(byte[] arr)
      Description copied from interface: BufWriter
      Write the contents of a byte array to the buffer
      Specified by:
      writeBytes in interface BufWriter
      Parameters:
      arr - the byte array
    • writeBytes

      public void writeBytes(BufWriter other)
      Description copied from interface: BufWriter
      Write the contents of another BufWriter to the buffer
      Specified by:
      writeBytes in interface BufWriter
      Parameters:
      other - the other BufWriter
    • writeBytes

      public void writeBytes(byte[] arr, int start, int length)
      Description copied from interface: BufWriter
      Write a range of a byte array to the buffer
      Specified by:
      writeBytes in interface BufWriter
      Parameters:
      arr - the byte array
      start - the offset within the byte array of the range
      length - the length of the range
    • patchInt

      public void patchInt(int offset, int size, int value)
      Description copied from interface: BufWriter
      Patch a previously written integer value. Depending on the specified size, the entire value, or the low 1 or 2 bytes, may be written.
      Specified by:
      patchInt in interface BufWriter
      Parameters:
      offset - the offset at which to patch
      size - the size of the integer value being written, in bytes
      value - the integer value
    • writeIntBytes

      public void writeIntBytes(int intSize, long intValue)
      Description copied from interface: BufWriter
      Write a 1, 2, 4, or 8 byte integer value to the buffer. Depending on the specified size, the entire value, or the low 1, 2, or 4 bytes, may be written.
      Specified by:
      writeIntBytes in interface BufWriter
      Parameters:
      intSize - the size of the integer value being written, in bytes
      intValue - the integer value
    • reserveSpace

      public void reserveSpace(int freeBytes)
      Description copied from interface: BufWriter
      Ensure that the buffer has at least freeBytes bytes of unused space
      Specified by:
      reserveSpace in interface BufWriter
      Parameters:
      freeBytes - the number of bytes to reserve
    • size

      public int size()
      Description copied from interface: BufWriter
      Returns the number of bytes that have been written to the buffer.
      Specified by:
      size in interface BufWriter
      Returns:
      the number of bytes that have been written to the buffer
    • asByteBuffer

      public ByteBuffer asByteBuffer()
      Description copied from interface: BufWriter
      Returns a ByteBuffer view of the bytes in the buffer.
      Specified by:
      asByteBuffer in interface BufWriter
      Returns:
      a ByteBuffer view of the bytes in the buffer
    • copyTo

      public void copyTo(byte[] array, int bufferOffset)
      Description copied from interface: BufWriter
      Copy the contents of the buffer into a byte array.
      Specified by:
      copyTo in interface BufWriter
      Parameters:
      array - the byte array
      bufferOffset - the offset into the array at which to write the contents of the buffer
    • writeIndex

      public void writeIndex(PoolEntry entry)
      Description copied from interface: BufWriter
      Write the index of the specified constant pool entry, as a u2, to the buffer
      Specified by:
      writeIndex in interface BufWriter
      Parameters:
      entry - the constant pool entry
    • writeIndexOrZero

      public void writeIndexOrZero(PoolEntry entry)
      Description copied from interface: BufWriter
      Write the index of the specified constant pool entry, as a u2, to the buffer, or zero if the entry is null
      Specified by:
      writeIndexOrZero in interface BufWriter
      Parameters:
      entry - the constant pool entry
    • writeList

      public <T extends WritableElement<?>> void writeList(List<T> list)
      Description copied from interface: BufWriter
      Write a list of entities to the buffer. The length of the list is written as a u2, followed by the bytes corresponding to each element in the list. Writing of the entities is delegated to the entry.
      Specified by:
      writeList in interface BufWriter
      Type Parameters:
      T - the type of entity
      Parameters:
      list - the entities
    • writeListIndices

      public void writeListIndices(List<? extends PoolEntry> list)
      Description copied from interface: BufWriter
      Write a list of constant pool entry indexes to the buffer. The length of the list is written as a u2, followed by a u2 for each entry in the list.
      Specified by:
      writeListIndices in interface BufWriter
      Parameters:
      list - the list of entries