public static EffectiveBytes valueOf(int n) { switch (n) { case 1: return ONE; case 2: return TWO; case 3: return THREE; case 4: return FOUR; default : throw E.unexpected("Invalid EffectiveByte value: %s. Expected: 1 - 4", n); } } }
public static BufferedImage read(URL url) { try { return ImageIO.read(url); } catch (Exception e) { throw unexpected(e); } }
@Override public void run(Scenario scenario) { try { Thread.sleep(time); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw E.unexpected(e); } }
private void initType(String desc) { if (desc.contains("Profile")) { type = Type.Profile; } else if (desc.contains("Mode")) { type = Type.Mode; } else if (desc.contains("Group")) { type = Type.Group; } else { throw E.unexpected("Unknown Env annotation: %s", desc); } }
Mac macOf(String key) { try { SecretKeySpec spec = new SecretKeySpec(key.getBytes(Charset.forName("UTF-8")), javaName); Mac mac = Mac.getInstance(javaName); mac.init(spec); return mac; } catch (Exception e) { throw E.unexpected(e); } }
public static Method overwrittenMethodOf(Method method) { Class host = method.getDeclaringClass(); Class base = host.getSuperclass(); try { return base.getMethod(method.getName(), method.getParameterTypes()); } catch (NoSuchMethodException e) { throw E.unexpected("Unable to find the overwritten method of " + method); } }
public T clone() { try { T clone = (T) super.clone(); clone.reset(); return clone; } catch (CloneNotSupportedException e) { throw E.unexpected(e); } } }
public CommandMethodMetaInfo addLead(String lead) { if (null == lead) { return this; } if (optionLeads.contains(lead)) { throw E.unexpected("Duplicate option lead %s found on %s.%s", lead, clsInfo.className(), methodName); } optionLeads.add(lead); return this; }
public static String render(File imageSource, boolean favicon) { try { URL url = imageSource.toURI().toURL(); boolean isIcon = imageSource.getName().endsWith(".ico"); return render(url, favicon, isIcon); } catch (MalformedURLException e) { // this is never gonna happen throw E.unexpected(e); } }
@Override public void visit(Object entity) throws $.Break { try { field.set(entity, tsGen.now()); } catch (IllegalAccessException e) { throw E.unexpected(e); } } }
public static Document read(File file) { DocumentBuilder b = builder.get(); try { return b.parse(file); } catch (Exception e) { throw E.unexpected(e); } finally { b.reset(); } }
public static List<InternetAddress> canonicalRecipients(List<InternetAddress> l, String... recipients) { if (null == l) l = new ArrayList<>(); if (recipients.length == 0) return l; String s = S.join(",", recipients).replaceAll(SEP, ","); try { InternetAddress[] aa = InternetAddress.parse(s); l.addAll(C.listOf(aa)); return l; } catch (AddressException e) { throw E.unexpected(e); } }
public static Document read(String content) { DocumentBuilder b = builder.get(); try { return b.parse(IO.inputStream(content)); } catch (Exception e) { throw E.unexpected(e); } finally { b.reset(); } }
private <T> T resolve(String val, StringValueResolver<T> resolver) { if (null == errorTemplate) { return resolver.resolve(val); } try { return resolver.resolve(val); } catch (Exception e) { throw E.unexpected(errorTemplate, val); } }
private void verifyHome() { if (!verifyDir(lib) || !verifyDir(plugin)) { throw E.unexpected("Cannot load Act: can't find lib or plugin dir"); } }
public static UploadFileStorageService create(App app) { File tmp = app.tmpDir(); if (!tmp.exists() && !tmp.mkdirs()) { throw E.unexpected("Cannot create tmp dir"); } Map<String, String> conf = C.newMap("storage.fs.home.dir", Files.file(app.tmpDir(), "uploads").getAbsolutePath(), "storage.keygen", KeyGenerator.Predefined.BY_DATE.name()); conf.put(IStorageService.CONF_ID, "__upload"); conf.put("storage.storeSuffix", "false"); return new UploadFileStorageService(conf, app.config().uploadInMemoryCacheThreshold()); }
public void load() { String content = getResourceAsString("requests.yml"); if (null != content) { try { doParse(content); } catch (RuntimeException e) { throw E.unexpected(e, "Error loading requests.yml"); } } addBuildInTemplates(); }
@Override protected Map<String, String> doGetMeta(String fullPath) { try { CloudBlockBlob blob = blobContainer.getBlockBlobReference(fullPath); blob.downloadAttributes(); Map<String, String> meta = C.newMap(blob.getMetadata()); meta.put(ISObject.ATTR_CONTENT_TYPE, blob.getProperties().getContentType()); return meta; } catch (Exception e) { throw E.unexpected(e); } }
private Object load(ParamTree tree, ActContext context) { ParamTreeNode node = tree.node(paramKey, context); if (null == node) { return null; } if (!node.isLeaf()) { throw E.unexpected("Expect leaf node, found: \n%s", node.debug()); } String value = node.value(); return (null == value) ? null : stringValueResolver.resolve(value); }
private Object load(ParamTree tree, ActContext context) { ParamTreeNode node = tree.node(paramKey, context); if (null == node) { return null; } if (!node.isLeaf()) { throw E.unexpected("Expect leaf node, found: \n%s", node.debug()); } String value = node.value(); return (null == value) ? null : stringValueResolver.resolve(value); }