Class DLSequenceGenerator


public class DLSequenceGenerator extends DLGenerator
A stream generator for definite-length SEQUENCEs. The caller commits to the total length of the SEQUENCE body up front; the header is written immediately and the body then streams through getRawOutputStream() / addObject(ASN1Encodable). close() verifies the body came out at exactly the promised length and throws an IOException otherwise — by then the output is not usable, but every length mismatch is a caller arithmetic bug that must not pass silently.

Unlike DERSequenceGenerator nothing is buffered, so the body may exceed the size of a Java array; the trade-off is that the length has to be known before any content is produced.

  • Constructor Details

    • DLSequenceGenerator

      public DLSequenceGenerator(OutputStream out, long bodyLength) throws IOException
      Use the passed in stream as the target for the generator, writing out the header for a definite-length constructed SEQUENCE.
      Parameters:
      out - target stream
      bodyLength - the exact number of content octets that will be written
      Throws:
      IOException - if the target stream cannot be written to.
    • DLSequenceGenerator

      public DLSequenceGenerator(OutputStream out, int tagNo, boolean isExplicit, long bodyLength) throws IOException
      Use the passed in stream as the target for the generator, writing out the header for a tagged definite-length constructed SEQUENCE (possibly implicit).
      Parameters:
      out - target stream
      tagNo - the tag number to introduce
      isExplicit - true if this is an explicitly tagged object, false otherwise.
      bodyLength - the exact number of content octets that will be written
      Throws:
      IOException - if the target stream cannot be written to.
  • Method Details

    • getRawOutputStream

      public OutputStream getRawOutputStream()
      Return the target stream for the SEQUENCE body. Writes are counted against the length declared at construction; writing past it fails immediately.
      Overrides:
      getRawOutputStream in class DLGenerator
      Returns:
      the stream that is directly encoded to.
    • addObject

      public void addObject(ASN1Encodable object) throws IOException
      Add the DL encoding of the passed in object to the SEQUENCE body.
      Throws:
      IOException
    • close

      public void close() throws IOException
      Verify the declared body length was written in full.
      Throws:
      IOException - if fewer content octets were written than declared.