Files
jpexs-decompiler/trunk/src/com/jpexs/helpers/LimitedInputStream.java
Jindra Petøík 17a5e75f1a Issue #367 Search in memory: save(export) SWFs
few refactorings
2013-09-10 07:46:16 +02:00

39 lines
781 B
Java

package com.jpexs.helpers;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author JPEXS
*/
public class LimitedInputStream extends InputStream {
private InputStream is;
private long pos = 0;
private long limit;
public LimitedInputStream(InputStream is, long limit) {
this.is = is;
this.limit = limit;
}
@Override
public int read() throws IOException {
if (pos >= limit) {
return -1;
}
pos++;
return is.read();
}
@Override
public int available() throws IOException {
int avail = is.available();
if (pos + avail > limit) {
avail = (int)(limit - pos);
}
return avail;
}
}