Last active
August 29, 2015 14:27
-
-
Save adamv/0e706463d24f1416d876 to your computer and use it in GitHub Desktop.
Buh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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