Interface IUploadedFile
- All Superinterfaces:
IUploadFile
- All Known Implementing Classes:
UploadedFile
A verified, completely received upload, as handed to
IFileUploadListener.onFileCompleted(IUploadReservation,IUploadedFile).The server process owns the staged file until the API user takes it with take() or removes it with delete(). A file left alone is still server-owned and is swept when its reservation or app session ends.
- Author:
- Christopher Mindus
Method Summary
Modifier and TypeMethodDescriptionlongdecompressTo(Path target) Streams the decompressed content to a target file.voiddelete()Deletes the staged file now: the state becomesUploadState.CONSUMEDand the quota is released.longGets the size of the staged file as stored, i.e.getFile()Gets the staged file as stored on disk: the raw bytes as received, compressed if the transfer used gzip.Opens the content, transparently decompressed: a caller reads the original bytes whatever compression the transfer used.longgetSize()Gets the uncompressed size as measured during verification.Gets the media type verified from the file's own bytes, when the sniffer knows the type.take()Takes ownership of the raw staged file: the state becomesUploadState.CONSUMED, the quota is released, no sweep will ever touch the file again, and what happens next is the caller's business (move it, delete it, leave it).Methods inherited from interface IUploadFile
getBytesReceived, getCompression, getDeclaredSize, getDeclaredType, getFileIndex, getGroup, getLastModified, getOriginalName, getPlainBytesReceived, getReason, getReservation, getState
Method Details
getVerifiedType
String getVerifiedType()Gets the media type verified from the file's own bytes, when the sniffer knows the type.- Returns:
- The verified type in lower case, or empty if the bytes were not sniffable and the declared type stands.
getSize
long getSize()Gets the uncompressed size as measured during verification. It equals the declared size, because a mismatch fails verification.- Returns:
- The size in bytes.
getCompressedSize
long getCompressedSize()Gets the size of the staged file as stored, i.e. compressed if the transfer used gzip.- Returns:
- The compressed size in bytes.
getInputStream
Opens the content, transparently decompressed: a caller reads the original bytes whatever compression the transfer used. Each call opens a new stream; the caller closes it.- Returns:
- The stream of original bytes.
- Throws:
IOException- For file errors.IllegalStateException- If the file has been deleted or taken.
getFile
File getFile()Gets the staged file as stored on disk: the raw bytes as received, compressed if the transfer used gzip. The caller must neither delete nor move it; usetake()for that.- Returns:
- The raw file.
- Throws:
IllegalStateException- If the file has been deleted or taken.
decompressTo
Streams the decompressed content to a target file.- Parameters:
target- The target path; an existing file is replaced.- Returns:
- The number of bytes written.
- Throws:
IOException- For file errors.IllegalStateException- If the file has been deleted or taken.
take
File take()Takes ownership of the raw staged file: the state becomesUploadState.CONSUMED, the quota is released, no sweep will ever touch the file again, and what happens next is the caller's business (move it, delete it, leave it). The sidecar stays until the reservation is swept.- Returns:
- The raw file, compressed if the transfer used gzip.
- Throws:
IllegalStateException- If already taken or deleted.
delete
void delete()Deletes the staged file now: the state becomesUploadState.CONSUMEDand the quota is released.- Throws:
IllegalStateException- If already taken or deleted.