org.abstracthorizon.mercury.common.io
Class TempStorage

java.lang.Object
  extended by org.abstracthorizon.mercury.common.io.TempStorage

public class TempStorage
extends Object

This is temporary storage. It stores first defined number of bytes in memory and if more are written then it creates a temporary file and continues to write to the file

Author:
Daniel Sendula

Nested Class Summary
protected  class TempStorage.OutputStreamImpl
          Output stream implementation
 
Field Summary
protected  ByteArrayOutputStream buffer
          Buffer array output stream
protected  OutputStream defaultOutputStream
          Default output stream
protected  File file
          Temporary file
static int MAX_MEMORY
          Default maximum number of bytes to be stored in memory
protected  int maxMemory
          Number of bytes to be stored in memory
protected  OutputStream os
          Output stream
protected  String prefix
          Prefix
protected  int size
          Size
protected  String suffix
          Suffix
 
Constructor Summary
TempStorage()
          Constructor
TempStorage(String prefix, String suffix)
          Constructor
TempStorage(String prefix, String suffix, int maxMemory)
          Constructor
 
Method Summary
 void clear()
          Clears storage for new use
 File getFile()
          Returns temporary file (or null)
 InputStream getInputStream()
          Returns input stream (file or memory buffer)
 OutputStream getOutputStream()
          Returns default output stream
 int getSize()
          Returns size of storage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_MEMORY

public static final int MAX_MEMORY
Default maximum number of bytes to be stored in memory

See Also:
Constant Field Values

maxMemory

protected int maxMemory
Number of bytes to be stored in memory


file

protected File file
Temporary file


defaultOutputStream

protected OutputStream defaultOutputStream
Default output stream


os

protected OutputStream os
Output stream


buffer

protected ByteArrayOutputStream buffer
Buffer array output stream


size

protected int size
Size


prefix

protected String prefix
Prefix


suffix

protected String suffix
Suffix

Constructor Detail

TempStorage

public TempStorage()
Constructor


TempStorage

public TempStorage(String prefix,
                   String suffix)
Constructor

Parameters:
prefix - file prefix
suffix - file suffix

TempStorage

public TempStorage(String prefix,
                   String suffix,
                   int maxMemory)
Constructor

Parameters:
prefix - prefix
suffix - suffix
maxMemory - maximum number of bytes
Method Detail

getFile

public File getFile()
Returns temporary file (or null)

Returns:
temporary file (or null)

getSize

public int getSize()
Returns size of storage

Returns:
size of storage

getOutputStream

public OutputStream getOutputStream()
Returns default output stream

Returns:
default output stream

getInputStream

public InputStream getInputStream()
                           throws IOException
Returns input stream (file or memory buffer)

Returns:
input stream (file or memory buffer)
Throws:
IOException

clear

public void clear()
           throws IOException
Clears storage for new use

Throws:
IOException


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.