lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Isakson" <Eric.Isak...@sas.com>
Subject RE: Converting a Directory to a RAMDirectory
Date Thu, 17 Oct 2002 18:42:33 GMT
Why not add this code to a RAMDirectory constructor like:

	public RAMDirectory(Directory d) throws IOException {
		this();
		final String[] ar = d.list();
		for (int i = 0; i < ar.length; i++) {
			// make place on ram disk
			OutputStream os = 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
			is.close();
			os.close();
		}
	}

--
Eric D. Isakson        SAS Institute Inc.
Application Developer  SAS Campus Drive
XML Technologies       Cary, NC 27513
(919) 531-3639         http://www.sas.com


--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message