lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Spencer, Dave" <>
Subject Converting a FSDirectory (on disk index) to a RAMDirectory
Date Thu, 21 Feb 2002 21:40:07 GMT

Inspired by the talk on slashdot recently about google using solid state
disks I wanted to play around w/ Lucene runnning purely out of memory.

Could anyone glance at this and verify that this code is correct.
Goal is to convert an existing, on-disk, index to a RAMDirectory, which
presumably is purely in memory.

If the code is correct I'd suggest someone w/ CVS powers adding it to
source base - maybe a static method in  RAMDirectory itself.

public static RAMDirectory convert( String path)
  throws IOException
  final RAMDirectory ram = new RAMDirectory();
  final Directory d = FSDirectory.getDirectory( path, false);
  final String[] ar = d.list();
  for ( int i = 0; i< ar.length; i++)
   // make place on ram disk
   OutputStream os = ram.createFile( ar[ i]);
   // read current file
   InputStream is = d.openFile( ar[ i]);
   // and copy to ram disk
   int len = (int) is.length();   
   byte[] buf = new byte[ len];
   is.readBytes( buf, 0, len);
   os.writeBytes( buf, len);
   // graceful cleanup
  return ram;

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message