Class BinaryStubBundle

java.lang.Object
org.checkerframework.framework.stub.BinaryStubBundle

public class BinaryStubBundle extends Object
In-memory index of a binary stub bundle: a single file combining the binary form of every .astub file under one -Astubs directory, as written by BinaryStubFileGenerator's --bundle mode. Conventionally named with the SUFFIX suffix, as a sibling of the directory it covers.

A bundle is a container, not a merged BinaryStubData: each entry holds the exact bytes a per-file .astub.bin.gz would, generated independently, so each entry has its own constant and annotation pools whose indices are meaningful only within that entry. Entry bytes are read eagerly; get(java.lang.String) parses an entry into a BinaryStubData only when requested.

The binary format consists of:

  1. A 4-byte magic number (MAGIC).
  2. A 2-byte version number.
  3. An entry count.
  4. For each entry: its slash-separated path (relative to the bundled directory), a 4-byte byte length, and that many raw bytes -- the complete, independently gzip-compressed contents a per-file .astub.bin.gz would hold for that source file.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Magic number identifying a binary stub bundle.
    static final String
    File-name suffix appended to a source stub directory's name to name the bundle covering it (e.g.
    static final short
    Format version of the bundle container.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Reads a bundle's directory of entries from the given stream.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(String relativePath)
    Returns true if the bundle has an entry for relativePath, without parsing it, unlike get(java.lang.String).
    get(String relativePath)
    Returns the binary stub data for the entry at relativePath, parsing it on this call.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAGIC

      public static final int MAGIC
      Magic number identifying a binary stub bundle.
      See Also:
    • VERSION

      public static final short VERSION
      Format version of the bundle container.
      See Also:
    • SUFFIX

      public static final String SUFFIX
      File-name suffix appended to a source stub directory's name to name the bundle covering it (e.g. a -Astubs directory named mystubs → sibling file mystubs.astub.bin.gz).
      See Also:
  • Constructor Details

    • BinaryStubBundle

      public BinaryStubBundle(InputStream in) throws IOException
      Reads a bundle's directory of entries from the given stream.
      Parameters:
      in - the input stream to read from; the stream is closed when this constructor returns
      Throws:
      IOException - if the stream cannot be read or contains an invalid/unsupported format
  • Method Details

    • get

      public @Nullable BinaryStubData get(String relativePath) throws IOException
      Returns the binary stub data for the entry at relativePath, parsing it on this call. The result is not cached.
      Parameters:
      relativePath - the entry's path, relative to the bundled directory, with '/' as separator
      Returns:
      the entry's binary stub data, or null if the bundle has no entry for that path
      Throws:
      IOException - if the entry's bytes cannot be parsed as binary stub data
    • contains

      public boolean contains(String relativePath)
      Returns true if the bundle has an entry for relativePath, without parsing it, unlike get(java.lang.String).
      Parameters:
      relativePath - the entry's path, relative to the bundled directory, with '/' as separator
      Returns:
      true if the bundle has an entry for relativePath