Class ObjectBuilder

    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectBuilder()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract byte[] build()
      Format this builder's state as a git object.
      protected PersonIdent getAuthor()
      Retrieves the author of this object.
      java.nio.charset.Charset getEncoding()
      Retrieves the encoding that should be used for the message text.
      GpgSignature getGpgSignature()
      Retrieves the GPG signature of this object.
      java.lang.String getMessage()
      Retrieves the complete message of the object.
      protected void setAuthor​(PersonIdent newAuthor)
      Sets the author (name, email address, and date) of this object.
      void setEncoding​(java.nio.charset.Charset encoding)
      Sets the encoding for the object message.
      void setGpgSignature​(GpgSignature gpgSignature)
      Sets the GPG signature of this object.
      void setMessage​(java.lang.String message)
      Sets the message (commit message, or message of an annotated tag).
      (package private) static void writeEncoding​(java.nio.charset.Charset encoding, java.io.OutputStream out)
      Writes an "encoding" header.
      (package private) static void writeMultiLineHeader​(java.lang.String in, java.io.OutputStream out, boolean enforceAscii)
      Writes signature to output as per gpgsig header.
      • Methods inherited from class java.lang.Object

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

      • hencoding

        private static final byte[] hencoding
        Byte representation of "encoding".
      • message

        private java.lang.String message
      • encoding

        private java.nio.charset.Charset encoding
    • Constructor Detail

      • ObjectBuilder

        public ObjectBuilder()
    • Method Detail

      • getAuthor

        protected PersonIdent getAuthor()
        Retrieves the author of this object.
        Returns:
        the author of this object, or null if not set yet
      • setAuthor

        protected void setAuthor​(PersonIdent newAuthor)
        Sets the author (name, email address, and date) of this object.
        Parameters:
        newAuthor - the new author, must be non-null
      • setGpgSignature

        public void setGpgSignature​(@Nullable
                                    GpgSignature gpgSignature)
        Sets the GPG signature of this object.

        Note, the signature set here will change the payload of the object, i.e. the output of build() will include the signature. Thus, the typical flow will be:

        1. call build() without a signature set to obtain payload
        2. create GpgSignature from payload
        3. set GpgSignature

        Parameters:
        gpgSignature - the signature to set or null to unset
        Since:
        5.3
      • getGpgSignature

        @Nullable
        public GpgSignature getGpgSignature()
        Retrieves the GPG signature of this object.
        Returns:
        the GPG signature of this object, or null if the object is not signed
        Since:
        5.3
      • getMessage

        @Nullable
        public java.lang.String getMessage()
        Retrieves the complete message of the object.
        Returns:
        the complete message; can be null.
      • setMessage

        public void setMessage​(@Nullable
                               java.lang.String message)
        Sets the message (commit message, or message of an annotated tag).
        Parameters:
        message - the message.
      • getEncoding

        @NonNull
        public java.nio.charset.Charset getEncoding()
        Retrieves the encoding that should be used for the message text.
        Returns:
        the encoding that should be used for the message text.
      • setEncoding

        public void setEncoding​(@NonNull
                                java.nio.charset.Charset encoding)
        Sets the encoding for the object message.
        Parameters:
        encoding - the encoding to use.
      • build

        @NonNull
        public abstract byte[] build()
                              throws java.io.UnsupportedEncodingException
        Format this builder's state as a git object.
        Returns:
        this object in the canonical git format, suitable for storage in a repository.
        Throws:
        java.io.UnsupportedEncodingException - the encoding specified by getEncoding() is not supported by this Java runtime.
      • writeMultiLineHeader

        static void writeMultiLineHeader​(@NonNull
                                         java.lang.String in,
                                         @NonNull
                                         java.io.OutputStream out,
                                         boolean enforceAscii)
                                  throws java.io.IOException,
                                         java.lang.IllegalArgumentException
        Writes signature to output as per gpgsig header.

        CRLF and CR will be sanitized to LF and signature will have a hanging indent of one space starting with line two. A trailing line break is not written; the caller is supposed to terminate the GPG signature header by writing a single newline.

        Parameters:
        in - signature string with line breaks
        out - output stream
        enforceAscii - whether to throw IllegalArgumentException if non-ASCII characters are encountered
        Throws:
        java.io.IOException - thrown by the output stream
        java.lang.IllegalArgumentException - if the signature string contains non 7-bit ASCII chars and enforceAscii == true
      • writeEncoding

        static void writeEncoding​(@NonNull
                                  java.nio.charset.Charset encoding,
                                  @NonNull
                                  java.io.OutputStream out)
                           throws java.io.IOException
        Writes an "encoding" header.
        Parameters:
        encoding - to write
        out - to write to
        Throws:
        java.io.IOException - if writing fails