Skip to content

Instantly share code, notes, and snippets.

@adamv
Last active August 29, 2015 14:27
Show Gist options
  • Save adamv/0e706463d24f1416d876 to your computer and use it in GitHub Desktop.
Save adamv/0e706463d24f1416d876 to your computer and use it in GitHub Desktop.
Buh.
class WorkaroundInputStream extends FilterInputStream {
static final int CONTROL_Z = 26;
protected WorkaroundInputStream(InputStream in) {
super(in);
}
@Override
public int read() throws IOException {
int nextByte = super.read();
while (nextByte == CONTROL_Z) {
nextByte = super.read();
}
return nextByte;
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
int bytesRead = super.read(b, off, len);
// filter out control-zs if any were read
int i = 0;
while (i < bytesRead) {
if (b[off + i] == CONTROL_Z) {
// move following bytes up a slot
System.arraycopy(b, off + i + 1, b, off + i, bytesRead - (i + 1));
bytesRead--;
}
i++;
}
return bytesRead;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment