Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.mockobjects.io
Class MockFileInputStream  view MockFileInputStream download MockFileInputStream.java

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FileInputStream
          extended bycom.mockobjects.io.MockFileInputStream
All Implemented Interfaces:
java.io.Closeable

public class MockFileInputStream
extends java.io.FileInputStream


Field Summary
static java.lang.String KNOWN_FILE
           
private  java.lang.String myContents
           
private  int myIndex
           
 
Fields inherited from class java.io.FileInputStream
 
Constructor Summary
private MockFileInputStream()
           
 
Method Summary
 int available()
          This method returns the number of bytes that can be read from this stream before a read can block.
 void mark(int readlimit)
          This method marks a position in the input to which the stream can be "reset" by calling the reset() method.
static MockFileInputStream newMockFileInputStream()
           
 int read()
          This method reads an unsigned byte from the input stream and returns it as an int in the range of 0-255.
 int read(byte[] b)
          This method reads bytes from a stream and stores them into a caller supplied buffer.
 int read(byte[] b, int off, int len)
          This method read bytes from a stream and stores them into a caller supplied buffer.
 void setupContents(java.lang.String contents)
           
 long skip(long n)
          This method skips the specified number of bytes in the stream.
 
Methods inherited from class java.io.FileInputStream
close, finalize, getChannel, getFD
 
Methods inherited from class java.io.InputStream
markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KNOWN_FILE

public static final java.lang.String KNOWN_FILE
See Also:
Constant Field Values

myContents

private java.lang.String myContents

myIndex

private int myIndex
Constructor Detail

MockFileInputStream

private MockFileInputStream()
                     throws java.io.FileNotFoundException
Method Detail

newMockFileInputStream

public static MockFileInputStream newMockFileInputStream()

available

public int available()
              throws java.io.IOException
Description copied from class: java.io.FileInputStream
This method returns the number of bytes that can be read from this stream before a read can block. A return of 0 indicates that blocking might (or might not) occur on the very next read attempt.

This method returns the number of unread bytes remaining in the file if the descriptor being read from is an actual file. If this method is reading from a ''special'' file such a the standard input, this method will return the appropriate value for the stream being read.

Be aware that reads on plain files that do not reside locally might possibly block even if this method says they should not. For example, a remote server might crash, preventing an NFS mounted file from being read.


mark

public void mark(int readlimit)
Description copied from class: java.io.InputStream
This method marks a position in the input to which the stream can be "reset" by calling the reset() method. The parameter @code{readlimit} is the number of bytes that can be read from the stream after setting the mark before the mark becomes invalid. For example, if mark() is called with a read limit of 10, then when 11 bytes of data are read from the stream before the reset() method is called, then the mark is invalid and the stream object instance is not required to remember the mark.

This method does nothing in this class, but subclasses may override it to provide mark/reset functionality.


read

public int read()
         throws java.io.IOException
Description copied from class: java.io.FileInputStream
This method reads an unsigned byte from the input stream and returns it as an int in the range of 0-255. This method also will return -1 if the end of the stream has been reached.

This method will block until the byte can be read.


read

public int read(byte[] b)
         throws java.io.IOException
Description copied from class: java.io.FileInputStream
This method reads bytes from a stream and stores them into a caller supplied buffer. This method attempts to completely fill the buffer, but can return before doing so. The actual number of bytes read is returned as an int. A -1 is returned to indicate the end of the stream.

This method will block until some data can be read.

This method operates by calling an overloaded read method like so: read(buf, 0, buf.length)


read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Description copied from class: java.io.FileInputStream
This method read bytes from a stream and stores them into a caller supplied buffer. It starts storing the data at index offset into the buffer and attempts to read len bytes. This method can return before reading the number of bytes requested. The actual number of bytes read is returned as an int. A -1 is returned to indicate the end of the stream.

This method will block until some data can be read.


setupContents

public void setupContents(java.lang.String contents)

skip

public long skip(long n)
          throws java.io.IOException
Description copied from class: java.io.FileInputStream
This method skips the specified number of bytes in the stream. It returns the actual number of bytes skipped, which may be less than the requested amount.