org.archive.queue
Class DiskStack

java.lang.Object
  extended by org.archive.queue.DiskStack
All Implemented Interfaces:
java.io.Serializable, Stack

public class DiskStack
extends java.lang.Object
implements Stack, java.io.Serializable

A Stack which serializes objects to disk.

Author:
gojomo
See Also:
Serialized Form

Field Summary
protected  long height
          total items in stack
(package private)  HeaderlessObjectInputStream popStream
          stream offering serialization reading from raf
(package private)  HeaderlessObjectOutputStream pushStream
          stream offering serialization writing into raf
(package private)  java.io.RandomAccessFile raf
          random-access file into which bojects are serialized
(package private)  java.io.DataOutputStream rawStream
          stream offering non-serialization writing into raf
protected  java.io.File storage
          the backing file
protected  long topItemPointer
          pointer to top prevIndex + topItem in backing file
 
Constructor Summary
DiskStack(java.io.File storage)
           
 
Method Summary
 void close()
          Close, releasing held resources.
 void discard()
          Close and delete any disk-based storage
 void disconnect()
           
 long height()
          Number of items in the Stack.
 boolean isEmpty()
           
 java.lang.Object peek()
           
 java.lang.Object pop()
          Remove and return item from top of Stack
 void push(java.lang.Object object)
          Add object to top of Stack
 void release()
          Release any OS resources, if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storage

protected java.io.File storage
the backing file


height

protected long height
total items in stack


topItemPointer

protected long topItemPointer
pointer to top prevIndex + topItem in backing file


raf

transient java.io.RandomAccessFile raf
random-access file into which bojects are serialized


rawStream

transient java.io.DataOutputStream rawStream
stream offering non-serialization writing into raf


pushStream

transient HeaderlessObjectOutputStream pushStream
stream offering serialization writing into raf


popStream

transient HeaderlessObjectInputStream popStream
stream offering serialization reading from raf

Constructor Detail

DiskStack

public DiskStack(java.io.File storage)
          throws java.io.IOException
Parameters:
storage -
Throws:
java.io.FileNotFoundException
java.io.IOException
Method Detail

push

public void push(java.lang.Object object)
Description copied from interface: Stack
Add object to top of Stack

Specified by:
push in interface Stack

pop

public java.lang.Object pop()
Description copied from interface: Stack
Remove and return item from top of Stack

Specified by:
pop in interface Stack
Returns:
Item removed from top of Stack

peek

public java.lang.Object peek()
Specified by:
peek in interface Stack
Returns:
Return item from top of Stack without removing it.

height

public long height()
Description copied from interface: Stack
Number of items in the Stack.

Specified by:
height in interface Stack

close

public void close()
           throws java.io.IOException
Close, releasing held resources.

Throws:
java.io.IOException

discard

public void discard()
             throws java.io.IOException
Close and delete any disk-based storage

Throws:
java.io.IOException

disconnect

public void disconnect()

release

public void release()
Description copied from interface: Stack
Release any OS resources, if necessary.

Specified by:
release in interface Stack

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Stack
Returns:
True if empty.


Copyright © 2003-2005 Internet Archive. All Rights Reserved.