summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-12-20 18:38:08 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2021-12-21 01:18:09 +0100
commite8f31cbe437ee969f4dd0490a0409b62b2fd045d (patch)
tree694203ae0423448b259c924c167ecb5584c36229 /vespajlib/src/main/java/com
parent5d6f586ccff9880a40366d51f75db5234795c0fc (diff)
GC deprecated junit assertThat.
Diffstat (limited to 'vespajlib/src/main/java/com')
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/TeeInputStream.java100
1 files changed, 0 insertions, 100 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/TeeInputStream.java b/vespajlib/src/main/java/com/yahoo/io/TeeInputStream.java
deleted file mode 100644
index c199fedf395..00000000000
--- a/vespajlib/src/main/java/com/yahoo/io/TeeInputStream.java
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.io;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.IOException;
-
-/**
- * Forwards input from a source InputStream while making a copy of it into an outputstream.
- * Note that it also does read-ahead and copies up to 64K of data more than was used.
- *
- * @author arnej
- */
-class TeeInputStream extends InputStream {
- final InputStream src;
- final OutputStream dst;
-
- static final int CAPACITY = 65536;
-
- byte[] buf = new byte[CAPACITY];
- int readPos = 0;
- int writePos = 0;
-
- private int inBuf() { return writePos - readPos; }
-
- private void fillBuf() throws IOException {
- if (readPos == writePos) {
- readPos = 0;
- writePos = 0;
- }
- if (readPos * 3 > CAPACITY) {
- int had = inBuf();
- System.arraycopy(buf, readPos, buf, 0, had);
- readPos = 0;
- writePos = had;
- }
- int wantToRead = CAPACITY - writePos;
- if (inBuf() > 0) {
- // if we have data already, do not block, read only what is available
- wantToRead = Math.min(wantToRead, src.available());
- }
- if (wantToRead > 0) {
- int got = src.read(buf, writePos, wantToRead);
- if (got > 0) {
- dst.write(buf, writePos, got);
- writePos += got;
- }
- }
- }
-
- /** Construct a Tee */
- public TeeInputStream(InputStream from, OutputStream to) {
- super();
- this.src = from;
- this.dst = to;
- }
-
- @Override
- public int available() throws IOException {
- return inBuf() + src.available();
- }
-
- @Override
- public void close() throws IOException {
- src.close();
- dst.close();
- }
-
- @Override
- public int read() throws IOException {
- fillBuf();
- if (inBuf() > 0) {
- int r = buf[readPos++];
- return r & 0xff;
- }
- return -1;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- if (len <= 0) {
- return 0;
- }
- fillBuf();
- int had = inBuf();
- if (had > 0) {
- len = Math.min(len, had);
- System.arraycopy(buf, readPos, b, off, len);
- readPos += len;
- return len;
- }
- return -1;
- }
-
-}