Class DXFile
- java.lang.Object
-
- com.dnanexus.DXObject
-
- com.dnanexus.DXDataObject
-
- com.dnanexus.DXFile
-
public class DXFile extends DXDataObject
A file (an opaque sequence of bytes).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDXFile.BuilderBuilder class for creating a newDXFileobject.static classDXFile.DescribeContains metadata for a file.-
Nested classes/interfaces inherited from class com.dnanexus.DXDataObject
DXDataObject.DescribeOptions
-
-
Field Summary
-
Fields inherited from class com.dnanexus.DXDataObject
cachedDescribe
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DXFileclose()Closes the data object.DXFilecloseAndWait()Closes the data object and waits until the close operation is complete.DXFile.Describedescribe()Returns metadata about the data object.DXFile.Describedescribe(DXDataObject.DescribeOptions options)Returns metadata about the data object, specifying which optional fields are to be returned and what project to obtain project-specific metadata from.byte[]downloadBytes()Downloads the entire file into a byte array.byte[]downloadBytes(long start, long end)Downloads the specified byte range of the file into a byte array.voiddownloadToOutputStream(OutputStream os)Downloads the entire file and writes the data to an OutputStream.voiddownloadToOutputStream(OutputStream os, long start, long end)Downloads the specified byte range of the file into an OutputStream.DXFile.DescribegetCachedDescribe()Returns metadata about the data object, likeDXDataObject.describe(), but without making an API call.InputStreamgetDownloadStream()Returns a stream of the file's contents.InputStreamgetDownloadStream(long start, long end)Returns a stream of the specified byte range of the file's contents.static DXFilegetInstance(String fileId)Returns aDXFileassociated with an existing file.static DXFilegetInstance(String fileId, DXContainer project)Returns aDXFileassociated with an existing file in a particular project or container.static DXFilegetInstanceWithEnvironment(String fileId, DXContainer project, DXEnvironment env)Returns aDXFileassociated with an existing file in a particular project using the specified environment.static DXFilegetInstanceWithEnvironment(String fileId, DXEnvironment env)Returns aDXFileassociated with an existing file using the specified environment.OutputStreamgetUploadStream()Returns an OutputStream that uploads any data written to itstatic DXFile.BuildernewFile()Returns a Builder object for creating a newDXFile.static DXFile.BuildernewFileWithEnvironment(DXEnvironment env)Returns a Builder object for creating a newDXFileusing the specified environment.voidupload(byte[] data)Uploads data from the specified byte array to the file.voidupload(InputStream data)Uploads data from the specified stream to the file.-
Methods inherited from class com.dnanexus.DXDataObject
addTags, addTypes, checkCachedDescribeAvailable, checkDXLinkFormat, equals, getLinkAsJson, getProject, hashCode, listProjects, putAllProperties, putAllProperties, putProperty, removeProperty, removeTags, removeTypes, rename, setDetails, setVisibility
-
Methods inherited from class com.dnanexus.DXObject
apiCallOnObject, apiCallOnObject, getId, toString
-
-
-
-
Method Detail
-
getInstance
public static DXFile getInstance(String fileId)
Returns aDXFileassociated with an existing file.- Throws:
NullPointerException- IffileIdis null
-
getInstance
public static DXFile getInstance(String fileId, DXContainer project)
Returns aDXFileassociated with an existing file in a particular project or container.- Throws:
NullPointerException- IffileIdorcontaineris null
-
getInstanceWithEnvironment
public static DXFile getInstanceWithEnvironment(String fileId, DXContainer project, DXEnvironment env)
Returns aDXFileassociated with an existing file in a particular project using the specified environment.- Throws:
NullPointerException- IffileIdorcontaineris null
-
getInstanceWithEnvironment
public static DXFile getInstanceWithEnvironment(String fileId, DXEnvironment env)
Returns aDXFileassociated with an existing file using the specified environment.- Throws:
NullPointerException- IffileIdis null
-
newFile
public static DXFile.Builder newFile()
Returns a Builder object for creating a newDXFile.- Returns:
- a newly initialized builder object
-
newFileWithEnvironment
public static DXFile.Builder newFileWithEnvironment(DXEnvironment env)
Returns a Builder object for creating a newDXFileusing the specified environment.- Parameters:
env- environment to use to make API calls- Returns:
- a newly initialized builder object
-
close
public DXFile close()
Description copied from class:DXDataObjectCloses the data object.Returns the same object so you can chain calls.
- Overrides:
closein classDXDataObject- Returns:
- the same
DXDataObject
-
closeAndWait
public DXFile closeAndWait()
Description copied from class:DXDataObjectCloses the data object and waits until the close operation is complete.Returns the same object so you can chain calls.
- Overrides:
closeAndWaitin classDXDataObject- Returns:
- the same
DXDataObject
-
describe
public DXFile.Describe describe()
Description copied from class:DXDataObjectReturns metadata about the data object.The properties and details fields will not be returned, and any project-specific metadata fields will be selected from an arbitrary project in which the requesting user has access to this object. To change either of these aspects of this behavior, use
DXDataObject.describe(DescribeOptions)instead.- Overrides:
describein classDXDataObject- Returns:
- a
Describecontaining the data object's metadata.
-
describe
public DXFile.Describe describe(DXDataObject.DescribeOptions options)
Description copied from class:DXDataObjectReturns metadata about the data object, specifying which optional fields are to be returned and what project to obtain project-specific metadata from.- Overrides:
describein classDXDataObject- Parameters:
options-DescribeOptionsobject specifying how thedescriberequest is to be made.- Returns:
- a
Describecontaining the data object's metadata.
-
downloadBytes
public byte[] downloadBytes() throws IOExceptionDownloads the entire file into a byte array.- Returns:
- byte array containing file contents
- Throws:
IOException- if an error occurs while downloading the data
-
downloadBytes
public byte[] downloadBytes(long start, long end) throws IOExceptionDownloads the specified byte range of the file into a byte array. Range requested must be no larger than 2 GB.- Parameters:
start- first byte of the range within the file to be downloaded. The start byte is inclusive in the range, and 0 is indexed as the first byte in the file.end- last byte of the range within the file to be downloaded. The end byte is exclusive (not included in the range). An input of -1 specifies the end of the file.- Returns:
- byte array containing file contents within range specified
- Throws:
IOException- if an error occurs while downloading the data
-
downloadToOutputStream
public void downloadToOutputStream(OutputStream os) throws IOException
Downloads the entire file and writes the data to an OutputStream.- Parameters:
os- output stream downloaded file contents are written into- Throws:
IOException
-
downloadToOutputStream
public void downloadToOutputStream(OutputStream os, long start, long end) throws IOException
Downloads the specified byte range of the file into an OutputStream.- Parameters:
os- output stream downloaded file contents are written intostart- first byte of the range within the file to be downloaded. The start byte is inclusive in the range, and 0 is indexed as the first byte in the file.end- last byte of the range within the file to be downloaded. The end byte is exclusive (not included in the range). An input of -1 specifies the end of the file.- Throws:
IOException
-
getCachedDescribe
public DXFile.Describe getCachedDescribe()
Description copied from class:DXDataObjectReturns metadata about the data object, likeDXDataObject.describe(), but without making an API call.This cached describe info is only available if this object appears in the result of a
DXSearch.findDataObjects()call that specifiedDXSearch.FindDataObjectsRequestBuilder.includeDescribeOutput(), and the describe info that is returned reflects the state of the object at the time that the search was performed.- Overrides:
getCachedDescribein classDXDataObject- Returns:
- a
Describecontaining the data object's metadata
-
getDownloadStream
public InputStream getDownloadStream()
Returns a stream of the file's contents.- Returns:
- stream containing file contents
-
getDownloadStream
public InputStream getDownloadStream(long start, long end)
Returns a stream of the specified byte range of the file's contents.- Parameters:
start- first byte of the range within the file to be downloaded. The start byte is inclusive in the range, and 0 is indexed as the first byte in the file.end- last byte of the range within the file to be downloaded. The end byte is exclusive (not included in the range). An input of -1 specifies the end of the file.- Returns:
- stream containing file contents within range specified
-
getUploadStream
public OutputStream getUploadStream()
Returns an OutputStream that uploads any data written to itThe file must be in the "open" state. This method assumes exclusive access to the file: the file must have no parts uploaded before this call is made, and no other clients may upload data to the same file concurrently.
- Returns:
- OutputStream to which file contents are written
-
upload
public void upload(byte[] data) throws IOExceptionUploads data from the specified byte array to the file.The file must be in the "open" state. This method assumes exclusive access to the file: the file must have no parts uploaded before this call is made, and no other clients may upload data to the same file concurrently.
- Parameters:
data- data in bytes to be uploaded- Throws:
IOException- if an error occurs while uploading the data
-
upload
public void upload(InputStream data) throws IOException
Uploads data from the specified stream to the file.The file must be in the "open" state. This method assumes exclusive access to the file: the file must have no parts uploaded before this call is made, and no other clients may upload data to the same file concurrently.
- Parameters:
data- stream containing data to be uploaded- Throws:
IOException- if an error occurs while uploading the data
-
-