Skip to content

Instantly share code, notes, and snippets.

@apage43
Last active December 21, 2015 21:29
Show Gist options
  • Save apage43/6369005 to your computer and use it in GitHub Desktop.
Save apage43/6369005 to your computer and use it in GitHub Desktop.
package dumper;
import com.couchbase.client.TapClient;
import net.spy.memcached.tapmessage.ResponseMessage;
import java.net.URI;
import java.util.ArrayList;
import java.util.zip.InflaterOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
public class DumpDB {
public static byte[] inflate(byte[] input) throws java.io.IOException {
final ByteArrayInputStream inbytes = new ByteArrayInputStream(input);
final ByteArrayOutputStream outbytes = new ByteArrayOutputStream();
final InflaterOutputStream inflater = new InflaterOutputStream(outbytes);
while(inbytes.available() > 0) {
inflater.write(inbytes.read());
}
return outbytes.toByteArray();
}
public static void main(String[] args) throws Exception {
final ArrayList<URI> urilist = new ArrayList<URI>();
urilist.add(new URI("http://mango.hq.couchbase.com:8091/pools"));
// Couchbase URL, bucket, password
final TapClient tapclient = new TapClient(urilist, "funkytown","");
tapclient.tapDump("dumpdb");
while(tapclient.hasMoreMessages()) {
ResponseMessage msg = tapclient.getNextMessage();
if(msg != null) {
System.out.println("Got key: " + msg.getKey());
System.out.println("Got value: " + new String(inflate(msg.getValue())));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment