import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; import java.net.URLEncoder; public class CouchDBQ3 { public static void main(String[] args) throws IOException { final String base = "localhost:5984/"; Scanner scan = new Scanner(System.in); BufferedWriter writer = new BufferedWriter(new FileWriter("generatorOutput.bat")); String sourceDB; String destDB; ArrayList docs = new ArrayList(); System.out.println("This program will generate a script to clone one DB's documents to another DB."); System.out.print("\nPlease enter the source DB name (to copy from): "); sourceDB = scan.nextLine(); System.out.print("Please enter the new DB name (to copy to): "); destDB = scan.nextLine(); System.out.println("\nPlease enter the names of the documents to copy: (type !finish to finish)"); String temp = ""; while (true) { System.out.print('\t'); temp = scan.nextLine(); if (temp.equals("!finish")) break; docs.add(temp); } //make DB writer.write("curl -X PUT "+base+destDB+"\n"); System.out.println("curl -X PUT "+base+destDB+""); //populate for (int i = 0; i < docs.size(); i++) { String surl = URLEncoder.encode(docs.get(i), "UTF-8").replace("%", "%%"); String durl = URLEncoder.encode(docs.get(i), "UTF-8").replace("%", "%%"); writer.write("curl -X GET "+base+sourceDB+"/"+surl+" > f"+i+".json\n"); System.out.println("curl -X GET "+base+sourceDB+"/"+surl+" > f"+i+".json"); writer.write("curl -X PUT "+base+destDB+"/"+durl+" -d @f"+i+".json\n\n"); System.out.println("curl -X PUT "+base+destDB+"/"+durl+" -d @f"+i+".json"); } writer.close(); } }