Package me.desair.tus.server.upload.disk
Class DiskStorageService
java.lang.Object
me.desair.tus.server.upload.disk.AbstractDiskBasedService
me.desair.tus.server.upload.disk.DiskStorageService
- All Implemented Interfaces:
UploadStorageService
Implementation of
UploadStorageService
that implements storage on disk.-
Constructor Summary
ConstructorDescriptionDiskStorageService
(String storagePath) DiskStorageService
(UploadIdFactory idFactory, String storagePath) -
Method Summary
Modifier and TypeMethodDescriptionappend
(UploadInfo info, InputStream inputStream) Append the bytes in the giveInputStream
to the upload with the given ID starting at the provided offset.void
cleanupExpiredUploads
(UploadLockingService uploadLockingService) Clean up any upload data that is expired according to the configured expiration time.void
copyUploadTo
(UploadInfo info, OutputStream outputStream) Copy the uploaded bytes to the given output stream.create
(UploadInfo info, String ownerKey) Create an upload location with the given upload information.long
Get the maximum upload size configured on this storage service.Return theUploadConcatenationService
implementation that this upload service is using.getUploadedBytes
(String uploadUri, String ownerKey) Get the uploaded bytes corresponding to the given upload URL as a stream.Get the uploaded bytes corresponding to the given upload ID as a stream.Get the expiration period of an upload in milliseconds.getUploadInfo
(String uploadUrl, String ownerKey) Method to retrieve the upload info by its upload URL.Method to retrieve the upload info by its ID.The URI which is configured as the upload endpoint.void
removeLastNumberOfBytes
(UploadInfo info, long byteCount) Remove the given last amount of bytes from the uploaded data.void
setIdFactory
(UploadIdFactory idFactory) Set an instance if IdFactory to be used for creating identities and extracting them from uploadUris.void
setMaxUploadSize
(Long maxUploadSize) Limit the maximum upload size to the given value.void
setUploadConcatenationService
(UploadConcatenationService concatenationService) Set theUploadConcatenationService
that this upload storage service should use.void
setUploadExpirationPeriod
(Long uploadExpirationPeriod) Set the expiration period after which an in-progress upload expires.void
terminateUpload
(UploadInfo info) Terminate completed and unfinished uploads allowing the Server to free up used resources.void
update
(UploadInfo uploadInfo) Update the upload information for the provided ID.Methods inherited from class me.desair.tus.server.upload.disk.AbstractDiskBasedService
getPathInStorageDirectory, getStoragePath
-
Constructor Details
-
DiskStorageService
-
DiskStorageService
-
-
Method Details
-
setIdFactory
Description copied from interface:UploadStorageService
Set an instance if IdFactory to be used for creating identities and extracting them from uploadUris.- Specified by:
setIdFactory
in interfaceUploadStorageService
- Parameters:
idFactory
- TheUploadIdFactory
to use within this storage service
-
setMaxUploadSize
Description copied from interface:UploadStorageService
Limit the maximum upload size to the given value.- Specified by:
setMaxUploadSize
in interfaceUploadStorageService
- Parameters:
maxUploadSize
- The maximum upload limit to set
-
getMaxUploadSize
public long getMaxUploadSize()Description copied from interface:UploadStorageService
Get the maximum upload size configured on this storage service.- Specified by:
getMaxUploadSize
in interfaceUploadStorageService
- Returns:
- The maximum upload size or zero if no maximum
-
getUploadInfo
Description copied from interface:UploadStorageService
Method to retrieve the upload info by its upload URL.- Specified by:
getUploadInfo
in interfaceUploadStorageService
- Parameters:
uploadUrl
- The URL corresponding to this upload. This parameter can be null.ownerKey
- A key representing the owner of the upload- Returns:
- The upload info matching the given URL, or null when not found.
- Throws:
IOException
-
getUploadInfo
Description copied from interface:UploadStorageService
Method to retrieve the upload info by its ID.- Specified by:
getUploadInfo
in interfaceUploadStorageService
- Parameters:
id
- The ID of the upload- Returns:
- The matching upload info
- Throws:
IOException
- When the service is not able to retrieve the upload information
-
getUploadUri
Description copied from interface:UploadStorageService
The URI which is configured as the upload endpoint.- Specified by:
getUploadUri
in interfaceUploadStorageService
- Returns:
- The URI
-
create
Description copied from interface:UploadStorageService
Create an upload location with the given upload information.- Specified by:
create
in interfaceUploadStorageService
- Parameters:
info
- The Upload information to use to create the new uploadownerKey
- A key representing the owner of the upload- Returns:
- An
UploadInfo
object containing the information used to create the upload and its unique ID - Throws:
IOException
-
update
Description copied from interface:UploadStorageService
Update the upload information for the provided ID.- Specified by:
update
in interfaceUploadStorageService
- Parameters:
uploadInfo
- The upload info object containing the ID and information to update- Throws:
IOException
UploadNotFoundException
-
append
Description copied from interface:UploadStorageService
Append the bytes in the giveInputStream
to the upload with the given ID starting at the provided offset. This method also updates theUploadInfo
corresponding to this upload. The Upload Storage server should not exceed its max upload size when writing bytes.- Specified by:
append
in interfaceUploadStorageService
- Parameters:
info
- The ID of the uploadinputStream
- The input stream containing the bytes to append- Returns:
- The new
UploadInfo
for this upload - Throws:
IOException
TusException
-
removeLastNumberOfBytes
public void removeLastNumberOfBytes(UploadInfo info, long byteCount) throws UploadNotFoundException, IOException Description copied from interface:UploadStorageService
Remove the given last amount of bytes from the uploaded data.- Specified by:
removeLastNumberOfBytes
in interfaceUploadStorageService
- Parameters:
info
- Upload of which to remove the bytesbyteCount
- The number of bytes to remove at the end- Throws:
UploadNotFoundException
IOException
-
terminateUpload
Description copied from interface:UploadStorageService
Terminate completed and unfinished uploads allowing the Server to free up used resources.- Specified by:
terminateUpload
in interfaceUploadStorageService
- Parameters:
info
- The upload to terminate- Throws:
UploadNotFoundException
IOException
-
getUploadExpirationPeriod
Description copied from interface:UploadStorageService
Get the expiration period of an upload in milliseconds.- Specified by:
getUploadExpirationPeriod
in interfaceUploadStorageService
- Returns:
- The number of milliseconds before an upload expires, or null if it cannot expire
-
setUploadExpirationPeriod
Description copied from interface:UploadStorageService
Set the expiration period after which an in-progress upload expires.- Specified by:
setUploadExpirationPeriod
in interfaceUploadStorageService
- Parameters:
uploadExpirationPeriod
- The period in milliseconds
-
setUploadConcatenationService
Description copied from interface:UploadStorageService
Set theUploadConcatenationService
that this upload storage service should use.- Specified by:
setUploadConcatenationService
in interfaceUploadStorageService
- Parameters:
concatenationService
- The UploadConcatenationService implementation to use
-
getUploadConcatenationService
Description copied from interface:UploadStorageService
Return theUploadConcatenationService
implementation that this upload service is using.- Specified by:
getUploadConcatenationService
in interfaceUploadStorageService
- Returns:
- The UploadConcatenationService that is being used
-
getUploadedBytes
public InputStream getUploadedBytes(String uploadUri, String ownerKey) throws IOException, UploadNotFoundException Description copied from interface:UploadStorageService
Get the uploaded bytes corresponding to the given upload URL as a stream.- Specified by:
getUploadedBytes
in interfaceUploadStorageService
- Parameters:
uploadUri
- The URIownerKey
- The owner key of this upload- Returns:
- an
OutputStream
containing the bytes of the upload - Throws:
IOException
UploadNotFoundException
-
getUploadedBytes
Description copied from interface:UploadStorageService
Get the uploaded bytes corresponding to the given upload ID as a stream.- Specified by:
getUploadedBytes
in interfaceUploadStorageService
- Parameters:
id
- the ID of the upload- Returns:
- an
OutputStream
containing the bytes of the upload - Throws:
IOException
- When retrieving the bytes from the storage layer failsUploadNotFoundException
- When the proved id is not linked to an upload
-
copyUploadTo
public void copyUploadTo(UploadInfo info, OutputStream outputStream) throws UploadNotFoundException, IOException Description copied from interface:UploadStorageService
Copy the uploaded bytes to the given output stream.- Specified by:
copyUploadTo
in interfaceUploadStorageService
- Parameters:
info
- The upload of which we should copy the bytesoutputStream
- The output stream where we have to copy the bytes to- Throws:
UploadNotFoundException
IOException
-
cleanupExpiredUploads
Description copied from interface:UploadStorageService
Clean up any upload data that is expired according to the configured expiration time.- Specified by:
cleanupExpiredUploads
in interfaceUploadStorageService
- Parameters:
uploadLockingService
- AnUploadLockingService
that can be used to check and lock uploads- Throws:
IOException
-