lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicolas Maisonneuve" <n.maisonne...@hotPop.com>
Subject Fw: Betreff: Copy Directory to Directory function ( backup)
Date Thu, 15 Jan 2004 14:21:22 GMT

----- Original Message ----- 
From: "Nick Smith" <nick.smith@techop.ch>
To: <n.maisonneuve@hotPop.com>
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: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Mime
View raw message