summaryrefslogtreecommitdiff
path: root/main/client/src/ProxyOutputStream.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/client/src/ProxyOutputStream.java')
-rw-r--r--main/client/src/ProxyOutputStream.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/main/client/src/ProxyOutputStream.java b/main/client/src/ProxyOutputStream.java
new file mode 100644
index 00000000..339e0150
--- /dev/null
+++ b/main/client/src/ProxyOutputStream.java
@@ -0,0 +1,34 @@
+package mill.main.client;
+
+import java.io.IOException;
+
+public class ProxyOutputStream extends java.io.OutputStream {
+ private java.io.OutputStream out;
+ private int key;
+ public ProxyOutputStream(java.io.OutputStream out, int key){
+ this.out = out;
+ this.key = key;
+ }
+ @Override synchronized public void write(int b) throws IOException {
+ out.write(key);
+ out.write(b);
+ }
+ @Override synchronized public void write(byte[] b) throws IOException {
+ write(b, 0, b.length);
+ }
+ @Override synchronized public void write(byte[] b, int off, int len) throws IOException {
+ int i = 0;
+ while(i < len && i + off < b.length){
+ int chunkLength = Math.min(len - i, 127);
+ out.write(chunkLength * key);
+ out.write(b, off + i, Math.min(b.length - off - i, chunkLength));
+ i += chunkLength;
+ }
+ }
+ @Override public void flush() throws IOException {
+ out.flush();
+ }
+ @Override public void close() throws IOException {
+ out.close();
+ }
+}