Package org.eclipse.jgit.lib
Class ObjectBuilder
- java.lang.Object
-
- org.eclipse.jgit.lib.ObjectBuilder
-
- Direct Known Subclasses:
CommitBuilder,TagBuilder
public abstract class ObjectBuilder extends java.lang.ObjectCommon base class forCommitBuilderandTagBuilder.- Since:
- 5.11
-
-
Field Summary
Fields Modifier and Type Field Description private PersonIdentauthorprivate java.nio.charset.Charsetencodingprivate GpgSignaturegpgSignatureprivate static byte[]hencodingByte representation of "encoding".private java.lang.Stringmessage
-
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 PersonIdentgetAuthor()Retrieves the author of this object.java.nio.charset.CharsetgetEncoding()Retrieves the encoding that should be used for the message text.GpgSignaturegetGpgSignature()Retrieves the GPG signature of this object.java.lang.StringgetMessage()Retrieves the complete message of the object.protected voidsetAuthor(PersonIdent newAuthor)Sets the author (name, email address, and date) of this object.voidsetEncoding(java.nio.charset.Charset encoding)Sets the encoding for the object message.voidsetGpgSignature(GpgSignature gpgSignature)Sets the GPG signature of this object.voidsetMessage(java.lang.String message)Sets the message (commit message, or message of an annotated tag).(package private) static voidwriteEncoding(java.nio.charset.Charset encoding, java.io.OutputStream out)Writes an "encoding" header.(package private) static voidwriteMultiLineHeader(java.lang.String in, java.io.OutputStream out, boolean enforceAscii)Writes signature to output as per gpgsig header.
-
-
-
Field Detail
-
hencoding
private static final byte[] hencoding
Byte representation of "encoding".
-
author
private PersonIdent author
-
gpgSignature
private GpgSignature gpgSignature
-
message
private java.lang.String message
-
encoding
private java.nio.charset.Charset encoding
-
-
Method Detail
-
getAuthor
protected PersonIdent getAuthor()
Retrieves the author of this object.- Returns:
- the author of this object, or
nullif 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:- call
build()without a signature set to obtain payload - create
GpgSignaturefrom payload - set
GpgSignature
- Parameters:
gpgSignature- the signature to set ornullto unset- Since:
- 5.3
- call
-
getGpgSignature
@Nullable public GpgSignature getGpgSignature()
Retrieves the GPG signature of this object.- Returns:
- the GPG signature of this object, or
nullif 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 bygetEncoding()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 breaksout- output streamenforceAscii- whether to throwIllegalArgumentExceptionif non-ASCII characters are encountered- Throws:
java.io.IOException- thrown by the output streamjava.lang.IllegalArgumentException- if the signature string contains non 7-bit ASCII chars andenforceAscii == true
-
-