com.monkeycoder.monkeynetwork
Class TurboBuffer

java.lang.Object
  extended by com.monkeycoder.monkeynetwork.TurboBuffer

public class TurboBuffer
extends java.lang.Object

This class is for buffering network data quickly and intelligently. It uses memory for smaller content and a file storage device for larger. This buffer system is always in either read or write mode, but never both. A new TurboBuffer starts in write mode and remains in write mode until an InputStream is requested. It can be returned to write mode by calling reset().

This class uses monkeynetwork.ini and requires the following parameters:

Author:
David Stephens

Constructor Summary
TurboBuffer()
          Creates a TurboBuffer for content storage.
 
Method Summary
 void dumpToFile(java.io.File inTargetFile)
          Dumps the contents of the TurboBuffer to a File.
 java.io.InputStream getInputStream()
          Request an InputStream providing access to the data stored in the TurboBuffer.
 void reset()
          Fully resets this TurboBuffer.
 void write(byte inData)
          Write a single byte into the TurboBuffer.
 void write(byte[] inData)
          Write an entire array of bytes into the TurboBuffer.
 void write(byte[] inData, int inOffset, int inLength)
          Write part of an array of bytes into the TurboBuffer.
 void write(int inData)
          Write the least significant byte of a single integer into the TurboBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TurboBuffer

public TurboBuffer()
Creates a TurboBuffer for content storage.

Method Detail

reset

public void reset()
Fully resets this TurboBuffer. All internal states are reset and any temporary files in use are deleted. This also closes the active InputStream if the TurboBuffer was currently in file backed mode.


write

public void write(byte[] inData)
           throws java.io.IOException,
                  MonkeyException
Write an entire array of bytes into the TurboBuffer.

Parameters:
inData - Array containing the data to write.
Throws:
java.io.IOException - When one is thrown by underlying code.
MonkeyException - If an InputStream to the stored data has already been requested.

write

public void write(byte[] inData,
                  int inOffset,
                  int inLength)
           throws java.io.IOException,
                  MonkeyException
Write part of an array of bytes into the TurboBuffer.

Parameters:
inData - Array containing the data to write.
inOffset - The starting location of data to write from the array.
inLength - The length of data to write from the array.
Throws:
java.io.IOException - When one is thrown by underlying code.
MonkeyException - If an InputStream to the stored data has already been requested.

write

public void write(int inData)
           throws java.io.IOException,
                  MonkeyException
Write the least significant byte of a single integer into the TurboBuffer.

Parameters:
inData - The integer to write.
Throws:
java.io.IOException - When one is thrown by underlying code.
MonkeyException - If an InputStream to the stored data has already been requested.

write

public void write(byte inData)
           throws java.io.IOException,
                  MonkeyException
Write a single byte into the TurboBuffer.

Parameters:
inData - The byte of data to write.
Throws:
java.io.IOException - When one is thrown by underlying code.
MonkeyException - If an InputStream to the stored data has already been requested.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Request an InputStream providing access to the data stored in the TurboBuffer. This buffer system is always in either read or write mode, but never both. Requesting an InputStream will switch the buffer into read mode. It can be returned to write mode by calling reset().

Returns:
An InputStream providing access to the data stored in the TurboBuffer.
Throws:
java.io.IOException - When one is thrown by underlying code.
See Also:
reset()

dumpToFile

public void dumpToFile(java.io.File inTargetFile)
                throws java.io.IOException
Dumps the contents of the TurboBuffer to a File. This process will request an InputStream which shuts off writing to this buffer.

Throws:
java.io.IOException - When one is thrown by underlying code.
See Also:
getInputStream()