Class UploadLimits

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

public final class UploadLimits extends Object
A snapshot of the upload settings in force when a reservation is made: quotas, counts, sizes, timeouts and the permitted media types. Immutable, so a reservation keeps the limits it was granted under even if an administrator changes the settings afterwards.

A reservation made for a request that names the types it accepts is granted under limits narrowed to them (withTypes(String), CC-UPLOAD-U1): a file must then be permitted by the configured list and by the request's list both (isPermitted(String, String, String)).

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    Chunk size in bytes.
    final int
    Idle timeout in seconds.
    final long
    Maximum declared size of one file in bytes.
    final int
    Maximum file count per reservation.
    final int
    Maximum pause time in seconds: how long a reservation may stay paused before it is cancelled.
    static final String
    The relative upload path every reservation reports, ending with '/'.
    final String
    The permitted types as configured, empty for any.
    final String
    The types the request of the reservation accepts, as given, empty for none of its own.
    final long
    Server-global quota in bytes, 0 for unlimited.
    final long
    Per-application-session quota in bytes, 0 for unlimited.
    final int
    Start timeout in seconds.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UploadLimits(long serverQuotaBytes, long sessionQuotaBytes, int maxFiles, long maxFileBytes, int chunkBytes, int idleSeconds, int startSeconds, int maxPauseSeconds, String permittedTypes)
    Constructor.
    UploadLimits(long serverQuotaBytes, long sessionQuotaBytes, int maxFiles, long maxFileBytes, int chunkBytes, int idleSeconds, int startSeconds, String permittedTypes)
    Constructor with the default maximum pause time (ServerSettings.DEFAULT_UPLOAD_MAX_PAUSE).
  • Method Summary

    Modifier and Type
    Method
    Description
    Snapshots the server settings.
    boolean
    isPermitted(String name, String type, String verified)
    Checks a file against the permitted list and the types of the reservation's request, at reservation and at verification.
    boolean
    Checks a media type against the permitted list.
    Outputs to string.
    Narrows these limits to the types a request accepts, for the one reservation made from it: a file must then be permitted by the configured list and by the request's list both.

    Methods inherited from class Object

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

    • PATH

      public static final String PATH
      The relative upload path every reservation reports, ending with '/'.
      See Also:
    • serverQuotaBytes

      public final long serverQuotaBytes
      Server-global quota in bytes, 0 for unlimited.
    • sessionQuotaBytes

      public final long sessionQuotaBytes
      Per-application-session quota in bytes, 0 for unlimited.
    • maxFiles

      public final int maxFiles
      Maximum file count per reservation.
    • maxFileBytes

      public final long maxFileBytes
      Maximum declared size of one file in bytes.
    • chunkBytes

      public final int chunkBytes
      Chunk size in bytes.
    • idleSeconds

      public final int idleSeconds
      Idle timeout in seconds.
    • startSeconds

      public final int startSeconds
      Start timeout in seconds.
    • maxPauseSeconds

      public final int maxPauseSeconds
      Maximum pause time in seconds: how long a reservation may stay paused before it is cancelled.
    • permittedTypes

      public final String permittedTypes
      The permitted types as configured, empty for any.
    • requestTypes

      public final String requestTypes
      The types the request of the reservation accepts, as given, empty for none of its own.
  • Constructor Details

    • UploadLimits

      public UploadLimits(long serverQuotaBytes, long sessionQuotaBytes, int maxFiles, long maxFileBytes, int chunkBytes, int idleSeconds, int startSeconds, String permittedTypes)
      Constructor with the default maximum pause time (ServerSettings.DEFAULT_UPLOAD_MAX_PAUSE).
      Parameters:
      serverQuotaBytes - Server-global quota in bytes, 0 for unlimited.
      sessionQuotaBytes - Per-session quota in bytes, 0 for unlimited.
      maxFiles - Maximum file count per reservation, at least 1.
      maxFileBytes - Maximum declared size of one file in bytes, at least 1.
      chunkBytes - Chunk size in bytes, at least 1.
      idleSeconds - Idle timeout in seconds, at least 1.
      startSeconds - Start timeout in seconds, at least 1.
      permittedTypes - Comma-separated media types, empty or null for any.
      Throws:
      IllegalArgumentException - If a value is below its minimum.
    • UploadLimits

      public UploadLimits(long serverQuotaBytes, long sessionQuotaBytes, int maxFiles, long maxFileBytes, int chunkBytes, int idleSeconds, int startSeconds, int maxPauseSeconds, String permittedTypes)
      Constructor.
      Parameters:
      serverQuotaBytes - Server-global quota in bytes, 0 for unlimited.
      sessionQuotaBytes - Per-session quota in bytes, 0 for unlimited.
      maxFiles - Maximum file count per reservation, at least 1.
      maxFileBytes - Maximum declared size of one file in bytes, at least 1.
      chunkBytes - Chunk size in bytes, at least 1.
      idleSeconds - Idle timeout in seconds, at least 1.
      startSeconds - Start timeout in seconds, at least 1.
      maxPauseSeconds - Maximum pause time in seconds, at least 1.
      permittedTypes - Comma-separated media types, empty or null for any.
      Throws:
      IllegalArgumentException - If a value is below its minimum.
  • Method Details

    • from

      public static UploadLimits from(ServerSettings ss)
      Snapshots the server settings.
      Parameters:
      ss - The settings.
      Returns:
      The limits.
    • isTypePermitted

      public boolean isTypePermitted(String type)
      Checks a media type against the permitted list.
      Parameters:
      type - The type, lower case; empty means "undeclared".
      Returns:
      true if the list is empty, or the type or its type/* family is listed.
    • withTypes

      public UploadLimits withTypes(String types)
      Narrows these limits to the types a request accepts, for the one reservation made from it: a file must then be permitted by the configured list and by the request's list both.
      Parameters:
      types - The request's types in the syntax of the HTML accept attribute: comma-separated media types, type/* families and .ext file name extensions; null or blank for none.
      Returns:
      The narrowed limits, or these when the request has no types of its own.
    • isPermitted

      public boolean isPermitted(String name, String type, String verified)
      Checks a file against the permitted list and the types of the reservation's request, at reservation and at verification.

      The configured list is checked on the type, as isTypePermitted(String) does. The request's types, when it has any, must permit the file as well: by a media type or family entry matching the type, or by an extension entry matching the end of the name. An extension entry is a statement about the name, not the content, so at verification it stops counting when the content was recognized as something else than what that extension names: a ZIP archive called a.pdf is not permitted by .pdf. An extension the sniffer has no type for (.txt, .docx) permits by the name alone.

      Parameters:
      name - The original file name, or null to check the type only.
      type - The type: at reservation the declared one; at verification the type the content was found to be, else the declared one. Empty means "undeclared".
      verified - The type the content was found to be; empty or null when it was not recognized, and at reservation.
      Returns:
      true if both lists permit the file.
    • toString

      public String toString()
      Outputs to string.
      Overrides:
      toString in class Object