Package com.atlassian.bitbucket.content
Interface ContentService
public interface ContentService
A service for the management of files and their metadata.
-
Method Summary
Modifier and TypeMethodDescriptioneditFile
(EditFileRequest request) Adds a new file or updates the content of an existing file.getBlame
(Repository repository, String commitId, String path, PageRequest pageRequest) CalculatesBlame
for the lines included by the providedPageRequest
for the specified path starting from the provided commit.long
Retrieves the maximum size, in bytes, for uploading content.getSize
(Repository repository, String commitId, String path) Retrieves the size of the specified file.getType
(Repository repository, String commitId, String path) Retrieves the type of object at the specified path.void
streamArchive
(ArchiveRequest request, TypeAwareOutputSupplier outputSupplier) Streams an archive of the specified repository at the specified commit, optionally filtering by path.void
streamDirectory
(Repository repository, String objectId, String path, boolean recursive, ContentTreeCallback callback, PageRequest pageRequest) Performs a directory listing for the specified objectId+path from the specified repository, streaming the results to the providedcallback
.void
streamFile
(Repository repository, String objectId, String path, TypeAwareOutputSupplier supplier) Streams the raw content of the file into an OutputStream obtained from the given TypeAwareOutputSupplier.void
streamFile
(Repository repository, String objectId, String path, PageRequest pageRequest, boolean withBlame, FileContentCallback fileContentCallback) void
streamPatch
(PatchRequest request, TypeAwareOutputSupplier outputSupplier) Streams a patch for a given commit or commit range.
-
Method Details
-
editFile
Adds a new file or updates the content of an existing file.- Parameters:
request
- details for adding/updating a file- Returns:
- the commit containing the file edit
- Throws:
EditFileFailedException
- if the edit operation failsFeatureUnsupportedScmException
- if the SCM for the specified repository does not support editing filesFileAlreadyExistsException
- if a file or path exists at the given path on the tip of the branch and no source commit was givenFileContentUnmodifiedException
- if the given content is identical to the content of the file at the tip of the given branchRepositoryHookVetoedException
- if one or more hooks canceled thefile edit
FileOutOfDateException
- if the given file has been changed since the source commit occurredFileTranscodingException
- if the input content could not be transcoded to the existing file's encodingNoSuchBranchException
- if the given branch does not exist in the repositoryNoSuchPathException
- if the file is not present in the source commit or at the tip of the given branchRepositoryArchivedException
- if repository is archivedForbiddenException
- if the author or committer is forbidden to make the commitArgumentValidationException
- if there are any validation errors in the requestServiceException
- Since:
- 4.13
-
getBlame
@Nonnull Page<Blame> getBlame(@Nonnull Repository repository, @Nonnull String commitId, @Nonnull String path, @Nonnull PageRequest pageRequest) CalculatesBlame
for the lines included by the providedPageRequest
for the specified path starting from the provided commit.A commit ID can be provided in several forms:
- A branch name
- A tag name
- A hash (which can identify a branch, a tag, or a specific commit, among other things)
- Parameters:
repository
- the repository to usecommitId
- the commit from which the blame traversal should start (which can also be specified as a ref ID)path
- the path for which blame should be retrievedpageRequest
- defines the set of lines within the file for which blame should be generated- Returns:
- a list containing 0 or more
Blame
objects, ordered by the line at which they start in the file - Since:
- 5.0
-
getMaxUploadSize
long getMaxUploadSize()Retrieves the maximum size, in bytes, for uploading content. Files larger than this will be rejected by the server.- Returns:
- the maximum size, in bytes, for uploading content
- Since:
- 4.13
-
getSize
@Nonnull OptionalLong getSize(@Nonnull Repository repository, @Nonnull String commitId, @Nonnull String path) Retrieves the size of the specified file. If the provided path identifies an empty file the returned size will beof(0L)
, notempty()
;empty()
indicates the provided path identifies a directory or submodule, not a file, and therefore has no size.- Parameters:
repository
- the repository to usecommitId
- the commit ID to retrieve the file size at (which can also be specified as a ref ID)path
- the path to the file to retrieve the size for- Returns:
- the file's size, which may be
of(0L)
if the file is empty orempty()
if the path is a directory or submodule - Throws:
NoSuchCommitException
- if the specified commit does not exist in the repositoryNoSuchPathException
- if the specified path does not exist in the commit- Since:
- 7.7
-
getType
@Nonnull ContentTreeNode.Type getType(@Nonnull Repository repository, @Nonnull String commitId, @Nullable String path) Retrieves the type of object at the specified path. This can be used to determine whether a given path identifies a directory, file or submodule.- Parameters:
repository
- the repository to usecommitId
- the commit ID to retrieve the object type at (which can also be specified as a ref ID)path
- the path to retrieve the type for- Returns:
- the path's type, indicating whether it's a directory, file or submodule
- Throws:
NoSuchCommitException
- if the specified commit does not exist in the repositoryNoSuchPathException
- if the specified path does not exist in the commit
-
streamArchive
void streamArchive(@Nonnull ArchiveRequest request, @Nonnull TypeAwareOutputSupplier outputSupplier) Streams an archive of the specified repository at the specified commit, optionally filtering by path. The content type for the requested archive format will be provided to the supplier when retrieving the output stream to which the archive will be written.- Parameters:
request
- describes the commit to archive, the format to archive it in, and the repository to archive it fromoutputSupplier
- a supplier which, when given the archive content type, will provide an output stream- Since:
- 5.1
-
streamDirectory
void streamDirectory(@Nonnull Repository repository, @Nonnull String objectId, @Nullable String path, boolean recursive, @Nonnull ContentTreeCallback callback, @Nonnull PageRequest pageRequest) Performs a directory listing for the specified objectId+path from the specified repository, streaming the results to the providedcallback
.The objectId provided here can be several things:
- A branch name
- A tag name
- A hash (which can identify a branch, a tag, or a specific commit, among other things)
The listing is provided to the caller via a callback mechanism - the supplied
ContentTreeCallback
parameter. This method promises to callContentTreeCallback.onStart(ContentTreeContext)
on the supplied instance once followed by zero or moreContentTreeCallback.onTreeNode(ContentTreeNode)
for each path in the directory and finally followed by aContentTreeCallback.onEnd(ContentTreeSummary)
.When
recursive
isfalse
,file sizes
will be populated and subdirectories below the specifiedpath
will be returned. For recursive listings, subdirectories and file sizes are omitted to improve performance.- Parameters:
repository
- the repository to useobjectId
- an identifier (name or hash) for the branch, tag or commit at which blame should be retrievedpath
- the path for which blame should be retrievedrecursive
- whether the directory listing should be recursivecallback
- the callback instance to call as the page starts, the children nodes are encountered and as the page endspageRequest
- defines the range of children in the listing the caller is interested in
-
streamFile
void streamFile(@Nonnull Repository repository, @Nonnull String objectId, @Nonnull String path, @Nonnull PageRequest pageRequest, boolean withBlame, @Nonnull FileContentCallback fileContentCallback) throws ServiceException - Parameters:
repository
- the repositoryobjectId
- the identifier for a point in the repository. Can be a commit ID, a branch or a tagpath
- the path to the filepageRequest
- the page request for the start and limit of the pagewithBlame
-true
to include blame information for content; otherwise,false
to omit itfileContentCallback
- the callback for receiving lines and page information- Throws:
ServiceException
- if the stream file operation fails
-
streamFile
void streamFile(@Nonnull Repository repository, @Nonnull String objectId, @Nonnull String path, @Nonnull TypeAwareOutputSupplier supplier) throws ServiceException Streams the raw content of the file into an OutputStream obtained from the given TypeAwareOutputSupplier. The implementation might try to detect the mime-type of the file, and pass that information to the TypeAwareOutputSupplier. Note: this method is not paged.- Parameters:
repository
- the repository to useobjectId
- the identifier for a point in the repository. Can be a commit ID, branch or tagpath
- the path to the filesupplier
- an object that can return an OutputStream given a mime-type- Throws:
ServiceException
- if the stream operation fails.
-
streamPatch
Streams a patch for a given commit or commit range.- Parameters:
request
- describes the commit and repository for which to generate the patchoutputSupplier
- a supplier which will provide an output stream- Since:
- 6.7
-