1 22 23 package org.continuent.sequoia.console.text.commands.controller; 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.FileNotFoundException ; 28 import java.io.IOException ; 29 30 import org.continuent.sequoia.common.i18n.ConsoleTranslate; 31 import org.continuent.sequoia.console.text.ConsoleException; 32 import org.continuent.sequoia.console.text.commands.ConsoleCommand; 33 import org.continuent.sequoia.console.text.module.AbstractConsoleModule; 34 35 41 public class AddDriver extends ConsoleCommand 42 { 43 44 49 public AddDriver(AbstractConsoleModule module) 50 { 51 super(module); 52 } 53 54 57 public void parse(String commandText) throws IOException , ConsoleException 58 { 59 checkJmxConnectionToController(); 60 String filename = null; 61 if (commandText == null || commandText.trim().equals("")) { 64 try 65 { 66 filename = console.readLine(ConsoleTranslate 67 .get("controller.command.add.driver.input.filename")); } 69 catch (Exception che) 70 { 71 } 72 } 73 else 74 filename = commandText.trim(); 75 76 if (filename == null || filename.equals("")) throw new ConsoleException(ConsoleTranslate 78 .get("controller.command.add.driver.null.filename")); 80 try 81 { 82 jmxClient.getControllerProxy().addDriver(readDriver(filename)); 84 console.printInfo(ConsoleTranslate.get( 85 "controller.command.add.driver.file.sent", filename)); } 87 catch (FileNotFoundException fnf) 88 { 89 throw new ConsoleException(ConsoleTranslate.get( 90 "controller.command.add.driver.file.not.found", filename)); } 92 catch (Exception ioe) 93 { 94 throw new ConsoleException(ConsoleTranslate.get( 95 "controller.command.add.driver.sent.failed", ioe)); } 97 } 98 99 private byte[] readDriver(String filename) throws FileNotFoundException , 100 IOException 101 { 102 File file; 103 FileInputStream fileInput = null; 104 file = new File (filename); 105 fileInput = new FileInputStream (file); 106 107 long size = file.length(); 109 if (size > Integer.MAX_VALUE) 110 throw new IOException (ConsoleTranslate 111 .get("controller.command.add.driver.file.too.big")); byte[] bytes = new byte[(int) size]; 113 int nb = fileInput.read(bytes); 114 fileInput.close(); 115 if (nb != size) 116 throw new IOException (ConsoleTranslate 117 .get("controller.command.add.driver.file.not.read")); return bytes; 119 } 120 121 124 public String getCommandName() 125 { 126 return "upload driver"; } 128 129 132 public String getCommandDescription() 133 { 134 return ConsoleTranslate.get("controller.command.add.driver.description"); } 136 137 140 public String getCommandParameters() 141 { 142 return ConsoleTranslate.get("controller.command.add.driver.params"); } 144 145 } 146 | Popular Tags |