/** * Copies a resource to the location specified by the File parameter. */ public void createFileFromResource(final String resourceName, final File file) { File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } Exceptions.VoidBlock block = new Exceptions.VoidBlock() { @Override public void inner() throws Exception { InputStream is = getResourceAsStream(resourceName); try { FileOutputStream fos = new FileOutputStream(file); try { copy(is, fos); } finally { fos.close(); } } finally { is.close(); } } }; block.exec(); }
public void execNotThrowingExceptions(PrintStream err) { try { inner(); } catch (Exception e) { e.printStackTrace(err); } } }
public void testSwallowExceptionBlockExec() { ByteArrayOutputStream log = new ByteArrayOutputStream(); PrintStream fakeErr = new PrintStream(log); final Exception orig = new SQLException("foo"); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { @Override public void inner() throws Exception { throw orig; } }; block.execNotThrowingExceptions(fakeErr); assertTrue(log.toString().indexOf("foo") >= 0); } }
public Map parseHelp(String help) { String trimmed = trimToOptions(help); final Map map = new HashMap(); final BufferedReader reader = new BufferedReader(new StringReader( trimmed)); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { while (true) { String line = reader.readLine(); if (line == null) { break; } if (line.indexOf(' ') <= 0) { continue; } String key = line.substring(0, line.indexOf(' ')); String val = line.substring(key.length()).trim(); if (val.equals(NO_DEFAULT_VALUE)) { val = ""; } map.put(key, val); } } }; block.exec(); return map; }
/** * Copies a resource to the location specified by the File parameter. */ public void createFileFromResource(final String resourceName, final File file) { File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { InputStream is = getResourceAsStream(resourceName); try { FileOutputStream fos = new FileOutputStream(file); try { copy(is, fos); } finally { fos.close(); } } finally { is.close(); } } }; block.exec(); }
/** * Copies a resource to the location specified by the File parameter. */ public void createFileFromResource(final String resourceName, final File file) { File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { InputStream is = getResourceAsStream(resourceName); try { FileOutputStream fos = new FileOutputStream(file); try { copy(is, fos); } finally { fos.close(); } } finally { is.close(); } } }; block.exec(); }
public void testVoidBlock() { final Exception orig = new SQLException(); assertNull(orig.getMessage()); Exception caught = null; Exceptions.VoidBlock block = new Exceptions.VoidBlock() { @Override public void inner() throws Exception { throw orig; } }; try { block.exec(); } catch (WrappedException converted) { caught = converted; } assertNotNull(caught); assertEquals(orig, caught.getCause()); }
public void testVoidBlock() { final Exception orig = new SQLException(); assertNull(orig.getMessage()); Exception caught = null; Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; try { block.exec(); } catch (WrappedException converted) { caught = converted; } assertNotNull(caught); assertEquals(orig, caught.getCause()); }
/** * If the jar exists as a resource, the contents of the jar will be expanded * on the file system in the location specified by the File parameter. * * If any files already exist, they will <b>not </b> be over-written. */ public void expandResourceJar(final File outputDir, final String jarResourceName) { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { @Override public void inner() throws Exception { expandResourceJarInner(outputDir, jarResourceName); } }; block.exec(); }
void issueForceKill() { printWarning("attempting to \"force kill\" " + pid()); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() { new ProcessUtil(pid(), err, err).forceKill(); } }; block.execSwallowingException(err); waitForProcessToDie(); if (processRunning()) { String msg = (processRunning() ? "not " : "") + "killed."; printWarning(pid() + " " + msg); } else { printMessage("force kill " + pid() + " issued."); } }
/** * If the jar exists as a resource, the contents of the jar will be expanded * on the file system in the location specified by the File parameter. * * If any files already exist, they will <b>not </b> be over-written. */ public void expandResourceJar(final File outputDir, final String jarResourceName) { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { expandResourceJarInner(outputDir, jarResourceName); } }; block.exec(); }
public void testVoidBlock() { final Exception orig = new SQLException(); assertNull(orig.getMessage()); Exception caught = null; Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; try { block.exec(); } catch (WrappedException converted) { caught = converted; } assertNotNull(caught); assertEquals(orig, caught.getCause()); }
/** * If the jar exists as a resource, the contents of the jar will be expanded * on the file system in the location specified by the File parameter. * * If any files already exist, they will <b>not </b> be over-written. */ public void expandResourceJar(final File outputDir, final String jarResourceName) { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { expandResourceJarInner(outputDir, jarResourceName); } }; block.exec(); }
public void testSwallowExceptionBlockExec() { ByteArrayOutputStream log = new ByteArrayOutputStream(); PrintStream fakeErr = new PrintStream(log); final Exception orig = new SQLException("foo"); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; block.execSwallowingException(fakeErr); assertTrue(log.toString().indexOf("foo") >= 0); } }
private void issueNormalKill() { if (!pidFile().exists()) { printWarning("Not running? File not found: " + pidFile()); return; } Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() { new ProcessUtil(pid(), err, err).kill(); } }; block.execSwallowingException(err); waitForProcessToDie(); }
public void forceKill() { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { @Override public void inner() { kill(true); } }; block.execNotThrowingExceptions(err); }
public void testSwallowExceptionBlockExec() { ByteArrayOutputStream log = new ByteArrayOutputStream(); PrintStream fakeErr = new PrintStream(log); final Exception orig = new SQLException("foo"); Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { throw orig; } }; block.execNotThrowingExceptions(fakeErr); assertTrue(log.toString().indexOf("foo") >= 0); } }
public void execSwallowingException(PrintStream err) { try { inner(); } catch (Exception e) { e.printStackTrace(err); } } }
public void destroy() { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws ReflectionException { invoke(STOP_METHOD, null, null); } }; block.exec(); } }
public void killNoThrow() { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() { kill(); } }; block.execNotThrowingExceptions(err); } }