diff options
author | jonmv <venstad@gmail.com> | 2022-11-07 15:20:12 +0100 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-11-07 15:20:12 +0100 |
commit | 4a6f833f3265a955c1a9d793fdb2ebb9eb8e0dd0 (patch) | |
tree | 231cc7ea990f1b003ccd523ab4202917a66e4954 /vespajlib/src/main/java/com/yahoo/io | |
parent | 54eb99038030a5eee2cbc16fbda76c0375bcc52c (diff) |
Revert "Merge pull request #24781 from vespa-engine/revert-24777-jonmv/reapply-app-streams"
This reverts commit adc1c1fa16945d9f29778706f5bf8161434c2361, reversing
changes made to a0e9b51aaf01a425dbd6cdd1fbc8fd5ce066a9bb.
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/io')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/io/LazyInputStream.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/LazyInputStream.java b/vespajlib/src/main/java/com/yahoo/io/LazyInputStream.java new file mode 100644 index 00000000000..3ff7ada6b59 --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/io/LazyInputStream.java @@ -0,0 +1,53 @@ +package com.yahoo.io; + +import java.io.IOException; +import java.io.InputStream; +import java.util.function.Supplier; + +/** + * Input stream wrapping an input stream supplier, which doesn't have content yet at declaration time. + * + * @author jonmv + */ +public class LazyInputStream extends InputStream { + + private Supplier<InputStream> source; + private InputStream delegate; + + public LazyInputStream(Supplier<InputStream> source) { + this.source = source; + } + + private InputStream in() { + if (delegate == null) { + delegate = source.get(); + source = null; + } + return delegate; + } + + @Override + public int read() throws IOException { return in().read(); } + + @Override + public int read(byte[] b, int off, int len) throws IOException { return in().read(b, off, len); } + + @Override + public long skip(long n) throws IOException { return in().skip(n); } + + @Override + public int available() throws IOException { return in().available(); } + + @Override + public void close() throws IOException { in().close(); } + + @Override + public synchronized void mark(int readlimit) { in().mark(readlimit); } + + @Override + public synchronized void reset() throws IOException { in().reset(); } + + @Override + public boolean markSupported() { return in().markSupported(); } + +} |