I had this issue: Why does my InputStream hold old values?
I thought I was able to solve it by the answer provided, but I haven't.
I am sending an IR signal to the IR receiver which is passed through the BT module to the InputStream of the Android application. Every time I press a button on the emitter, I send 100 bytes which then I expect to get into the InputStream.
Is there a way to ignore all incoming bytes after I get one packet for 3 seconds? Even if they arrive I want to skip them, simply don't put them into buffer. But after those 3 seconds I want again to listen to the incoming InputStream
bytes flow.
I need that, because sometimes there are some dummy bytes coming from the IR emitter, or when user accidentally presses the button twice (I don't want the data to be sent twice). Simply I want some 3 seconds "cooldown".
My read
function:
public int read(final InputStream input, final byte[] buffer) throws IOException {
int remaining = buffer.length;
while (remaining > 20) {
final int location = buffer.length - remaining;
final int count = input.read(buffer, location, remaining);
if (count == -1) { // EOF
break;
}
remaining -= count;
}
return buffer.length - remaining;
}
May I use a skip(long n)
function? Can I define any number n
, since I don't know how many bytes do I want to skip? I just want to skip all which came within those 3 seconds.