public class BoxFile extends BoxItem
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 |
BoxFile.Info
Contains information about a BoxFile.
|
static class |
BoxFile.Permission
Enumerates the possible permissions that a user can have on a file.
|
Modifier and Type | Field and Description |
---|---|
static String[] |
ALL_FIELDS
An array of all possible file fields that can be requested when calling
getInfo() . |
Constructor and Description |
---|
BoxFile(BoxAPIConnection api,
String id)
Constructs a BoxFile for a file with a given ID.
|
Modifier and Type | Method and Description |
---|---|
BoxComment.Info |
addComment(String message)
Adds a comment to this file.
|
BoxTask.Info |
addTask(BoxTask.Action action,
String message,
Date dueAt)
Adds a new task to this file.
|
void |
canUploadVersion(String name,
long fileSize,
String parentID)
Checks if the file can be successfully uploaded by using the preflight check.
|
BoxFile.Info |
copy(BoxFolder destination)
Copies this item to another folder.
|
BoxFile.Info |
copy(BoxFolder destination,
String newName)
Copies this item to another folder and gives it a new name.
|
Metadata |
createMetadata(Metadata metadata)
Creates metadata on this file.
|
Metadata |
createMetadata(String typeName,
Metadata metadata)
Creates the metadata of specified type.
|
BoxSharedLink |
createSharedLink(BoxSharedLink.Access access,
Date unshareDate,
BoxSharedLink.Permissions permissions)
Creates a new shared link for this item.
|
void |
delete()
Deletes this file by moving it to the trash.
|
void |
deleteMetadata()
Deletes the file properties metadata.
|
void |
deleteMetadata(String typeName)
Deletes the file metadata of specified type.
|
void |
download(OutputStream output)
Downloads the contents of this file to a given OutputStream.
|
void |
download(OutputStream output,
ProgressListener listener)
Downloads the contents of this file to a given OutputStream while reporting the progress to a ProgressListener.
|
void |
downloadRange(OutputStream output,
long offset)
Downloads a part of this file's contents, starting at specified byte offset.
|
void |
downloadRange(OutputStream output,
long rangeStart,
long rangeEnd)
Downloads a part of this file's contents, starting at rangeStart and stopping at rangeEnd.
|
void |
downloadRange(OutputStream output,
long rangeStart,
long rangeEnd,
ProgressListener listener)
Downloads a part of this file's contents, starting at rangeStart and stopping at rangeEnd, while reporting the
progress to a ProgressListener.
|
List<BoxComment.Info> |
getComments()
Gets a list of any comments on this file.
|
BoxFile.Info |
getInfo()
Gets information about this item.
|
BoxFile.Info |
getInfo(String... fields)
Gets information about this item that's limited to a list of specified fields.
|
Metadata |
getMetadata()
Gets the file properties metadata.
|
Metadata |
getMetadata(String typeName)
Gets the file metadata of specified type.
|
URL |
getPreviewLink()
Gets an expiring URL for creating an embedded preview session.
|
List<BoxTask.Info> |
getTasks()
Gets a list of any tasks on this file.
|
Collection<BoxFileVersion> |
getVersions()
Gets any previous versions of this file.
|
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 |
rename(String newName)
Renames this file.
|
void |
updateInfo(BoxFile.Info info)
Updates the information about this file with any info fields that have been modified locally.
|
Metadata |
updateMetadata(Metadata metadata)
Updates the file metadata.
|
void |
uploadVersion(InputStream fileContent)
Uploads a new version of this file, replacing the current version.
|
void |
uploadVersion(InputStream fileContent,
Date modified)
Uploads a new version of this file, replacing the current version.
|
void |
uploadVersion(InputStream fileContent,
Date modified,
long fileSize,
ProgressListener listener)
Uploads a new version of this file, replacing the current version, while reporting the progress to a
ProgressListener.
|
getSharedItem, getSharedItem
equals, getAPI, getID, hashCode
public static final String[] ALL_FIELDS
getInfo()
.public BoxFile(BoxAPIConnection api, String id)
api
- the API connection to be used by the file.id
- the ID of the file.public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions)
BoxItem
This method is a convenience method for manually creating a new shared link and applying it to this item with
BoxItem.Info.setSharedLink(com.box.sdk.BoxSharedLink)
. You may want to create the shared link manually so that it can be updated along with
other changes to the item's info in a single network request, giving a boost to performance.
createSharedLink
in class BoxItem
access
- the access level of the shared link.unshareDate
- the date and time at which the link will expire. Can be null to create a non-expiring link.permissions
- the permissions of the shared link. Can be null to use the default permissions.public BoxComment.Info addComment(String message)
message
- the comment's message.public BoxTask.Info addTask(BoxTask.Action action, String message, Date dueAt)
action
- the action the task assignee will be prompted to do.message
- an optional message to include with the task.dueAt
- the day at which this task is due.public void download(OutputStream output)
output
- the stream to where the file will be written.public void download(OutputStream output, ProgressListener listener)
output
- the stream to where the file will be written.listener
- a listener for monitoring the download's progress.public void downloadRange(OutputStream output, long offset)
output
- the stream to where the file will be written.offset
- the byte offset at which to start the download.public void downloadRange(OutputStream output, long rangeStart, long rangeEnd)
output
- the stream to where the file will be written.rangeStart
- the byte offset at which to start the download.rangeEnd
- the byte offset at which to stop the download.public void downloadRange(OutputStream output, long rangeStart, long rangeEnd, ProgressListener listener)
output
- the stream to where the file will be written.rangeStart
- the byte offset at which to start the download.rangeEnd
- the byte offset at which to stop the download.listener
- a listener for monitoring the download's progress.public BoxFile.Info copy(BoxFolder destination)
BoxItem
public BoxFile.Info copy(BoxFolder destination, String newName)
BoxItem
public void delete()
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 file.public BoxFile.Info getInfo()
BoxItem
public BoxFile.Info getInfo(String... fields)
BoxItem
public void updateInfo(BoxFile.Info info)
The only fields that will be updated are the ones that have been modified locally. For example, the following code won't update any information (or even send a network request) since none of the info's fields were changed:
BoxFile file = new File(api, id); BoxFile.Info info = file.getInfo(); file.updateInfo(info);
info
- the updated info.public Collection<BoxFileVersion> getVersions()
public void canUploadVersion(String name, long fileSize, String parentID)
name
- the name to give the uploaded file or null to use existing name.fileSize
- the size of the file used for account capacity calculations.parentID
- the ID of the parent folder that the new version is being uploaded to.public void uploadVersion(InputStream fileContent)
fileContent
- a stream containing the new file contents.public void uploadVersion(InputStream fileContent, Date modified)
fileContent
- a stream containing the new file contents.modified
- the date that the new version was modified.public void uploadVersion(InputStream fileContent, Date modified, long fileSize, ProgressListener listener)
fileContent
- a stream containing the new file contents.modified
- the date that the new version was modified.fileSize
- the size of the file used for determining the progress of the upload.listener
- a listener for monitoring the upload's progress.public URL getPreviewLink()
public List<BoxComment.Info> getComments()
public List<BoxTask.Info> getTasks()
public Metadata createMetadata(Metadata metadata)
metadata
- The new metadata values.public Metadata createMetadata(String typeName, Metadata metadata)
typeName
- the metadata type name.metadata
- the new metadata values.public Metadata getMetadata()
public Metadata getMetadata(String typeName)
typeName
- the metadata type name.public Metadata updateMetadata(Metadata metadata)
metadata
- the new metadata values.public void deleteMetadata()
public void deleteMetadata(String typeName)
typeName
- the metadata type name.