Skip to content
Browse files

Add utility function to copy database file

  • Loading branch information...
1 parent f7ada29 commit d05788b422c49c7b95298ad47c9d26ecfde12d42 @daleharvey daleharvey committed Aug 14, 2011
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/com/couchbase/libcouch/CouchbaseEmbeddedServer.java
View
30 src/com/couchbase/libcouch/CouchbaseEmbeddedServer.java
@@ -1,9 +1,16 @@
package com.couchbase.libcouch;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.res.AssetManager;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
@@ -74,6 +81,29 @@ public ServiceConnection startCouchbase(Context ctx, String release) {
}
/*
+ * This will copy a database from the assets folder into the
+ * couch database directory
+ * NOTE: Databases that use snappy encoding will not currently
+ * be able to be opened
+ */
+ public void installDatabase(String fileName) throws IOException {
+ File db = new File(externalPath() + "/db/" + fileName);
+ if (!db.exists()) {
+ AssetManager assetManager = ctx.getAssets();
+ InputStream in = assetManager.open(fileName);
+ OutputStream out = new FileOutputStream(db);
+
+ byte[] buffer = new byte[1024];
+ int read;
+ while((read = in.read(buffer)) != -1){
+ out.write(buffer, 0, read);
+ }
+ in.close();
+ out.close();
+ }
+ }
+
+ /*
* This holds the connection to the CouchDB Service
*/
private final static ServiceConnection mConnection = new ServiceConnection() {

0 comments on commit d05788b

Please sign in to comment.
Something went wrong with that request. Please try again.