public class NoteMap extends Object implements Iterable<Note>
ObjectReader
that it
borrows/shares with the caller. The reader can be used during any call, and
is not released by this class. The caller should arrange for releasing the
shared ObjectReader
at the proper times.Modifier and Type | Method and Description |
---|---|
boolean |
contains(AnyObjectId id)
Determine if a note exists for the specified ObjectId.
|
ObjectId |
get(AnyObjectId id)
Lookup a note for a specific ObjectId.
|
byte[] |
getCachedBytes(AnyObjectId id,
int sizeLimit)
Open and return the content of an object's note.
|
Note |
getNote(AnyObjectId id)
Lookup a note for a specific ObjectId.
|
Iterator<Note> |
iterator() |
static NoteMap |
newEmptyMap()
Construct a new empty note map.
|
static NoteMap |
read(ObjectReader reader,
RevCommit commit)
Load a collection of notes from a branch.
|
static NoteMap |
read(ObjectReader reader,
RevTree tree)
Load a collection of notes from a tree.
|
static NoteMap |
readTree(ObjectReader reader,
ObjectId treeId)
Load a collection of notes from a tree.
|
void |
remove(AnyObjectId noteOn)
Remove a note from an object.
|
void |
set(AnyObjectId noteOn,
ObjectId noteData)
Attach (or remove) a note on an object.
|
void |
set(AnyObjectId noteOn,
String noteData,
ObjectInserter ins)
Attach a note to an object.
|
static String |
shortenRefName(String noteRefName)
Shorten the note ref name by trimming off the
Constants.R_NOTES
prefix if it exists. |
ObjectId |
writeTree(ObjectInserter inserter)
Write this note map as a tree.
|
public static NoteMap newEmptyMap()
public static String shortenRefName(String noteRefName)
Constants.R_NOTES
prefix if it exists.noteRefName
- public static NoteMap read(ObjectReader reader, RevCommit commit) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
reader
- reader to scan the note branch with. This reader may be
retained by the NoteMap for the life of the map in order to
support lazy loading of entries.commit
- the revision of the note branch to read.IOException
- the repository cannot be accessed through the reader.CorruptObjectException
- a tree object is corrupt and cannot be read.IncorrectObjectTypeException
- a tree object wasn't actually a tree.MissingObjectException
- a reference tree object doesn't exist.public static NoteMap read(ObjectReader reader, RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
reader
- reader to scan the note branch with. This reader may be
retained by the NoteMap for the life of the map in order to
support lazy loading of entries.tree
- the note tree to read.IOException
- the repository cannot be accessed through the reader.CorruptObjectException
- a tree object is corrupt and cannot be read.IncorrectObjectTypeException
- a tree object wasn't actually a tree.MissingObjectException
- a reference tree object doesn't exist.public static NoteMap readTree(ObjectReader reader, ObjectId treeId) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
reader
- reader to scan the note branch with. This reader may be
retained by the NoteMap for the life of the map in order to
support lazy loading of entries.treeId
- the note tree to read.IOException
- the repository cannot be accessed through the reader.CorruptObjectException
- a tree object is corrupt and cannot be read.IncorrectObjectTypeException
- a tree object wasn't actually a tree.MissingObjectException
- a reference tree object doesn't exist.public ObjectId get(AnyObjectId id) throws IOException
id
- the object to look for.IOException
- a portion of the note space is not accessible.public Note getNote(AnyObjectId id) throws IOException
id
- the object to look for.IOException
- a portion of the note space is not accessible.public boolean contains(AnyObjectId id) throws IOException
id
- the object to look for.IOException
- a portion of the note space is not accessible.public byte[] getCachedBytes(AnyObjectId id, int sizeLimit) throws LargeObjectException, MissingObjectException, IOException
ObjectId dataId = thisMap.get(id); if (dataId != null) reader.open(dataId).openStream();
id
- object to lookup the note of.sizeLimit
- maximum number of bytes to return. If the note data size is
larger than this limit, LargeObjectException will be thrown.id
, the note content. If no note
is defined, null.LargeObjectException
- the note data is larger than sizeLimit
.MissingObjectException
- the note's blob does not exist in the repository.IOException
- the note's blob cannot be read from the repositorypublic void set(AnyObjectId noteOn, ObjectId noteData) throws IOException
set(AnyObjectId, String, ObjectInserter)
is a convenient
way to encode and update a note in one step.noteOn
- the object to attach the note to. This same ObjectId can later
be used as an argument to get(AnyObjectId)
or
getCachedBytes(AnyObjectId, int)
to read back the
noteData
.noteData
- data to associate with the note. This must be the ObjectId of
a blob that already exists in the repository. If null the note
will be deleted, if present.IOException
- a portion of the note space is not accessible.public void set(AnyObjectId noteOn, String noteData, ObjectInserter ins) throws IOException
noteOn
- the object to attach the note to. This same ObjectId can later
be used as an argument to get(AnyObjectId)
or
getCachedBytes(AnyObjectId, int)
to read back the
noteData
.noteData
- text to store in the note. The text will be UTF-8 encoded when
stored in the repository. If null the note will be deleted, if
the empty string a note with the empty string will be stored.ins
- inserter to write the encoded noteData
out as a blob.
The caller must ensure the inserter is flushed before the
updated note map is made available for reading.IOException
- the note data could not be stored in the repository.public void remove(AnyObjectId noteOn) throws IOException
noteOn
- the object to remove the note from.IOException
- a portion of the note space is not accessible.public ObjectId writeTree(ObjectInserter inserter) throws IOException
inserter
- inserter to use when writing trees to the object database.
Caller is responsible for flushing the inserter before trying
to read the objects, or exposing them through a reference.IOException
- a tree could not be written.Copyright © 2015 Eclipse JGit Project. All rights reserved.