org.apache.hc.client5.testing.classic

## Class RandomHandler.RandomEntity

- java.lang.Object
- - org.apache.hc.core5.http.io.entity.AbstractHttpEntity
  - - org.apache.hc.client5.testing.classic.RandomHandler.RandomEntity

- All Implemented Interfaces:
    Closeable, AutoCloseable, org.apache.hc.core5.http.EntityDetails, org.apache.hc.core5.http.HttpEntity
  Enclosing class:
    RandomHandler

      public static class RandomHandler.RandomEntity
      extends org.apache.hc.core5.http.io.entity.AbstractHttpEntity

  An entity that generates random data. This is an outgoing entity, it supports `writeTo` but not `getContent`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected long` | `length` The length of the random data to generate.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RandomHandler.RandomEntity(long len)` Creates a new entity generating the given amount of data.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `InputStream` | `getContent()` Not supported.
    `long` | `getContentLength()` Obtains the size of the random data.
    `boolean` | `isRepeatable()` Tells that this entity is repeatable, in a way.
    `boolean` | `isStreaming()` Tells that this entity is not streaming.
    `void` | `writeTo(OutputStream out)` Generates the random content.

    - ### Methods inherited from class org.apache.hc.core5.http.io.entity.AbstractHttpEntity

      `getContentEncoding, getContentType, getTrailerNames, getTrailers, isChunked, toString, writeTo`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### length

          protected final long length

      The length of the random data to generate.

  - ### Constructor Detail

    - #### RandomHandler.RandomEntity

          public RandomHandler.RandomEntity(long len)

      Creates a new entity generating the given amount of data.
      Parameters:
        `len` - the number of random bytes to generate, 0 to maxint

  - ### Method Detail

    - #### isStreaming

          public final boolean isStreaming()

      Tells that this entity is not streaming.
      Returns:
        false

    - #### isRepeatable

          public boolean isRepeatable()

      Tells that this entity is repeatable, in a way. Repetitions will generate different random data, unless perchance the same random data is generated twice.
      Specified by:
        `isRepeatable` in interface `org.apache.hc.core5.http.HttpEntity`
      Overrides:
        `isRepeatable` in class `org.apache.hc.core5.http.io.entity.AbstractHttpEntity`
      Returns:
        `true`

    - #### getContentLength

          public long getContentLength()

      Obtains the size of the random data.
      Returns:
        the number of random bytes to generate

    - #### getContent

          public InputStream getContent()

      Not supported. This method throws an exception.
      Returns:
        never anything

    - #### writeTo

          public void writeTo(OutputStream out)
                       throws IOException

      Generates the random content.
      Specified by:
        `writeTo` in interface `org.apache.hc.core5.http.HttpEntity`
      Overrides:
        `writeTo` in class `org.apache.hc.core5.http.io.entity.AbstractHttpEntity`
      Parameters:
        `out` - where to write the content to
      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Throws:
        `IOException`

Copyright © 1999–2022 The Apache Software Foundation. All rights reserved.