Class UploadedFile

java.lang.Object
com.iizix.server.upload.UploadedFile
All Implemented Interfaces:
IUploadedFile, IUploadFile

public final class UploadedFile extends Object implements IUploadedFile
A verified upload as handed to the listener: reads the staged part transparently decompressed, and transfers or ends the server's ownership through take() / delete().
Author:
Christopher Mindus
  • Constructor Details

  • Method Details

    • getFileIndex

      public int getFileIndex()
      Description copied from interface: IUploadFile
      Gets the file index inside its reservation, 0..N-1. It is part of the upload URL.
      Specified by:
      getFileIndex in interface IUploadFile
      Returns:
      The file index.
    • getReservation

      public IUploadReservation getReservation()
      Description copied from interface: IUploadFile
      Gets the reservation the file belongs to.
      Specified by:
      getReservation in interface IUploadFile
      Returns:
      The reservation.
    • getOriginalName

      public String getOriginalName()
      Description copied from interface: IUploadFile
      Gets the original file name as the client sent it. Metadata only: never a path.
      Specified by:
      getOriginalName in interface IUploadFile
      Returns:
      The name.
    • getDeclaredType

      public String getDeclaredType()
      Description copied from interface: IUploadFile
      Gets the media type the client declared, lower case, empty if none.
      Specified by:
      getDeclaredType in interface IUploadFile
      Returns:
      The declared type.
    • getDeclaredSize

      public long getDeclaredSize()
      Description copied from interface: IUploadFile
      Gets the uncompressed size the client declared.
      Specified by:
      getDeclaredSize in interface IUploadFile
      Returns:
      The declared size in bytes.
    • getLastModified

      public long getLastModified()
      Description copied from interface: IUploadFile
      Gets the client's last-modified time.
      Specified by:
      getLastModified in interface IUploadFile
      Returns:
      Milliseconds since the epoch, 0 if unknown.
    • getGroup

      public String getGroup()
      Description copied from interface: IUploadFile
      Gets the group name the client placed the file in.
      Specified by:
      getGroup in interface IUploadFile
      Returns:
      The group, empty if none.
    • getCompression

      public String getCompression()
      Description copied from interface: IUploadFile
      Gets the compression the transfer uses, as confirmed by the reservation.
      Specified by:
      getCompression in interface IUploadFile
      Returns:
      UploadFileRequest.COMPRESSION_NONE or UploadFileRequest.COMPRESSION_GZIP.
    • getState

      public UploadState getState()
      Description copied from interface: IUploadFile
      Gets the current state.
      Specified by:
      getState in interface IUploadFile
      Returns:
      The state.
    • getReason

      public String getReason()
      Description copied from interface: IUploadFile
      Specified by:
      getReason in interface IUploadFile
      Returns:
      The reason, or null while none applies.
    • getPlainBytesReceived

      public long getPlainBytesReceived()
      Description copied from interface: IUploadFile
      Gets the uncompressed bytes acknowledged so far, for progress.
      Specified by:
      getPlainBytesReceived in interface IUploadFile
      Returns:
      The plain high-water mark.
    • getBytesReceived

      public long getBytesReceived()
      Description copied from interface: IUploadFile
      Gets the compressed (on-the-wire) bytes acknowledged so far.
      Specified by:
      getBytesReceived in interface IUploadFile
      Returns:
      The compressed high-water mark.
    • getVerifiedType

      public String getVerifiedType()
      Description copied from interface: IUploadedFile
      Gets the media type verified from the file's own bytes, when the sniffer knows the type.
      Specified by:
      getVerifiedType in interface IUploadedFile
      Returns:
      The verified type in lower case, or empty if the bytes were not sniffable and the declared type stands.
    • getSize

      public long getSize()
      Description copied from interface: IUploadedFile
      Gets the uncompressed size as measured during verification. It equals the declared size, because a mismatch fails verification.
      Specified by:
      getSize in interface IUploadedFile
      Returns:
      The size in bytes.
    • getCompressedSize

      public long getCompressedSize()
      Description copied from interface: IUploadedFile
      Gets the size of the staged file as stored, i.e. compressed if the transfer used gzip.
      Specified by:
      getCompressedSize in interface IUploadedFile
      Returns:
      The compressed size in bytes.
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from interface: IUploadedFile
      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.
      Specified by:
      getInputStream in interface IUploadedFile
      Returns:
      The stream of original bytes.
      Throws:
      IOException - For file errors.
    • getFile

      public File getFile()
      Description copied from interface: IUploadedFile
      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; use IUploadedFile.take() for that.
      Specified by:
      getFile in interface IUploadedFile
      Returns:
      The raw file.
    • decompressTo

      public long decompressTo(Path target) throws IOException
      Description copied from interface: IUploadedFile
      Streams the decompressed content to a target file.
      Specified by:
      decompressTo in interface IUploadedFile
      Parameters:
      target - The target path; an existing file is replaced.
      Returns:
      The number of bytes written.
      Throws:
      IOException - For file errors.
    • take

      public File take()
      Description copied from interface: IUploadedFile
      Takes ownership of the raw staged file: the state becomes UploadState.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.
      Specified by:
      take in interface IUploadedFile
      Returns:
      The raw file, compressed if the transfer used gzip.
    • delete

      public void delete()
      Description copied from interface: IUploadedFile
      Deletes the staged file now: the state becomes UploadState.CONSUMED and the quota is released.
      Specified by:
      delete in interface IUploadedFile
    • toString

      public String toString()
      Outputs to string, without the name.
      Overrides:
      toString in class Object