1 16 package org.outerj.daisy.backupTool.dbDump; 17 18 import java.io.InputStream ; 19 import java.io.OutputStream ; 20 21 import org.outerj.daisy.backupTool.BackupHelper; 22 23 public abstract class AbstractDbDumper implements DbDumper { 24 25 protected String dbName; 26 27 protected String host; 28 29 protected Integer port; 30 31 protected String password; 32 33 protected String username; 34 35 public AbstractDbDumper (String dbName, String host, Integer port, String password, String username) { 36 this.dbName = dbName; 37 this.host = host; 38 this.port = port; 39 this.password = password; 40 this.username = username; 41 } 42 43 protected static void handleRuntimeProcess(Process process, InputStream is, 44 OutputStream os) throws Exception { 45 InputStream pris = process.getInputStream(); 46 InputStream pres = process.getErrorStream(); 47 OutputStream pros = process.getOutputStream(); 48 Thread writeToProcess = null; 49 Thread readFromProcess = null; 50 Thread readErrors; 51 try { 52 if (is != null) { 53 writeToProcess = new Thread ( 54 new BackupHelper.RunnableStreamCopy(is, pros)); 55 writeToProcess.start(); 56 } 57 if (os != null) { 58 readFromProcess = new Thread ( 59 new BackupHelper.RunnableStreamCopy(pris, os)); 60 readFromProcess.start(); 61 } 62 readErrors = new Thread (new BackupHelper.RunnableStreamCopy(pres, 63 System.err)); 64 readErrors.start(); 65 66 if (writeToProcess != null) 67 writeToProcess.join(); 68 pros.close(); 69 70 if (readFromProcess != null) 71 readFromProcess.join(); 72 pris.close(); 73 74 readErrors.join(); 75 pres.close(); 76 77 if (process.waitFor() != 0) 78 throw new RuntimeException (process + " ran with errors."); 79 } finally { 80 pris.close(); 81 pres.close(); 82 pros.close(); 83 } 84 } 85 86 public String getDbName() { 87 return dbName; 88 } 89 90 public void setDbName(String dbName) { 91 this.dbName = dbName; 92 } 93 94 public String getHost() { 95 return host; 96 } 97 98 public void setHost(String host) { 99 this.host = host; 100 } 101 102 public String getPassword() { 103 return password; 104 } 105 106 public void setPassword(String password) { 107 this.password = password; 108 } 109 110 public String getUsername() { 111 return username; 112 } 113 114 public void setUsername(String username) { 115 this.username = username; 116 } 117 118 } | Popular Tags |