@BoxResourceType(value="folder") public class BoxFolder extends BoxItem implements Iterable<BoxItem.Info>
Represents a folder on Box. This class can be used to iterate through a folder's contents, collaborate a folder with another user or group, and perform other common folder operations (move, copy, delete, etc.).
Unless otherwise noted, the methods in this class can throw an unchecked BoxAPIException
(unchecked
meaning that the compiler won't force you to handle it) if an error occurs. If you wish to implement custom error
handling for errors related to the Box REST API, you should capture this exception explicitly.
Modifier and Type | Class and Description |
---|---|
class |
BoxFolder.Info
Contains information about a BoxFolder.
|
static class |
BoxFolder.Permission
Enumerates the possible permissions that a user can have on a folder.
|
static class |
BoxFolder.SortDirection
Used to specify what direction to sort and display results.
|
static class |
BoxFolder.SyncState
Enumerates the possible sync states that a folder can have.
|
Modifier and Type | Field and Description |
---|---|
static URLTemplate |
ADD_COLLABORATION_URL
Add Collaboration URL Template.
|
static String[] |
ALL_FIELDS
An array of all possible folder fields that can be requested when calling
getInfo(String...) . |
static URLTemplate |
COPY_FOLDER_URL
Copy Folder URL Template.
|
static URLTemplate |
CREATE_FOLDER_URL
Create Folder URL Template.
|
static URLTemplate |
CREATE_WEB_LINK_URL
Create Web Link URL Template.
|
static URLTemplate |
DELETE_FOLDER_URL
Delete Folder URL Template.
|
static URLTemplate |
FOLDER_INFO_URL_TEMPLATE
Folder Info URL Template.
|
static URLTemplate |
FOLDER_LOCK_URL_TEMPLATE
Folder Locks URL Template.
|
static URLTemplate |
GET_COLLABORATIONS_URL
Get Collaborations URL Template.
|
static URLTemplate |
GET_ITEMS_URL
Get Items URL Template.
|
static URLTemplate |
METADATA_URL_TEMPLATE
Metadata URL Template.
|
static URLTemplate |
SEARCH_URL_TEMPLATE
Search URL Template.
|
static URLTemplate |
UPLOAD_FILE_URL
Upload File URL Template.
|
static URLTemplate |
UPLOAD_SESSION_URL_TEMPLATE
Upload Session URL Template.
|
SHARED_ITEM_URL_TEMPLATE, WATERMARK_URL_TEMPLATE
Constructor and Description |
---|
BoxFolder(BoxAPIConnection api,
String id)
Constructs a BoxFolder for a folder with a given ID.
|
Modifier and Type | Method and Description |
---|---|
String |
addClassification(String classificationType)
Adds a metadata classification to the specified file.
|
BoxMetadataCascadePolicy.Info |
addMetadataCascadePolicy(String scope,
String templateKey)
Creates a new Metadata Cascade Policy on a folder.
|
BoxWebHook.Info |
addWebHook(URL address,
BoxWebHook.Trigger... triggers)
Adds new
BoxWebHook to this BoxFolder . |
BoxWatermark |
applyWatermark()
Used to apply or update the watermark for the folder.
|
void |
canUpload(String name,
long fileSize)
Checks if the file can be successfully uploaded by using the preflight check.
|
BoxCollaboration.Info |
collaborate(BoxCollaborator collaborator,
BoxCollaboration.Role role)
Adds a collaborator to this folder.
|
BoxCollaboration.Info |
collaborate(BoxCollaborator collaborator,
BoxCollaboration.Role role,
Boolean notify,
Boolean canViewPath)
Adds a collaborator to this folder.
|
BoxCollaboration.Info |
collaborate(BoxCollaborator collaborator,
BoxCollaboration.Role role,
Boolean notify,
Boolean canViewPath,
Date expiresAt,
Boolean isAccessOnly)
Adds a collaborator to this folder.
|
BoxCollaboration.Info |
collaborate(String email,
BoxCollaboration.Role role)
Adds a collaborator to this folder.
|
BoxCollaboration.Info |
collaborate(String email,
BoxCollaboration.Role role,
Boolean notify,
Boolean canViewPath)
Adds a collaborator to this folder.
|
BoxCollaboration.Info |
collaborate(String email,
BoxCollaboration.Role role,
Boolean notify,
Boolean canViewPath,
Date expiresAt,
Boolean isAccessOnly)
Adds a collaborator to this folder.
|
BoxFolder.Info |
copy(BoxFolder destination)
Copies this item to another folder.
|
BoxFolder.Info |
copy(BoxFolder destination,
String newName)
Copies this item to another folder and gives it a new name.
|
BoxFolder.Info |
createFolder(String name)
Creates a new child folder inside this folder.
|
Metadata |
createMetadata(Metadata metadata)
Creates global property metadata on this folder.
|
Metadata |
createMetadata(String templateName,
Metadata metadata)
Creates metadata on this folder using a specified template.
|
Metadata |
createMetadata(String templateName,
String scope,
Metadata metadata)
Creates metadata on this folder using a specified scope and template.
|
BoxSharedLink |
createSharedLink(BoxSharedLinkRequest sharedLinkRequest)
Creates a shared link.
|
BoxFileUploadSession.Info |
createUploadSession(String fileName,
long fileSize)
Creates an upload session to create a new file in chunks.
|
BoxWebLink.Info |
createWebLink(String name,
URL linkURL)
Uploads a new weblink to this folder.
|
BoxWebLink.Info |
createWebLink(String name,
URL linkURL,
String description)
Uploads a new weblink to this folder.
|
BoxWebLink.Info |
createWebLink(URL linkURL)
Uploads a new weblink to this folder.
|
BoxWebLink.Info |
createWebLink(URL linkURL,
String description)
Uploads a new weblink to this folder.
|
void |
delete(boolean recursive)
Deletes this folder, optionally recursively deleting all of its contents.
|
void |
deleteClassification()
Deletes the classification on the file.
|
void |
deleteMetadata()
Deletes the global properties metadata on this folder.
|
void |
deleteMetadata(String templateName)
Deletes the metadata on this folder associated with a specified template.
|
void |
deleteMetadata(String templateName,
String scope)
Deletes the metadata on this folder associated with a specified scope and template.
|
Iterable<Metadata> |
getAllMetadata(String... fields)
Used to retrieve all metadata associated with the folder.
|
Iterable<BoxItem.Info> |
getChildren()
Returns an iterable containing the items in this folder.
|
Iterable<BoxItem.Info> |
getChildren(SortParameters sortParameters,
PagingParameters pagingParameters,
String... fields)
Returns an iterable containing the items in this folder sorted by name and direction.
|
Iterable<BoxItem.Info> |
getChildren(String... fields)
Returns an iterable containing the items in this folder and specifies which child fields to retrieve from the
API.
|
Iterable<BoxItem.Info> |
getChildren(String sort,
BoxFolder.SortDirection direction,
long offset,
long limit,
String... fields)
Returns an iterable containing the items in this folder sorted by name and direction.
|
Iterable<BoxItem.Info> |
getChildren(String sort,
BoxFolder.SortDirection direction,
String... fields)
Returns an iterable containing the items in this folder sorted by name and direction.
|
PartialCollection<BoxItem.Info> |
getChildrenRange(long offset,
long limit,
String... fields)
Retrieves a specific range of child items in this folder.
|
String |
getClassification()
Gets the classification type for the specified file.
|
Collection<BoxCollaboration.Info> |
getCollaborations(String... fields)
Gets information about all of the collaborations for this folder.
|
BoxFolder.Info |
getInfo(String... fields)
Gets information about this item that's limited to a list of specified fields.
|
protected URL |
getItemURL() |
Iterable<BoxFolderLock.Info> |
getLocks()
Get the lock on this folder.
|
Metadata |
getMetadata()
Gets the global properties metadata on this folder.
|
Metadata |
getMetadata(String templateName)
Gets the metadata on this folder associated with a specified template.
|
Metadata |
getMetadata(String templateName,
String scope)
Gets the metadata on this folder associated with a specified scope and template.
|
Iterable<BoxMetadataCascadePolicy.Info> |
getMetadataCascadePolicies(String... fields)
Retrieves all Metadata Cascade Policies on a folder.
|
Iterable<BoxMetadataCascadePolicy.Info> |
getMetadataCascadePolicies(String enterpriseID,
int limit,
String... fields)
Retrieves all Metadata Cascade Policies on a folder.
|
static BoxFolder |
getRootFolder(BoxAPIConnection api)
Gets the current user's root folder.
|
BoxWatermark |
getWatermark(String... fields)
Used to retrieve the watermark for the folder.
|
Iterator<BoxItem.Info> |
iterator()
Returns an iterator over the items in this folder.
|
BoxFolderLock.Info |
lock()
Lock this folder.
|
BoxItem.Info |
move(BoxFolder destination)
Moves this item to another folder.
|
BoxItem.Info |
move(BoxFolder destination,
String newName)
Moves this item to another folder and gives it a new name.
|
void |
removeWatermark()
Removes a watermark from the folder.
|
void |
rename(String newName)
Renames this folder.
|
String |
setClassification(String classificationType)
Attempts to add classification to a file.
|
BoxFolder.Info |
setCollections(BoxCollection... collections)
Sets the collections that this item belongs to.
|
Metadata |
setMetadata(String templateName,
String scope,
Metadata metadata)
Sets the provided metadata on the folder.
|
String |
updateClassification(String classificationType)
Updates a metadata classification on the specified file.
|
void |
updateInfo(BoxFolder.Info info)
Updates the information about this folder with any info fields that have been modified locally.
|
Metadata |
updateMetadata(Metadata metadata)
Updates the folder metadata.
|
BoxFile.Info |
uploadFile(FileUploadParams uploadParams)
Uploads a new file to this folder with custom upload parameters.
|
BoxFile.Info |
uploadFile(InputStream fileContent,
String name)
Uploads a new file to this folder.
|
BoxFile.Info |
uploadFile(InputStream fileContent,
String name,
long fileSize,
ProgressListener listener)
Uploads a new file to this folder while reporting the progress to a ProgressListener.
|
BoxFile.Info |
uploadFile(InputStream fileContent,
String name,
String description)
Uploads a new file to this folder with a specified file description.
|
BoxFile.Info |
uploadFile(UploadFileCallback callback,
String name)
Uploads a new file to this folder.
|
BoxFile.Info |
uploadLargeFile(InputStream inputStream,
String fileName,
long fileSize)
Creates a new file.
|
BoxFile.Info |
uploadLargeFile(InputStream inputStream,
String fileName,
long fileSize,
int nParallelConnections,
long timeOut,
TimeUnit unit)
Creates a new file using specified number of parallel http connections.
|
BoxFile.Info |
uploadLargeFile(InputStream inputStream,
String fileName,
long fileSize,
int nParallelConnections,
long timeOut,
TimeUnit unit,
Map<String,String> fileAttributes)
Creates a new file using specified number of parallel http connections.
|
BoxFile.Info |
uploadLargeFile(InputStream inputStream,
String fileName,
long fileSize,
Map<String,String> fileAttributes)
Creates a new file.
|
applyWatermark, getSharedItem, getSharedItem, getWatermark, removeWatermark
equals, getAPI, getID, getResourceType, hashCode
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static final String[] ALL_FIELDS
getInfo(String...)
.public static final URLTemplate CREATE_FOLDER_URL
public static final URLTemplate CREATE_WEB_LINK_URL
public static final URLTemplate COPY_FOLDER_URL
public static final URLTemplate DELETE_FOLDER_URL
public static final URLTemplate FOLDER_INFO_URL_TEMPLATE
public static final URLTemplate UPLOAD_FILE_URL
public static final URLTemplate ADD_COLLABORATION_URL
public static final URLTemplate GET_COLLABORATIONS_URL
public static final URLTemplate GET_ITEMS_URL
public static final URLTemplate SEARCH_URL_TEMPLATE
public static final URLTemplate METADATA_URL_TEMPLATE
public static final URLTemplate UPLOAD_SESSION_URL_TEMPLATE
public static final URLTemplate FOLDER_LOCK_URL_TEMPLATE
public BoxFolder(BoxAPIConnection api, String id)
api
- the API connection to be used by the folder.id
- the ID of the folder.public static BoxFolder getRootFolder(BoxAPIConnection api)
api
- the API connection to be used by the folder.protected URL getItemURL()
getItemURL
in class BoxItem
public BoxCollaboration.Info collaborate(BoxCollaborator collaborator, BoxCollaboration.Role role)
collaborator
- the collaborator to add.role
- the role of the collaborator.public BoxCollaboration.Info collaborate(String email, BoxCollaboration.Role role)
email
- the email address of the collaborator to add.role
- the role of the collaborator.public BoxCollaboration.Info collaborate(BoxCollaborator collaborator, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath, Date expiresAt, Boolean isAccessOnly)
collaborator
- the collaborator to add.role
- the role of the collaborator.notify
- the user/group should receive email notification of the collaboration or not.canViewPath
- the view path collaboration feature is enabled or not.
View path collaborations allow the invitee to see the entire ancestral path to the associated
folder. The user will not gain privileges in any ancestral folder.expiresAt
- when the collaboration should expire.isAccessOnly
- whether the collaboration is access only or not.public BoxCollaboration.Info collaborate(BoxCollaborator collaborator, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath)
collaborator
- the collaborator to add.role
- the role of the collaborator.notify
- the user/group should receive email notification of the collaboration or not.canViewPath
- the view path collaboration feature is enabled or not.
View path collaborations allow the invitee to see the entire ancestral path to the associated
folder. The user will not gain privileges in any ancestral folder.public BoxCollaboration.Info collaborate(String email, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath, Date expiresAt, Boolean isAccessOnly)
email
- the email address of the collaborator to add.role
- the role of the collaborator.notify
- the user/group should receive email notification of the collaboration or not.canViewPath
- the view path collaboration feature is enabled or not.
View path collaborations allow the invitee to see the entire ancestral path to the associated
folder. The user will not gain privileges in any ancestral folder.expiresAt
- when the collaboration should expire.isAccessOnly
- whether the collaboration is access only or not.public BoxCollaboration.Info collaborate(String email, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath)
email
- the email address of the collaborator to add.role
- the role of the collaborator.notify
- the user/group should receive email notification of the collaboration or not.canViewPath
- the view path collaboration feature is enabled or not.
View path collaborations allow the invitee to see the entire ancestral path to the associated
folder. The user will not gain privileges in any ancestral folder.public BoxSharedLink createSharedLink(BoxSharedLinkRequest sharedLinkRequest)
sharedLinkRequest
- Shared link to createpublic Collection<BoxCollaboration.Info> getCollaborations(String... fields)
public BoxFolder.Info getInfo(String... fields)
BoxItem
public void updateInfo(BoxFolder.Info info)
info
- the updated info.public BoxFolder.Info copy(BoxFolder destination)
BoxItem
public BoxFolder.Info copy(BoxFolder destination, String newName)
BoxItem
public BoxFolder.Info createFolder(String name)
name
- the new folder's name.public void delete(boolean recursive)
recursive
- true to recursively delete this folder's contents; otherwise false.public BoxItem.Info move(BoxFolder destination)
BoxItem
public BoxItem.Info move(BoxFolder destination, String newName)
BoxItem
public void rename(String newName)
newName
- the new name of the folder.public void canUpload(String name, long fileSize)
name
- the name to give the uploaded file.fileSize
- the size of the file used for account capacity calculations.public BoxFile.Info uploadFile(InputStream fileContent, String name)
fileContent
- a stream containing the contents of the file to upload.name
- the name to give the uploaded file.public BoxFile.Info uploadFile(UploadFileCallback callback, String name)
callback
- the callback which allows file content to be written on output stream.name
- the name to give the uploaded file.public BoxFile.Info uploadFile(InputStream fileContent, String name, long fileSize, ProgressListener listener)
fileContent
- a stream containing the contents of the file to upload.name
- the name to give the uploaded file.fileSize
- the size of the file used for determining the progress of the upload.listener
- a listener for monitoring the upload's progress.public BoxFile.Info uploadFile(InputStream fileContent, String name, String description)
fileContent
- a stream containing the contents of the file to upload.name
- the name to give the uploaded file.description
- the description to give the uploaded file.public BoxFile.Info uploadFile(FileUploadParams uploadParams)
uploadParams
- the custom upload parameters.public BoxWebLink.Info createWebLink(URL linkURL)
linkURL
- the URL the weblink points to.public BoxWebLink.Info createWebLink(String name, URL linkURL)
name
- the filename for the weblink.linkURL
- the URL the weblink points to.public BoxWebLink.Info createWebLink(URL linkURL, String description)
linkURL
- the URL the weblink points to.description
- the weblink's description.public BoxWebLink.Info createWebLink(String name, URL linkURL, String description)
name
- the filename for the weblink.linkURL
- the URL the weblink points to.description
- the weblink's description.public Iterable<BoxItem.Info> getChildren()
public Iterable<BoxItem.Info> getChildren(String... fields)
fields
- the fields to retrieve.public Iterable<BoxItem.Info> getChildren(String sort, BoxFolder.SortDirection direction, String... fields)
sort
- the field to sort by, can be set as `name`, `id`, and `date`.direction
- the direction to display the item results.fields
- the fields to retrieve.public Iterable<BoxItem.Info> getChildren(String sort, BoxFolder.SortDirection direction, long offset, long limit, String... fields)
sort
- the field to sort by, can be set as `name`, `id`, and `date`.direction
- the direction to display the item results.offset
- the index of the first child item to retrieve.limit
- the maximum number of children to retrieve after the offset.fields
- the fields to retrieve.public PartialCollection<BoxItem.Info> getChildrenRange(long offset, long limit, String... fields)
offset
- the index of the first child item to retrieve.limit
- the maximum number of children to retrieve after the offset.fields
- the fields to retrieve.public Iterable<BoxItem.Info> getChildren(SortParameters sortParameters, PagingParameters pagingParameters, String... fields)
sortParameters
- describes sorting parameters.
Sort parameters are supported only with offset based pagination.
Use SortParameters.none()
to ignore sorting.pagingParameters
- describes paging parameters.fields
- the fields to retrieve.public Iterator<BoxItem.Info> iterator()
iterator
in interface Iterable<BoxItem.Info>
public BoxWebHook.Info addWebHook(URL address, BoxWebHook.Trigger... triggers)
BoxWebHook
to this BoxFolder
.address
- BoxWebHook.Info.getAddress()
triggers
- BoxWebHook.Info.getTriggers()
BoxWebHook.Info
public BoxWatermark getWatermark(String... fields)
fields
- the fields to retrieve.public BoxWatermark applyWatermark()
public void removeWatermark()
public Iterable<Metadata> getAllMetadata(String... fields)
fields
- the optional fields to retrieve.public BoxFolder.Info setCollections(BoxCollection... collections)
BoxItem
setCollections
in class BoxItem
collections
- the collections that this item should belong to.public Metadata createMetadata(Metadata metadata)
metadata
- the new metadata values.public Metadata createMetadata(String templateName, Metadata metadata)
templateName
- the name of the metadata template.metadata
- the new metadata values.public Metadata createMetadata(String templateName, String scope, Metadata metadata)
templateName
- the name of the metadata template.scope
- the scope of the template (usually "global" or "enterprise").metadata
- the new metadata values.public Metadata setMetadata(String templateName, String scope, Metadata metadata)
templateName
- the name of the metadata template.scope
- the scope of the template (usually "global" or "enterprise").metadata
- the new metadata values.public Metadata getMetadata()
public Metadata getMetadata(String templateName)
templateName
- the metadata template type name.public Metadata getMetadata(String templateName, String scope)
templateName
- the metadata template type name.scope
- the scope of the template (usually "global" or "enterprise").public Metadata updateMetadata(Metadata metadata)
metadata
- the new metadata values.public void deleteMetadata()
public void deleteMetadata(String templateName)
templateName
- the metadata template type name.public void deleteMetadata(String templateName, String scope)
templateName
- the metadata template type name.scope
- the scope of the template (usually "global" or "enterprise").public String addClassification(String classificationType)
classificationType
- the metadata classification type.public String updateClassification(String classificationType)
classificationType
- the metadata classification type.public String setClassification(String classificationType)
classificationType
- the metadata classification type.public String getClassification()
public void deleteClassification()
public BoxFileUploadSession.Info createUploadSession(String fileName, long fileSize)
fileName
- the name of the file to be createdfileSize
- the size of the file that will be uploadedpublic BoxFile.Info uploadLargeFile(InputStream inputStream, String fileName, long fileSize) throws InterruptedException, IOException
inputStream
- the stream instance that contains the data.fileName
- the name of the file to be created.fileSize
- the size of the file that will be uploaded.InterruptedException
- when a thread execution is interrupted.IOException
- when reading a stream throws exception.public BoxFile.Info uploadLargeFile(InputStream inputStream, String fileName, long fileSize, Map<String,String> fileAttributes) throws InterruptedException, IOException
inputStream
- the stream instance that contains the data.fileName
- the name of the file to be created.fileSize
- the size of the file that will be uploaded.fileAttributes
- file attributes to setInterruptedException
- when a thread execution is interrupted.IOException
- when reading a stream throws exception.public BoxFile.Info uploadLargeFile(InputStream inputStream, String fileName, long fileSize, int nParallelConnections, long timeOut, TimeUnit unit) throws InterruptedException, IOException
inputStream
- the stream instance that contains the data.fileName
- the name of the file to be created.fileSize
- the size of the file that will be uploaded.nParallelConnections
- number of parallel http connections to usetimeOut
- time to wait before killing the jobunit
- time unit for the time wait valueInterruptedException
- when a thread execution is interrupted.IOException
- when reading a stream throws exception.public BoxFile.Info uploadLargeFile(InputStream inputStream, String fileName, long fileSize, int nParallelConnections, long timeOut, TimeUnit unit, Map<String,String> fileAttributes) throws InterruptedException, IOException
inputStream
- the stream instance that contains the data.fileName
- the name of the file to be created.fileSize
- the size of the file that will be uploaded.nParallelConnections
- number of parallel http connections to usetimeOut
- time to wait before killing the jobunit
- time unit for the time wait valuefileAttributes
- file attributes to setInterruptedException
- when a thread execution is interrupted.IOException
- when reading a stream throws exception.public BoxMetadataCascadePolicy.Info addMetadataCascadePolicy(String scope, String templateKey)
scope
- the scope of the metadata cascade policy.templateKey
- the key of the template.public Iterable<BoxMetadataCascadePolicy.Info> getMetadataCascadePolicies(String... fields)
fields
- optional fields to retrieve for cascade policies.public Iterable<BoxMetadataCascadePolicy.Info> getMetadataCascadePolicies(String enterpriseID, int limit, String... fields)
enterpriseID
- the ID of the enterprise to retrieve cascade policies for.limit
- the number of entries of cascade policies to retrieve.fields
- optional fields to retrieve for cascade policies.public BoxFolderLock.Info lock()
public Iterable<BoxFolderLock.Info> getLocks()