mirror of
https://github.com/revanced/jadb.git
synced 2025-02-11 09:36:48 +01:00
Filtering out 0x0d, 0x0a sequences from shell commands. Makes screenshotting work again. :-)
This commit is contained in:
parent
c9a0a59ace
commit
68e92d14f4
45
src/se/vidstige/jadb/LookBackFilteringOutputStream.java
Normal file
45
src/se/vidstige/jadb/LookBackFilteringOutputStream.java
Normal file
@ -0,0 +1,45 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
public class LookBackFilteringOutputStream extends FilterOutputStream {
|
||||
private final ArrayDeque<Byte> buffer;
|
||||
private final int lookBackBufferSize;
|
||||
|
||||
protected LookBackFilteringOutputStream(OutputStream inner, int lookBackBufferSize)
|
||||
{
|
||||
super(inner);
|
||||
this.lookBackBufferSize = lookBackBufferSize;
|
||||
this.buffer = new ArrayDeque<Byte>(lookBackBufferSize);
|
||||
}
|
||||
|
||||
protected void unwrite() {
|
||||
buffer.removeFirst();
|
||||
}
|
||||
|
||||
protected ArrayDeque<Byte> lookback() {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int c) throws IOException {
|
||||
buffer.addLast((byte) c);
|
||||
flushBuffer(lookBackBufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
flushBuffer(0);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
private void flushBuffer(int size) throws IOException {
|
||||
while (buffer.size() > size) {
|
||||
Byte b = buffer.removeFirst();
|
||||
out.write(b);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user