Class BlobPart

All Implemented Interfaces:
PropertyChangeSource, Rebindable
Direct Known Subclasses:
ModelBlobPart, UserBlobPart

public abstract class BlobPart extends AbstractPart
An abstract base class for binary data parts, such as an image or a document. It can be created from raw bytes or directly from a file path, in which case it retains a reference to the source path for traceability.
Author:
anahata
  • Field Details

    • mimeType

      @NonNull private final @NonNull String mimeType
      The MIME type of the data (e.g., "image/png", "application/pdf").
    • data

      @NonNull private final @NonNull byte[] data
      The raw binary data.
    • sourcePath

      private Path sourcePath
      The original source path if this blob was created from a file. Can be null.
  • Constructor Details

    • BlobPart

      public BlobPart(@NonNull @NonNull AbstractMessage message, @NonNull @NonNull String mimeType, @NonNull @NonNull byte[] data)
      Constructs a BlobPart from raw byte data and a specified MIME type.
      Parameters:
      message - The message this part belongs to.
      mimeType - The MIME type.
      data - The binary data.
    • BlobPart

      protected BlobPart(@NonNull @NonNull AbstractMessage message, @NonNull @NonNull String mimeType, @NonNull @NonNull byte[] data, @NonNull @NonNull Path sourcePath)
      Internal constructor for BlobParts with a source path.
      Parameters:
      message - The parent message.
      mimeType - The MIME type.
      data - The binary data.
      sourcePath - The source file path.
  • Method Details

    • asText

      public String asText()
      Description copied from class: AbstractPart
      Returns the content of the part as a simple string. This is implemented by subclasses.
      Specified by:
      asText in class AbstractPart
      Returns:
      The text representation of the part.
    • getPrunedHint

      public String getPrunedHint()
      Returns a summarized string representation of the part's content to be used as a "Hint" when the part is effectively pruned. Defaults to a formatted version of AbstractPart.asText(). Provides essential binary metadata (MIME and Size) when the content is pruned.
      Overrides:
      getPrunedHint in class AbstractPart
      Returns:
      The pruned hint string.
    • calculateTokenCount

      protected void calculateTokenCount()
      Performs the lazy, model-specific token calculation for this part. This is implemented by subclasses to perform the actual calculation.

      Calculates the multimodal token count for this binary part using the active model.

      Specified by:
      calculateTokenCount in class AbstractPart
    • appendMetadata

      protected void appendMetadata(StringBuilder sb)
      Hook for subclasses to inject specialized metadata into the part header. Always includes the source path in the metadata header if available, ensuring semantic continuity even when pruned.
      Overrides:
      appendMetadata in class AbstractPart
      Parameters:
      sb - The StringBuilder building the header.
    • getDefaultMaxDepth

      protected int getDefaultMaxDepth()
      Description copied from class: AbstractPart
      Template method hook for subclasses to provide their specific default max depth policy. This is the fallback value used when no explicit maxDepth is set on the instance.
      Specified by:
      getDefaultMaxDepth in class AbstractPart
      Returns:
      The default maximum depth for this part type.