edu.nmu.io
Class DelegatedInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--edu.nmu.io.DelegatedInputStream

public class DelegatedInputStream
extends java.io.InputStream

Reads input from another InputStream

By using delegation as a level of abstraction, applications can change the source of input without needing to reference a new InputStream. This is especially useful for changing the source of input for final references such as System.in

It is important to note that this class is not thread safe. A call to the delegated InputStream could forseeably hang waiting for new input while another Thread calls setStream(InputStream)

Since:
jdk1.4
Version:
1.0, 01/24/2003
Author:
Matt Murphy

Constructor Summary
DelegatedInputStream(java.io.InputStream in)
          Creates a new DelegatedInputStream from the specified InputStream
 
Method Summary
 int available()
           
 void close()
           
 java.io.InputStream getStream()
          Gets the InputStream used for delegation
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void reset()
           
 void setStream(java.io.InputStream in)
          Sets a new InputStream to be used for delegation
 long skip(long n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatedInputStream

public DelegatedInputStream(java.io.InputStream in)
Creates a new DelegatedInputStream from the specified InputStream

Parameters:
in - the InputStream to which calls should be delegated
Method Detail

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
java.io.IOException

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream
java.io.IOException

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.io.InputStream
java.io.IOException

mark

public void mark(int readlimit)
Overrides:
mark in class java.io.InputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class java.io.InputStream

read

public int read(byte[] b)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Overrides:
reset in class java.io.InputStream
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Overrides:
skip in class java.io.InputStream
java.io.IOException

getStream

public java.io.InputStream getStream()
Gets the InputStream used for delegation

Returns:
the InputStream

setStream

public void setStream(java.io.InputStream in)
Sets a new InputStream to be used for delegation

Parameters:
in - the InputStream to which calls should be delegated