Package org.eclipse.jgit.lib
Class ObjectLoader
java.lang.Object
org.eclipse.jgit.lib.ObjectLoader
- Direct Known Subclasses:
ApplyCommand.StreamLoader
,DfsInserter.StreamLoader
,LargePackedWholeObject
,LargePackedWholeObject
,LfsBlobLoader
,ObjectLoader.Filter
,ObjectLoader.SmallObject
,PackInserter.Reader.StreamLoader
,UnpackedObject.LargeObject
Base class for a set of loaders for different representations of Git objects.
New loaders are constructed for every object.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Wraps a delegate ObjectLoader.static class
Simple loader around the cached byte array. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]
cloneArray
(byte[] data) void
copyTo
(OutputStream out) Copy this object to the output stream.final byte[]
getBytes()
Obtain a copy of the bytes of this object.final byte[]
getBytes
(int sizeLimit) Obtain a copy of the bytes of this object.abstract byte[]
Obtain a reference to the (possibly cached) bytes of this object.byte[]
getCachedBytes
(int sizeLimit) Obtain a reference to the (possibly cached) bytes of this object.abstract long
getSize()
Get size of object in bytesabstract int
getType()
Get Git in pack object typeboolean
isLarge()
Whether this object is too large to obtain as a byte array.abstract ObjectStream
Obtain an input stream to read this object's data.
-
Constructor Details
-
ObjectLoader
public ObjectLoader()
-
-
Method Details
-
getType
public abstract int getType()Get Git in pack object type- Returns:
- Git in pack object type, see
Constants
.
-
getSize
public abstract long getSize()Get size of object in bytes- Returns:
- size of object in bytes
-
isLarge
public boolean isLarge()Whether this object is too large to obtain as a byte array.- Returns:
- true if this object is too large to obtain as a byte array.
Objects over a certain threshold should be accessed only by their
openStream()
to prevent overflowing the JVM heap.
-
getBytes
Obtain a copy of the bytes of this object.Unlike
getCachedBytes()
this method returns an array that might be modified by the caller.- Returns:
- the bytes of this object.
- Throws:
LargeObjectException
- if the object won't fit into a byte array, becauseisLarge()
returns true. Callers should useopenStream()
instead to access the contents.
-
getBytes
public final byte[] getBytes(int sizeLimit) throws LargeObjectException, MissingObjectException, IOException Obtain a copy of the bytes of this object. If the object size is less than or equal tosizeLimit
this method will provide it as a byte array, even ifisLarge()
is true. This utility is useful for application code that absolutely must have the object as a single contiguous byte array in memory. UnlikegetCachedBytes(int)
this method returns an array that might be modified by the caller.- Parameters:
sizeLimit
- maximum number of bytes to return. If the object is larger than this limit,LargeObjectException
will be thrown.- Returns:
- the bytes of this object.
- Throws:
LargeObjectException
- if the object is bigger thansizeLimit
, or ifOutOfMemoryError
occurs during allocation of the result array. Callers should useopenStream()
instead to access the contents.MissingObjectException
- the object is large, and it no longer exists.IOException
- the object store cannot be accessed.
-
getCachedBytes
Obtain a reference to the (possibly cached) bytes of this object.This method offers direct access to the internal caches, potentially saving on data copies between the internal cache and higher level code. Callers who receive this reference must not modify its contents. Changes (if made) will affect the cache but not the repository itself.
- Returns:
- the cached bytes of this object. Do not modify it.
- Throws:
LargeObjectException
- if the object won't fit into a byte array, becauseisLarge()
returns true. Callers should useopenStream()
instead to access the contents.
-
getCachedBytes
public byte[] getCachedBytes(int sizeLimit) throws LargeObjectException, MissingObjectException, IOException Obtain a reference to the (possibly cached) bytes of this object. If the object size is less than or equal tosizeLimit
this method will provide it as a byte array, even ifisLarge()
is true. This utility is useful for application code that absolutely must have the object as a single contiguous byte array in memory. This method offers direct access to the internal caches, potentially saving on data copies between the internal cache and higher level code. Callers who receive this reference must not modify its contents. Changes (if made) will affect the cache but not the repository itself.- Parameters:
sizeLimit
- maximum number of bytes to return. If the object size is larger than this limit andisLarge()
is true,LargeObjectException
will be thrown.- Returns:
- the cached bytes of this object. Do not modify it.
- Throws:
LargeObjectException
- if the object is bigger thansizeLimit
, or ifOutOfMemoryError
occurs during allocation of the result array. Callers should useopenStream()
instead to access the contents.MissingObjectException
- the object is large, and it no longer exists.IOException
- the object store cannot be accessed.
-
openStream
Obtain an input stream to read this object's data.- Returns:
- a stream of this object's data. Caller must close the stream when through with it. The returned stream is buffered with a reasonable buffer size.
- Throws:
MissingObjectException
- the object no longer exists.IOException
- the object store cannot be accessed.
-
copyTo
Copy this object to the output stream.For some object store implementations, this method may be more efficient than reading from
openStream()
into a temporary byte array, then writing to the destination stream.The default implementation of this method is to copy with a temporary byte array for large objects, or to pass through the cached byte array for small objects.
- Parameters:
out
- stream to receive the complete copy of this object's data. Caller is responsible for flushing or closing this stream after this method returns.- Throws:
MissingObjectException
- the object no longer exists.IOException
- the object store cannot be accessed, or the stream cannot be written to.
-
cloneArray
private static byte[] cloneArray(byte[] data)
-