Module io.jooby
Package io.jooby

Interface ByteRange


public interface ByteRange
Utility class to compute single byte range requests when response content length is known. Jooby support single byte range requests on file responses, like: assets, input stream, files, etc.

Single byte range request looks like: bytes=0-100, bytes=100-, bytes=-100.

Multiple byte range request are not supported.

Since:
2.0.0
Author:
edgar
  • Field Details

  • Method Details

    • parse

      @NonNull static ByteRange parse(@Nullable String value, long contentLength)
      Parse a byte range request value. Example of valid values:

      - bytes=0-100 - bytes=-100 - bytes=100-

      Any non-matching values produces a not satisfiable response.

      If value is null or content length less or equal to 0, produces an empty/NOOP response.

      Parameters:
      value - Valid byte range request value.
      contentLength - Content length.
      Returns:
      Byte range instance.
    • getStart

      long getStart()
      Start range or -1.
      Returns:
      Start range or -1.
    • getEnd

      long getEnd()
      End range or -1.
      Returns:
      End range or -1.
    • getContentLength

      long getContentLength()
      New content length.
      Returns:
      New content length.
    • getContentRange

      @NonNull String getContentRange()
      Value for Content-Range response header.
      Returns:
      Value for Content-Range response header.
    • getStatusCode

      @NonNull StatusCode getStatusCode()
      For partial requests this method returns StatusCode.PARTIAL_CONTENT.

      For not satisfiable requests this returns StatusCode.REQUESTED_RANGE_NOT_SATISFIABLE..

      Otherwise just returns StatusCode.OK.

      Returns:
      Status code.
    • apply

      @NonNull ByteRange apply(@NonNull Context ctx)
      For partial request this method set the following byte range response headers:

      - Accept-Ranges - Content-Range - Content-Length

      For not satisfiable requests:

      - Throws a StatusCode.REQUESTED_RANGE_NOT_SATISFIABLE

      Otherwise this method does nothing.

      Parameters:
      ctx - Web context.
      Returns:
      This byte range request.
    • apply

      @NonNull InputStream apply(@NonNull InputStream input) throws IOException
      For partial requests this method generates a new truncated input stream.

      For not satisfiable requests this method throws an exception.

      If there is no range to apply this method returns the given input stream.

      Parameters:
      input - Input stream.
      Returns:
      A truncated input stream for partial request or same input stream.
      Throws:
      IOException - When truncation fails.