----- Original Message ----- From: "Nick Smith" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, January 15, 2004 2:58 PM Subject: Betreff: Copy Directory to Directory function ( backup)
> Hi Nico, > This is the method that I use for backing up my indices... > > Good Luck! > > Nick > > /** > * Copy contents of <code>dir</code>, erasing current contents. > * > * This can be used to write a memory-based index to disk. > * > * @param dir a <code>Directory</code> value > * @exception IOException if an error occurs > */ > public void copyDir(Directory dir) throws IOException { > // remove current contents of directory > create(); > > final String[] ar = dir.list(); > for (int i = 0; i < ar.length; i++) > { > // make place on disk > OutputStream os = createFile(ar[i]); > // read current file > InputStream is = dir.openFile(ar[i]); > > final int MAX_CHUNK_SIZE = 131072; > byte[] buf = new byte[MAX_CHUNK_SIZE]; > int remainder = (int)is.length(); > while (remainder > 0) { > int chunklen = (remainder > MAX_CHUNK_SIZE ? MAX_CHUNK_SIZE : remainde! > is.readBytes(buf, 0, chunklen); > os.writeBytes(buf, chunklen); > remainder -= chunklen; > } > > // graceful cleanup > is.close(); > os.close(); > } > } > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]