edu.mit.jverbnet.util
Class ByteBufferInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by edu.mit.jverbnet.util.ByteBufferInputStream
All Implemented Interfaces:
Closeable

public class ByteBufferInputStream
extends InputStream

Adapts a ByteBuffer to an InputStream.

Since:
JVerbnet 1.0.0
Version:
1.0.0
Author:
Mark A. Finlayson

Field Summary
protected  ByteBuffer buffer
           
protected  int mark
           
protected  RandomAccessFile raFile
           
 
Constructor Summary
ByteBufferInputStream(ByteBuffer buffer)
          Creates a new input stream that wraps the specified byte buffer.
ByteBufferInputStream(File file)
          Creates a new input stream that wraps the a byte buffer attached to the specified file.
 
Method Summary
 int available()
           
protected  void checkBuffer()
          Throws an exception if the stream has been closed
 void close()
           
 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

buffer

protected ByteBuffer buffer

raFile

protected RandomAccessFile raFile

mark

protected int mark
Constructor Detail

ByteBufferInputStream

public ByteBufferInputStream(ByteBuffer buffer)
Creates a new input stream that wraps the specified byte buffer.

Parameters:
buffer - the byte buffer to be wrapped; may not be null
Throws:
NullPointerException - if the specified buffer is null
Since:
JVerbnet 1.0.0

ByteBufferInputStream

public ByteBufferInputStream(File file)
                      throws IOException
Creates a new input stream that wraps the a byte buffer attached to the specified file.

Parameters:
file - the file on which the stream should be opened; may not be null
Throws:
NullPointerException - if the specified file is null
IOException
Since:
JVerbnet 1.0.0
Method Detail

checkBuffer

protected void checkBuffer()
                    throws IOException
Throws an exception if the stream has been closed

Throws:
IOException - if the stream has been closed
Since:
JVerbnet 1.0.0

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
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
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


Copyright © 2012 Massachusetts Institute of Technology. All Rights Reserved.