de.rico.engine.util
Class LoopingByteInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.ByteArrayInputStream
          extended by de.rico.engine.util.LoopingByteInputStream
All Implemented Interfaces:
java.io.Closeable

public class LoopingByteInputStream
extends java.io.ByteArrayInputStream

The LoopingByteInputStream is a ByteArrayInputStream that loops indefinitly. The looping stops when the close() method is called.

Possible ideas to extend this class:

Author:
David Brackeen (taken from the book "Developing games with Java")

Constructor Summary
LoopingByteInputStream(byte[] buffer)
          Creates a new LoopingByteInputStream with the specified byte array.
 
Method Summary
 void close()
          Closes the stream.
 int read(byte[] buffer, int offset, int length)
          Reads length bytes from the array.
 
Methods inherited from class java.io.ByteArrayInputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.io.InputStream
read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoopingByteInputStream

public LoopingByteInputStream(byte[] buffer)
Creates a new LoopingByteInputStream with the specified byte array. The array is not copied.

Method Detail

read

public int read(byte[] buffer,
                int offset,
                int length)
Reads length bytes from the array. If the end of the array is reached, the reading starts over from the beginning of the array. Returns -1 if the array has been closed.

Overrides:
read in class java.io.ByteArrayInputStream

close

public void close()
           throws java.io.IOException
Closes the stream. Future calls to the read() methods will return 1.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.ByteArrayInputStream
Throws:
java.io.IOException