private ScriptText readScriptText(String filePath, InputStreamReader reader) throws Exception { final char[] readBuffer = new char[4096]; StringBuilder scriptText = new StringBuilder(); try { int read = reader.read(readBuffer); while (read > 0) { scriptText.append(readBuffer, 0, read); read = reader.read(readBuffer); } reader.close(); return new ScriptText(filePath, scriptText.toString()); } catch (IOException e) { throw new Exception("Error reading from rule file: " + filePath, e); } }
ScriptText scriptText = new ScriptText(scriptName, scriptString); List<ScriptText> scriptTexts = new LinkedList<ScriptText>(); scriptTexts.add(scriptText); updatedScriptText = new ScriptText(installedScriptText.getFileName(), installedScriptText.getText()+scriptString); } else { updatedScriptText = new ScriptText(redirectedSubmissionsFile.getCanonicalPath(), scriptString);
for (String fileName : scriptFileNames) { String text = rulesByScript.get(fileName); scriptTexts.add(new ScriptText(fileName, text));
/** * unloads a script previously supplied as a text String * @param clazz the test class * @param testName the test name * @throws Exception if the script text cannot be unloaded */ public static void unloadScriptText(Class<?> clazz, String testName) throws Exception { String className = clazz.getName(); if (testName == null) { testName = ""; } String key = className + "+" + testName; String scriptText = fileTable.remove(key); if (scriptText == null) { throw new Exception("Rule script not found " + key); } Submit submit = new Submit(getHost(), getPort()); if (isBMUnitVerbose()) { System.out.println("BMUnit : unloading text script = " + key); } List<ScriptText> scripts = new ArrayList<ScriptText>(); ScriptText script = new ScriptText(key, scriptText); scripts.add(script); submit.deleteScripts(scripts); }
/** * loads a script supplied as a text String rather than via a file on disk * @param clazz the test class * @param testname the test name * @param scriptText the text of the rule or rules contained in the script * @throws Exception if the script text cannot be loaded */ public static void loadScriptText(Class<?> clazz, String testname, String scriptText) throws Exception { if (BMUnitConfigState.getCurrentConfigState() == null) { throw new Exception("BMUnit : load script file requested with no current configuration " + clazz.getName() + (testname != null ? " " + testname : "")); } String className = clazz.getName(); if (testname == null) { testname = ""; } String key = className + "+" + testname; fileTable.put(key, scriptText); Submit submit = new Submit(getHost(), getPort()); if (isBMUnitVerbose()) { System.out.println("BMUnit : loading text script = " + key); // System.out.println(scriptText); } List<ScriptText> scripts = new ArrayList<ScriptText>(); ScriptText script = new ScriptText(key, scriptText); scripts.add(script); submit.addScripts(scripts); }