Top Description Fields Constructors Methods
org.eclipse.jgit.lib

public abstract Class ObjectBuilder

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.lib.TagBuilder, org.eclipse.jgit.lib.CommitBuilder
Static Imports
java.nio.charset.StandardCharsets.UTF_8

Common base class for CommitBuilder and TagBuilder.
Since
5.11

Field Summary

Modifier and TypeField and Description
private PersonIdent
private Charset
private GpgSignature
private static final byte[]
hencoding

Byte representation of "encoding".

private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract byte[]

Returns:

this object in the canonical git format, suitable for storage in a repository.
build
()

Format this builder's state as a git object.

protected PersonIdent

Returns:

the author of this object, or null if not set yet
getAuthor
()

Retrieves the author of this object.

public Charset

Returns:

the encoding that should be used for the message text.
getEncoding
()

Retrieves the encoding that should be used for the message text.

public GpgSignature

Returns:

the GPG signature of this object, or null if the object is not signed
getGpgSignature
()

Retrieves the GPG signature of this object.

public String

Returns:

the complete message; can be null.
getMessage
()

Retrieves the complete message of the object.

protected void
setAuthor(PersonIdent
the new author, must be non-null
newAuthor
)

Sets the author (name, email address, and date) of this object.

public void
setEncoding(Charset
the encoding to use.
encoding
)

Sets the encoding for the object message.

public void
setGpgSignature(GpgSignature
the signature to set or null to unset
gpgSignature
)

Sets the GPG signature of this object.

public void
setMessage(String
the message.
message
)

Sets the message (commit message, or message of an annotated tag).

pack-priv static void
writeEncoding(Charset
to write
encoding
,
OutputStream
to write to
out
)

Writes an "encoding" header.

pack-priv static void
writeMultiLineHeader(String
signature string with line breaks
in
,
OutputStream
output stream
out
,
boolean
whether to throw IllegalArgumentException if non-ASCII characters are encountered
enforceAscii
)

Writes signature to output as per gpgsig header.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authorback to summary
private PersonIdent author
encodingback to summary
private Charset encoding
gpgSignatureback to summary
private GpgSignature gpgSignature
hencodingback to summary
private static final byte[] hencoding

Byte representation of "encoding".

messageback to summary
private String message

Constructor Detail

ObjectBuilderback to summary
public ObjectBuilder()

Method Detail

buildback to summary
public abstract byte[] build() throws UnsupportedEncodingException

Format this builder's state as a git object.

Returns:byte[]

this object in the canonical git format, suitable for storage in a repository.

Annotations
@NonNull
Exceptions
UnsupportedEncodingException:
the encoding specified by getEncoding() is not supported by this Java runtime.
getAuthorback to summary
protected PersonIdent getAuthor()

Retrieves the author of this object.

Returns:PersonIdent

the author of this object, or null if not set yet

getEncodingback to summary
public Charset getEncoding()

Retrieves the encoding that should be used for the message text.

Returns:Charset

the encoding that should be used for the message text.

Annotations
@NonNull
getGpgSignatureback to summary
public GpgSignature getGpgSignature()

Retrieves the GPG signature of this object.

Returns:GpgSignature

the GPG signature of this object, or null if the object is not signed

Annotations
@Nullable
Since
5.3
getMessageback to summary
public String getMessage()

Retrieves the complete message of the object.

Returns:String

the complete message; can be null.

Annotations
@Nullable
setAuthorback to summary
protected void setAuthor(PersonIdent newAuthor)

Sets the author (name, email address, and date) of this object.

Parameters
newAuthor:PersonIdent

the new author, must be non-null

setEncodingback to summary
public void setEncoding(Charset encoding)

Sets the encoding for the object message.

Parameters
encoding:Charset

the encoding to use.

setGpgSignatureback to summary
public void setGpgSignature(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:GpgSignature

the signature to set or null to unset

Since
5.3
setMessageback to summary
public void setMessage(String message)

Sets the message (commit message, or message of an annotated tag).

Parameters
message:String

the message.

writeEncodingback to summary
pack-priv static void writeEncoding(Charset encoding, OutputStream out) throws IOException

Writes an "encoding" header.

Parameters
encoding:Charset

to write

out:OutputStream

to write to

Exceptions
IOException:
if writing fails
writeMultiLineHeaderback to summary
pack-priv static void writeMultiLineHeader(String in, OutputStream out, boolean enforceAscii) throws IOException, 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:String

signature string with line breaks

out:OutputStream

output stream

enforceAscii:boolean

whether to throw IllegalArgumentException if non-ASCII characters are encountered

Exceptions
IOException:
thrown by the output stream
IllegalArgumentException:
if the signature string contains non 7-bit ASCII chars and enforceAscii == true