de.schlichtherle.io.util
Class SynchronizedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by de.schlichtherle.io.util.SynchronizedInputStream
All Implemented Interfaces:
Closeable

public class SynchronizedInputStream
extends InputStream

A decorator which synchronizes all access to an InputStream via an object provided to its constructor.

Since:
TrueZIP 6.4
Version:
TrueZIP 6.7
Author:
Christian Schlichtherle

Field Summary
protected  InputStream in
          The decorated input stream.
protected  Object lock
          The object to synchronize on - never null.
 
Constructor Summary
SynchronizedInputStream(InputStream in)
          Constructs a new synchronized input stream.
SynchronizedInputStream(InputStream in, Object lock)
          Constructs a new synchronized input stream.
 
Method Summary
 int available()
           
 void close()
          Synchronizes on the lock and calls doClose().
protected  void doClose()
          Closes the underlying stream.
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void reset()
           
 long skip(long n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lock

protected final Object lock
The object to synchronize on - never null.


in

protected InputStream in
The decorated input stream.

Constructor Detail

SynchronizedInputStream

public SynchronizedInputStream(InputStream in)
Constructs a new synchronized input stream. This object will synchronize on itself.

Parameters:
in - The input stream to wrap in this decorator.

SynchronizedInputStream

public SynchronizedInputStream(InputStream in,
                               Object lock)
Constructs a new synchronized input stream.

Parameters:
in - The input stream to wrap in this decorator.
lock - The object to synchronize on. If null, then this object is used, not the stream.
Method Detail

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

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

read

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

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Synchronizes on the lock and calls doClose().

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

doClose

protected void doClose()
                throws IOException
Closes the underlying stream. This method is not synchronized!

Throws:
IOException

mark

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

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream