001package jmri.jmrix; 002 003import java.io.*; 004 005/** 006 * An input stream where the stream can be replaced on the fly. 007 * 008 * @author Daniel Bergqvist (C) 2024 009 */ 010public class ReplaceableInputStream extends InputStream { 011 012 private volatile InputStream _stream; 013 014 public void replaceStream(InputStream stream) { 015 this._stream = stream; 016 } 017 018 /** {@inheritDoc} */ 019 @Override 020 public int read() throws IOException { 021 return _stream.read(); 022 } 023 024 /** {@inheritDoc} */ 025 @Override 026 public int read(byte b[]) throws IOException { 027 return _stream.read(b); 028 } 029 030 /** {@inheritDoc} */ 031 @Override 032 public int read(byte b[], int off, int len) throws IOException { 033 return _stream.read(b, off, len); 034 } 035 036 /** {@inheritDoc} */ 037 @Override 038 public byte[] readAllBytes() throws IOException { 039 return _stream.readAllBytes(); 040 } 041 042 /** {@inheritDoc} */ 043 @Override 044 public byte[] readNBytes(int len) throws IOException { 045 return _stream.readNBytes(len); 046 } 047 048 /** {@inheritDoc} */ 049 @Override 050 public int readNBytes(byte[] b, int off, int len) throws IOException { 051 return _stream.readNBytes(b, off, len); 052 } 053 054 /** {@inheritDoc} */ 055 @Override 056 public long skip(long n) throws IOException { 057 return _stream.skip(n); 058 } 059 060 /** {@inheritDoc} */ 061 @Override 062 public int available() throws IOException { 063 return _stream.available(); 064 } 065 066 /** {@inheritDoc} */ 067 @Override 068 public void close() throws IOException { 069 _stream.close(); 070 } 071 072 /** {@inheritDoc} */ 073 @Override 074 public synchronized void mark(int readlimit) { 075 _stream.mark(readlimit); 076 } 077 078 /** {@inheritDoc} */ 079 @Override 080 public synchronized void reset() throws IOException { 081 _stream.reset(); 082 } 083 084 /** {@inheritDoc} */ 085 @Override 086 public boolean markSupported() { 087 return _stream.markSupported(); 088 } 089 090 /** {@inheritDoc} */ 091 @Override 092 public long transferTo(OutputStream out) throws IOException { 093 return _stream.transferTo(out); 094 } 095 096}