/** * 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(); }
/** * 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 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; }
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(); }
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(); }
/** * 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 destroy() { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws ReflectionException { invoke(STOP_METHOD, null, null); } }; block.exec(); } }
public void destroy() { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws ReflectionException { invoke(STOP_METHOD, null, null); } }; block.exec(); } }
public void create() { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { String autoStart = "" + getAttribute(AUTOSTART_ATTR); autoStart = autoStart.toLowerCase(); if (autoStart.equals(Boolean.TRUE.toString())) { invoke(START_METHOD, null, null); } } }; block.exec(); }
public void create() { Exceptions.VoidBlock block = new Exceptions.VoidBlock() { public void inner() throws Exception { String autoStart = "" + getAttribute(AUTOSTART_ATTR); autoStart = autoStart.toLowerCase(); if (autoStart.equals(Boolean.TRUE.toString())) { invoke(START_METHOD, null, null); } } }; block.exec(); }
private void invokeStart() { Exceptions.VoidBlock startMethod = new Exceptions.VoidBlock() { public void inner() throws Exception { invoke(START_METHOD, null, null); } }; startMethod.exec(); } }