org.archive.wayback.util.flatfile
Class FlatFile

java.lang.Object
  extended by org.archive.wayback.util.flatfile.FlatFile
Direct Known Subclasses:
CachedFile, CDXIndex

public class FlatFile
extends Object

Subclass of File, which allows binary searching, returning Iterators that allow scanning forwards and backwards thru the (sorted) file starting from a particular prefix.

Version:
$Date: 2010-09-29 05:28:38 +0700 (Wed, 29 Sep 2010) $, $Revision: 3262 $
Author:
brad

Field Summary
protected  File file
           
 
Constructor Summary
FlatFile()
           
FlatFile(File parent, String child)
           
FlatFile(String path)
           
 
Method Summary
 long findKeyOffset(RandomAccessFile fh, String key)
          Binary search thru RandomAccessFile argument to locate the first line prefixed by key argument.
 long findKeyOffsetLT(RandomAccessFile fh, String key)
           
 long getLastMatchOffset()
           
 String getPath()
           
 CloseableIterator<String> getRecordIterator(String prefix)
           
 CloseableIterator<String> getRecordIteratorLT(String prefix)
           
 ReverseRecordIterator getReverseRecordIterator(String prefix)
           
 CloseableIterator<String> getSequentialIterator()
           
static void main(String[] args)
           
 void setPath(String path)
           
 void store(Iterator<String> itr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected File file
Constructor Detail

FlatFile

public FlatFile()

FlatFile

public FlatFile(File parent,
                String child)
Parameters:
parent -
child -

FlatFile

public FlatFile(String path)
Parameters:
path -
Method Detail

setPath

public void setPath(String path)
Parameters:
path - to set

getPath

public String getPath()
Returns:
current String path, or null if none has been set

findKeyOffset

public long findKeyOffset(RandomAccessFile fh,
                          String key)
                   throws IOException
Binary search thru RandomAccessFile argument to locate the first line prefixed by key argument. As a side effect, the RandomAccessFile's position is also set to the start of the first matching line.

Parameters:
fh -
key -
Returns:
long offset where first record prefixed with key is found
Throws:
IOException

findKeyOffsetLT

public long findKeyOffsetLT(RandomAccessFile fh,
                            String key)
                     throws IOException
Throws:
IOException

getLastMatchOffset

public long getLastMatchOffset()
Returns:
Returns the lastMatchOffset.

getSequentialIterator

public CloseableIterator<String> getSequentialIterator()
                                                throws IOException
Returns:
Iterator returning one String object for each line in the file.
Throws:
IOException

getRecordIterator

public CloseableIterator<String> getRecordIterator(String prefix)
                                            throws IOException
Parameters:
prefix -
Returns:
Iterator for records beggining with key
Throws:
IOException

getRecordIteratorLT

public CloseableIterator<String> getRecordIteratorLT(String prefix)
                                              throws IOException
Throws:
IOException

getReverseRecordIterator

public ReverseRecordIterator getReverseRecordIterator(String prefix)
                                               throws IOException
Parameters:
prefix -
Returns:
ReverseRecordIterator positioned to return the first line BEFORE prefix at the first call to readPrevLine().
Throws:
IOException

store

public void store(Iterator<String> itr)
           throws IOException
Throws:
IOException

main

public static void main(String[] args)
Parameters:
args -


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