@InterfaceAudience.Private public class ThrottledInputStream extends InputStream
Modifier and Type | Field and Description |
---|---|
private long |
bytesRead |
private long |
maxBytesPerSec |
private InputStream |
rawStream |
private static long |
SLEEP_DURATION_MS |
private long |
startTime |
private long |
totalSleepTime |
Constructor and Description |
---|
ThrottledInputStream(InputStream rawStream) |
ThrottledInputStream(InputStream rawStream,
long maxBytesPerSec) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
long |
getBytesPerSec()
Getter for the read-rate from this stream, since creation.
|
long |
getTotalBytesRead()
Getter for the number of bytes read from this stream, since creation.
|
long |
getTotalSleepTime()
Getter the total time spent in sleep.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
int |
read(long position,
byte[] buffer,
int offset,
int length)
Read bytes starting from the specified position.
|
private void |
throttle() |
String |
toString() |
available, mark, markSupported, reset, skip
private final InputStream rawStream
private final long maxBytesPerSec
private final long startTime
private long bytesRead
private long totalSleepTime
private static final long SLEEP_DURATION_MS
public ThrottledInputStream(InputStream rawStream)
public ThrottledInputStream(InputStream rawStream, long maxBytesPerSec)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b) throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public int read(long position, byte[] buffer, int offset, int length) throws IOException
PositionedReadable
.position
- buffer
- offset
- length
- IOException
private void throttle() throws IOException
IOException
public long getTotalBytesRead()
public long getBytesPerSec()
public long getTotalSleepTime()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.