Module org.xbib.rpm

Class AbstractHeader

java.lang.Object
org.xbib.rpm.header.AbstractHeader
Direct Known Subclasses:
Header, SignatureHeader

public abstract class AbstractHeader extends Object
  • Field Details

  • Constructor Details

    • AbstractHeader

      public AbstractHeader()
  • Method Details

    • pad

      protected abstract boolean pad()
    • read

      public int read(ReadableByteChannel in) throws IOException
      Reads the entire header contents for this channel and returns the number of entries found.
      Parameters:
      in - the ReadableByteChannel to read
      Returns:
      the number read
      Throws:
      IOException - there was an IO error
    • write

      public int write(WritableByteChannel out) throws IOException
      Writes this header section to the provided file at the current position and returns the required padding. The caller is responsible for adding the padding immediately after this data.
      Parameters:
      out - the WritableByteChannel to output to
      Returns:
      the number written
      Throws:
      IOException - there was an IO error
    • getEntries

      public Map<Integer,SpecEntry<?>> getEntries()
    • count

      public int count()
    • getEntry

      public SpecEntry<?> getEntry(EntryType entryType)
    • getEntry

      public SpecEntry<?> getEntry(int code)
    • createEntry

      public void createEntry(EntryType entryType, CharSequence value)
    • createEntry

      public void createEntry(EntryType entryType, Integer value)
    • writePending

      public void writePending(SeekableByteChannel channel)
    • createEntry

      public <T> void createEntry(EntryType entryType, T values)
      This is the main entry point through which entries are created from the builder code for types other than String.
      Type Parameters:
      T - type parameter
      Parameters:
      entryType - the Tag identifying the type of header this is bound for
      values - the values to be stored in the entry.
      Throws:
      ClassCastException - - if the type of values is not compatible with the type required by tag
    • addOrAppendEntry

      public <T> void addOrAppendEntry(EntryType entryType, T values)
      This is the main entry point through which entries are created or appended to from the builder or from places like the ChangelogHandler. This is useful for header types which may have multiple components of each tag, as changelogs do.
      Type Parameters:
      T - type parameter
      Parameters:
      entryType - the Tag identifying the type of header this is bound for
      values - the values to be stored in or appended to the entry.
      Throws:
      ClassCastException - - if the type of values is not compatible with the type required by tag
    • addEntry

      public SpecEntry<?> addEntry(EntryType entryType, int count)
      Adds a pending entry to this header. This entry will have the correctly sized buffer allocated, but will not be written until the caller writes a value and then invokes writePending(java.nio.channels.SeekableByteChannel) on this object.
      Parameters:
      entryType - the tag
      count - the count
      Returns:
      the entry added
    • getEndPos

      public int getEndPos()
    • setEndPos

      public void setEndPos(int endPos)
    • getStartPos

      public int getStartPos()
    • setStartPos

      public void setStartPos(int startPos)
    • getHeader

      protected ByteBuffer getHeader()
      Memory maps the portion of the destination file that will contain the header structure header and advances the file channels position. The resulting buffer will be prefilled with the necesssary magic data and the correct index count, but will require an integer value to be written with the total data section size once data writing is complete. This method must be invoked before mapping the index or data sections.
      Returns:
      a buffer containing the header
    • toString

      public String toString()
      Overrides:
      toString in class Object