Class ThrottledInputStream.Builder

All Implemented Interfaces:
IOSupplier<ThrottledInputStream>
Enclosing class:
ThrottledInputStream

public static class ThrottledInputStream.Builder extends AbstractStreamBuilder<ThrottledInputStream,ThrottledInputStream.Builder>
Builds a new ThrottledInputStream.

Using NIO


 ThrottledInputStream in = ThrottledInputStream.builder()
   .setPath(Paths.get("MyFile.xml"))
   .setMaxBytesPerSecond(100_000)
   .get();
 
 

Using IO


 ThrottledInputStream in = ThrottledInputStream.builder()
   .setFile(new File("MyFile.xml"))
   .setMaxBytesPerSecond(100_000)
   .get();
 
 

 ThrottledInputStream in = ThrottledInputStream.builder()
   .setInputStream(inputStream)
   .setMaxBytesPerSecond(100_000)
   .get();
 
 
See Also:
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • get

      public ThrottledInputStream get() throws IOException
      Builds a new ThrottledInputStream.

      You must set input that supports AbstractStreamBuilder.getInputStream(), otherwise, this method throws an exception.

      This builder use the following aspects:

      • AbstractStreamBuilder.getInputStream()
      • maxBytesPerSecond
      Returns:
      a new instance.
      Throws:
      IllegalStateException - if the origin is null.
      UnsupportedOperationException - if the origin cannot be converted to an InputStream.
      IOException - if an I/O error occurs.
      See Also:
      • AbstractStreamBuilder.getInputStream()
    • setMaxBytesPerSecond

      public void setMaxBytesPerSecond(long maxBytesPerSecond)
      Sets the maximum bytes per second.
      Parameters:
      maxBytesPerSecond - the maximum bytes per second.