Class FileRecord

java.lang.Object
com.iizix.server.upload.FileRecord

public final class FileRecord extends Object
The on-disk record of one file of an upload reservation, <fid>.json beside <fid>.part. The hwm field is the authority on how many bytes of the part are valid: the part is appended first and the record rewritten after, so on recovery a part longer than hwm is truncated to it, never the other way round.

The secret itself is never on disk; only its SHA-256 is, so that a record can be matched to a registry entry without the secret being recoverable from the staging directory.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Chunks acknowledged, i.e.
    final String
    The compression: gzip or none.
    final int
    The file index inside the reservation.
    final String
    The group name, empty for none.
    long
    Compressed bytes acknowledged: the valid length of the part.
    long
    The last write time in milliseconds.
    long
    The uncompressed size measured at verification, -1 until then.
    final long
    The client's last-modified time in milliseconds, 0 if unknown.
    final String
    The client's original name, verbatim, metadata only.
    boolean
    Whether the App holds the file paused; the state is UploadState.PAUSED while this or pausedByClient is set, and the servlet refuses chunks while this one is.
    boolean
    Whether the client has reported the file paused; a chunk from it clears this.
    long
    Uncompressed bytes acknowledged.
    The failure, refusal, cancellation or pause reason, empty for none.
    final String
    The reservation ID.
    final String
    SHA-256 of the secret, lower-case hex.
    final long
    The declared uncompressed size in bytes.
    The state.
    final String
    The declared media type, lower case, empty for none.
    final int
    The format version this record was read with or will be written with.
    The verified media type, empty until verification or when not sniffable.
  • Constructor Summary

    Constructors
    Constructor
    Description
    FileRecord(String rid, int fid, String name, String type, long size, long mod, String comp, String group, String secretHash, UploadState state, String reason, long now)
    Constructor for a new file record.
  • Method Summary

    Modifier and Type
    Method
    Description
    static FileRecord
    Deserializes from JSON.
    boolean
    Checks if the file uses gzip.
    Serializes to JSON.
    Outputs to string, without the client's name.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • version

      public final int version
      The format version this record was read with or will be written with.
    • rid

      public final String rid
      The reservation ID.
    • fid

      public final int fid
      The file index inside the reservation.
    • name

      public final String name
      The client's original name, verbatim, metadata only.
    • type

      public final String type
      The declared media type, lower case, empty for none.
    • size

      public final long size
      The declared uncompressed size in bytes.
    • mod

      public final long mod
      The client's last-modified time in milliseconds, 0 if unknown.
    • comp

      public final String comp
      The compression: gzip or none.
    • group

      public final String group
      The group name, empty for none.
    • secretHash

      public final String secretHash
      SHA-256 of the secret, lower-case hex.
    • hwm

      public long hwm
      Compressed bytes acknowledged: the valid length of the part.
    • plainHwm

      public long plainHwm
      Uncompressed bytes acknowledged.
    • chunks

      public int chunks
      Chunks acknowledged, i.e. the next chunk index.
    • state

      public UploadState state
      The state.
    • vtype

      public String vtype
      The verified media type, empty until verification or when not sniffable.
    • measuredSize

      public long measuredSize
      The uncompressed size measured at verification, -1 until then.
    • reason

      public String reason
      The failure, refusal, cancellation or pause reason, empty for none.
    • pausedByApp

      public boolean pausedByApp
      Whether the App holds the file paused; the state is UploadState.PAUSED while this or pausedByClient is set, and the servlet refuses chunks while this one is.
    • pausedByClient

      public boolean pausedByClient
      Whether the client has reported the file paused; a chunk from it clears this.
    • lastWrite

      public long lastWrite
      The last write time in milliseconds.
  • Constructor Details

    • FileRecord

      public FileRecord(String rid, int fid, String name, String type, long size, long mod, String comp, String group, String secretHash, UploadState state, String reason, long now)
      Constructor for a new file record.
      Parameters:
      rid - The reservation ID.
      fid - The file index.
      name - The client's original name.
      type - The declared media type.
      size - The declared size.
      mod - The client's last-modified time.
      comp - The compression.
      group - The group.
      secretHash - SHA-256 of the secret, hex; empty for a refused file.
      state - The initial state.
      reason - The refusal reason, empty for none.
      now - The current time.
  • Method Details

    • toJSON

      public JSONObject toJSON()
      Serializes to JSON.
      Returns:
      The JSON object.
    • fromJSON

      public static FileRecord fromJSON(JSONObject jo)
      Deserializes from JSON.
      Parameters:
      jo - The JSON object.
      Returns:
      The record.
      Throws:
      JSONException - If a required field is missing or of the wrong type.
      IllegalArgumentException - If the state name is unknown.
    • isGzip

      public boolean isGzip()
      Checks if the file uses gzip.
      Returns:
      true for gzip.
    • toString

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