Class SourceBundle

java.lang.Object
cs1302.tracer.api.SourceBundle

@API(status=STABLE, since="4.1.0") public final class SourceBundle extends Object
Immutable, ordered source files packaged in the tracer's delimited source format. Every file, including a single-file bundle, has a canonical // --- path.java --- header followed by LF. Original text, byte-order marks, and line endings are preserved. Before a subsequent header, one LF is added only when the preceding text does not already end with a delimiter-recognized line terminator. Empty files need no additional separator. The final file's text is not given an extra terminator.

Construction validates packaging, not compilation or entry-point availability. Explicitly named files may contain empty or invalid Java text. Inferred names require parseable source with exactly one public top-level type, or otherwise exactly one top-level type. Use source() with TraceRequest.builder(String) or an existing source-text constructor. File additions capture text immediately; later filesystem changes do not alter a built bundle. Binary dependencies are selected separately through TraceClassPath.

Logical paths name the packaged inputs. Executable locations returned in BreakpointDiscovery instead use package-relative debug source paths, which can differ from logical paths such as src/demo/Main.java.

Since:
4.1.0
See Also:
  • Method Details

    • builder

      public static SourceBundle.Builder builder()
      Creates an empty builder; add at least one file before building.
      Returns:
      A new mutable builder.
    • toBuilder

      public SourceBundle.Builder toBuilder()
      Copies the captured original paths and text into an independent builder without rereading files.
      Returns:
      A mutable builder initialized with this bundle's files in their original order.
    • source

      public String source()
      Returns the delimited source text for tracing, discovery, or other source-text consumers. Headers are part of this transport string; each file's original text follows its header. Calling this method performs no filesystem access or Java parsing.
      Returns:
      The immutable delimited source string.
    • openStream

      public InputStream openStream()
      Opens a fresh stream containing the UTF-8 encoding of source(). Each stream has independent bytes and cursor state, including when transferred to a custom output stream.
      Returns:
      A new caller-owned input stream positioned at its beginning.
    • writeUtf8

      public void writeUtf8(OutputStream destination) throws IOException
      Writes the UTF-8 encoding of source() without flushing or closing the caller's destination. The destination receives fresh bytes and cannot alter this bundle by retaining or modifying them.
      Parameters:
      destination - Caller-owned output stream.
      Throws:
      NullPointerException - If the destination is null.
      IOException - If the destination cannot accept the bytes.