Module io.jooby
Package io.jooby

Interface Body

All Superinterfaces:
Iterable<ValueNode>, Value, ValueNode

public interface Body extends ValueNode
HTTP body value. Allows to access HTTP body as string, byte[], stream, etc..

HTTP body can be read it only once per request. Attempt to read more than one resulted in unexpected behaviour.

Since:
2.0.0
Author:
edgar
  • Method Details

    • value

      @NonNull default String value(@NonNull Charset charset)
      HTTP body as string.
      Parameters:
      charset - Charset.
      Returns:
      Body as string.
    • bytes

      @NonNull byte[] bytes()
      HTTP body as byte array.
      Returns:
      Body as byte array.
    • isInMemory

      boolean isInMemory()
      True if body is on memory. False, indicates body is on file system. Body larger than ServerOptions.getMaxRequestSize() will be dump to disk.
      Returns:
      True if body is on memory. False, indicates body is on file system.
    • getSize

      long getSize()
      Size in bytes. This is the same as Content-Length header.
      Returns:
      Size in bytes. This is the same as Content-Length header.
    • channel

      @NonNull ReadableByteChannel channel()
      Body as readable channel.
      Returns:
      Body as readable channel.
    • stream

      @NonNull InputStream stream()
      Body as input stream.
      Returns:
      Body as input stream.
    • toList

      @NonNull default <T> List<T> toList(@NonNull Class<T> type)
      Description copied from interface: Value
      Get list of the given type.
      Specified by:
      toList in interface Value
      Type Parameters:
      T - Item type.
      Parameters:
      type - Type to convert.
      Returns:
      List of items.
    • toList

      @NonNull default List<String> toList()
      Description copied from interface: Value
      Get list of values.
      Specified by:
      toList in interface Value
      Returns:
      List of values.
    • toSet

      @NonNull default Set<String> toSet()
      Description copied from interface: Value
      Get set of values.
      Specified by:
      toSet in interface Value
      Returns:
      set of values.
    • to

      @NonNull default <T> T to(@NonNull Class<T> type)
      Description copied from interface: Value
      Convert this value to the given type. Support values are single-value, array-value and object-value. Object-value can be converted to a JavaBean type.
      Specified by:
      to in interface Value
      Type Parameters:
      T - Element type.
      Parameters:
      type - Type to convert.
      Returns:
      Instance of the type.
    • toNullable

      @Nullable default <T> T toNullable(@NonNull Class<T> type)
      Description copied from interface: Value
      Convert this value to the given type. Support values are single-value, array-value and object-value. Object-value can be converted to a JavaBean type.
      Specified by:
      toNullable in interface Value
      Type Parameters:
      T - Element type.
      Parameters:
      type - Type to convert.
      Returns:
      Instance of the type or null.
    • to

      @NonNull <T> T to(@NonNull Type type)
      Convert this body into the given type.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - Type to use.
      Returns:
      Converted value.
    • toNullable

      @Nullable <T> T toNullable(@NonNull Type type)
      Convert this body into the given type.
      Type Parameters:
      T - Generic type.
      Parameters:
      type - Type to use.
      Returns:
      Converted value or null.
    • empty

      @NonNull static Body empty(@NonNull Context ctx)
      Empty body.
      Parameters:
      ctx - Current context.
      Returns:
      Empty body.
    • of

      @NonNull static Body of(@NonNull Context ctx, @NonNull InputStream stream, long size)
      Creates a HTTP body from input stream.
      Parameters:
      ctx - Current context.
      stream - Input stream.
      size - Size in bytes or -1.
      Returns:
      A new body.
    • of

      @NonNull static Body of(@NonNull Context ctx, @NonNull byte[] bytes)
      Creates a HTTP body from byte array.
      Parameters:
      ctx - Current context.
      bytes - byte array.
      Returns:
      A new body.
    • of

      @NonNull static Body of(@NonNull Context ctx, @NonNull Path file)
      Creates a HTTP body from file.
      Parameters:
      ctx - Current context.
      file - File.
      Returns:
      A new body.