org.apache.hadoop.tools.util
Class ThrottledInputStream
java.lang.Object
java.io.InputStream
org.apache.hadoop.tools.util.ThrottledInputStream
- All Implemented Interfaces:
- Closeable
public class ThrottledInputStream
- extends InputStream
The ThrottleInputStream provides bandwidth throttling on a specified
InputStream. It is implemented as a wrapper on top of another InputStream
instance.
The throttling works by examining the number of bytes read from the underlying
InputStream from the beginning, and sleep()ing for a time interval if
the byte-transfer is found exceed the specified tolerable maximum.
(Thus, while the read-rate might exceed the maximum for a given short interval,
the average tends towards the specified maximum, overall.)
ThrottledInputStream
public ThrottledInputStream(InputStream rawStream)
ThrottledInputStream
public ThrottledInputStream(InputStream rawStream,
long maxBytesPerSec)
close
public void close()
throws IOException
- Specified by:
close in interface Closeable- Overrides:
close in class InputStream
- Throws:
IOException
read
public int read()
throws IOException
- Specified by:
read in class InputStream
- Throws:
IOException
read
public int read(byte[] b)
throws IOException
- Overrides:
read in class InputStream
- Throws:
IOException
read
public int read(byte[] b,
int off,
int len)
throws IOException
- Overrides:
read in class InputStream
- Throws:
IOException
getTotalBytesRead
public long getTotalBytesRead()
- Getter for the number of bytes read from this stream, since creation.
- Returns:
- The number of bytes.
getBytesPerSec
public long getBytesPerSec()
- Getter for the read-rate from this stream, since creation.
Calculated as bytesRead/elapsedTimeSinceStart.
- Returns:
- Read rate, in bytes/sec.
getTotalSleepTime
public long getTotalSleepTime()
- Getter the total time spent in sleep.
- Returns:
- Number of milliseconds spent in sleep.
toString
public String toString()
- Overrides:
toString in class Object
Copyright © 2014 Apache Software Foundation. All Rights Reserved.