/**
* {@inheritDoc}
*/
@Override
public int read() throws IOException {
return in.read();
}
/**
* {@inheritDoc}
*/
@Override
public int read(byte b[]) throws IOException {
return this.read(b, 0, b.length);
}
/**
* {@inheritDoc}
*/
@Override
public int available() throws IOException {
return in.available();
}
/**
* {@inheritDoc}
*/
@Override
public int read(byte b[], int off, int len) throws IOException {
startTimeStamp = System.currentTimeMillis();
int readSize = in.read(b, off, len);
endTimeStamp = System.currentTimeMillis();
readAdd = readAdd + readSize;
usingTime = usingTime + (endTimeStamp - startTimeStamp);
if (readAdd > limit) {
readAdd = 0;
usingTime = 0L;
if (usingTime < MAX_SLEEP_TIME) {
startTimeStamp = 0L;
endTimeStamp = 0L;
try {
Thread.sleep(MAX_SLEEP_TIME - usingTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
}
}
}
return readSize;
}
/**
* {@inheritDoc}
*/
@Override
public long skip(long n) throws IOException {
return in.skip(n);
}
/**
* {@inheritDoc}
*/
@Override
public void close() throws IOException {
in.close();
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void mark(int readlimit) {
in.mark(readlimit);
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void reset() throws IOException {
in.reset();
}
/**
* {@inheritDoc}
*/
@Override
public boolean markSupported() {
return in.markSupported();
}
/**
* 设置流读取速度
*
* @param limit 读取速度,单位byte
* @exception IllegalArgumentException 当设置限流速度limit为非正数时抛出此异常
*/
public void setLimit(int limit) {
if (limit <= 0) {
throw new IllegalArgumentException("limit size <= 0");
}
this.limit = limit;
}
}
* {@inheritDoc}
*/
@Override
public int read() throws IOException {
return in.read();
}
/**
* {@inheritDoc}
*/
@Override
public int read(byte b[]) throws IOException {
return this.read(b, 0, b.length);
}
/**
* {@inheritDoc}
*/
@Override
public int available() throws IOException {
return in.available();
}
/**
* {@inheritDoc}
*/
@Override
public int read(byte b[], int off, int len) throws IOException {
startTimeStamp = System.currentTimeMillis();
int readSize = in.read(b, off, len);
endTimeStamp = System.currentTimeMillis();
readAdd = readAdd + readSize;
usingTime = usingTime + (endTimeStamp - startTimeStamp);
if (readAdd > limit) {
readAdd = 0;
usingTime = 0L;
if (usingTime < MAX_SLEEP_TIME) {
startTimeStamp = 0L;
endTimeStamp = 0L;
try {
Thread.sleep(MAX_SLEEP_TIME - usingTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
}
}
}
return readSize;
}
/**
* {@inheritDoc}
*/
@Override
public long skip(long n) throws IOException {
return in.skip(n);
}
/**
* {@inheritDoc}
*/
@Override
public void close() throws IOException {
in.close();
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void mark(int readlimit) {
in.mark(readlimit);
}
/**
* {@inheritDoc}
*/
@Override
public synchronized void reset() throws IOException {
in.reset();
}
/**
* {@inheritDoc}
*/
@Override
public boolean markSupported() {
return in.markSupported();
}
/**
* 设置流读取速度
*
* @param limit 读取速度,单位byte
* @exception IllegalArgumentException 当设置限流速度limit为非正数时抛出此异常
*/
public void setLimit(int limit) {
if (limit <= 0) {
throw new IllegalArgumentException("limit size <= 0");
}
this.limit = limit;
}
}