private boolean isParentLoaded(String className) { try { return null != parentFindLoadedClass.invoke(parent, className); } catch (Exception e) { throw Exceptions.uncheck(e); } }
protected String[] readLines(String content) { BufferedReader reader = new BufferedReader(new StringReader(content)); List<String> lines = new ArrayList<>(); try { String line; while ((line = reader.readLine()) != null) { lines.add(line); } } catch (IOException e) { throw Exceptions.uncheck(e); } return lines.toArray(new String[lines.size()]); } }
public static void throwUnchecked(CatchRunnable runnable) { try{ runnable.run(); }catch (Throwable e) { throw Exceptions.uncheck(e); } }
public static <T> T throwUncheckedWithResult(CatchSupplier<T> supplier) { try{ return supplier.run(); }catch (Throwable e) { throw Exceptions.uncheck(e); } }
private AppClassLoader(ClassLoader parent) { this.parent = parent; this.testing = AppContextInitializer.isTesting(); try { parentLoaderDefineClass = ClassLoader.class.getDeclaredMethod("defineClass", new Class[] {String.class, byte[].class, int.class,int.class}); parentLoaderDefineClass.setAccessible(true); parentFindLoadedClass = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class); parentFindLoadedClass.setAccessible(true); } catch (Exception e) { throw Exceptions.uncheck(e); } }
public void validate(DomDocument doc) throws XmlValidationException,NestedIOException { Validator validator = schema.newValidator(); try { Source source = null; if(null != doc.domDocument()){ source = new DOMSource(doc.domDocument()); }else{ source = new StreamSource(new StringReader(doc.toXml())); } validator.validate(source); } catch (SAXException e) { throw new XmlValidationException(Strings.format("Error validating xml : {0} \n {1}",e.getMessage(),doc.location()),e); } catch (IOException e) { throw Exceptions.uncheck(e); } } }
throw Exceptions.uncheck(e); }else{ log.error("Error invoking observer.checkAndNotify",e);
throw Exceptions.uncheck(e);
throw Exceptions.uncheck(e);
processor.postCreateProcessors(getAppContext(), this); } catch (Throwable throwable) { throw Exceptions.uncheck(throwable);
throw Exceptions.uncheck(e);
public static void read(Reader reader,CsvProcessor processor) throws NestedIOException { CSVParser parser = null; try{ parser = new CSVParser(reader, DEFAULT_FORMAT); String[] row; int rownum = 0; while((row = parser.nextRecord1()) != null){ rownum++; processor.process(rownum,row); } }catch(IOException e){ throw Exceptions.wrap(e); }catch(Exception e){ throw Exceptions.uncheck(e); }finally{ IO.close(reader); IO.close(parser); } }
@Init private void init() { try { if(null == appDirectory) { log.info("App directory not found, will not start it"); return; } log.info("App directory : {}", appDirectory.getURLString()); nodeModulesDirectory = appDirectory.createRelative("./node_modules/"); List<Resource> jarModules = new ArrayList<>(); resolveJarDirectory("classpath*:META-INF/app/modules/", jarModules); resolveJarDirectory("classpath*:META-INF/app/node_modules/", jarModules); resolveJarDirectory("classpath*:META-INF/jmms/modules/", jarModules); resolveJarDirectory("classpath*:META-INF/jmms/node_modules/", jarModules); resolveJarDirectory("classpath*:META-INF/jmms/core/modules/", jarModules); resolveJarDirectory("classpath*:META-INF/jmms/core/node_modules/", jarModules); this.jarModulesDirectories = jarModules.toArray(new Resource[0]); }catch (Exception e) { throw Exceptions.uncheck(e); } }
public void run() { try { for(;;) { writer.println("Waiting command..."); String line=reader.readLine(); if(null == line) { break; } if(Strings.isBlank(line)) { output(400, "The input data can't be empty!"); return; } if("exit".equals(line)) { log.info("Received exit request, exit now"); break; } log.info("Received : " + line); execute(line); } }catch (Exception e) { log.error(e); throw Exceptions.uncheck(e); } }
public Resource getResource(String path) { try { Resource r = hasAppDirectory() ? getAppDirectory().createRelative(path) : null; if(null == r || !r.exists()) { ResourceSet rs = Resources.scan("classpath*:META-INF/app/" + Strings.removeStart(path, "./")); if(!rs.isEmpty()) { //todo: handle multi resources scanned. r = rs.get(0); } } return r; }catch (IOException e) { throw Exceptions.uncheck(e); } }
public void start(Global.LeapContext leap) { AppContext context = leap.context(); BeanFactory factory = leap.factory(); if(null == context) { log.error("Leap context not found, can not start jmms, is spring boot running at web environment?"); return; } try { AppContext.setCurrent(context); Engine engine = factory.getBean(Engine.class); if(engine.isStarted()) { log.info("Engine already started, skip"); return; } try { resolveSpringMappings(factory); } catch (RuntimeException e) { log.error("Resolve spring mapping info error", e); } engine.addInternalListener(this); engine.start(); started = true; }catch (Throwable e) { throw Exceptions.uncheck(e); }finally { AppContext.removeCurrent(); } }