Class ThrottledInputStream.Builder

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

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

    Using NIO

    
     ThrottledInputStream in = ThrottledInputStream.builder()
       .setPath(Paths.get("MyFile.xml"))
       .setMaxBytes(100_000, ChronoUnit.SECONDS)
       .get();
     
     

    Using IO

    
     ThrottledInputStream in = ThrottledInputStream.builder()
       .setFile(new File("MyFile.xml"))
       .setMaxBytes(100_000, ChronoUnit.SECONDS)
       .get();
     
     
    
     ThrottledInputStream in = ThrottledInputStream.builder()
       .setInputStream(inputStream)
       .setMaxBytes(100_000, ChronoUnit.SECONDS)
       .get();
     
     
    See Also:
    get()
    • Method Detail

      • setMaxBytes

        public ThrottledInputStream.Builder setMaxBytes​(long value,
                                                        java.time.temporal.ChronoUnit chronoUnit)
        Sets the maximum bytes per time period unit.

        For example, to throttle reading to 100K per second, use:

         builder.setMaxBytes(100_000, ChronoUnit.SECONDS)
         

        To test idle timeouts for example, use 1 byte per minute, 1 byte per 30 seconds, and so on.

        Parameters:
        value - the maximum bytes
        chronoUnit - a duration scale goal.
        Returns:
        this instance.
        Throws:
        java.lang.IllegalArgumentException - Thrown if maxBytesPerSecond <= 0.
        Since:
        2.19.0
      • setMaxBytesPerSecond

        public void setMaxBytesPerSecond​(long maxBytesPerSecond)
        Sets the maximum bytes per second.
        Parameters:
        maxBytesPerSecond - the maximum bytes per second.
        Throws:
        java.lang.IllegalArgumentException - Thrown if maxBytesPerSecond <= 0.