static String decode(byte[] b, int off, int len, String cs) { try { return new String(b, off, len, cs); } catch (UnsupportedEncodingException e) { throw new ConfigurationError(e); } }
public byte[] encode(String val) { try { return val.getBytes(charset); } catch (UnsupportedEncodingException e) { throw new ConfigurationError(e); } }
public static Object createInstance(String name) { try { return loadClass(name).newInstance(); } catch (ClassNotFoundException ex) { throw new ConfigurationError("Class not found: " + name, ex); } catch (InstantiationException ex) { throw new ConfigurationError("Could not instantiate: " + name, ex); } catch (IllegalAccessException ex) { throw new ConfigurationError("could not instantiate: " + name, ex); } }
public static Object loadResource(String name) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); InputStream is; if (cl == null || (is = cl.getResourceAsStream(name)) == null) { is = ResourceLocator.class.getClassLoader().getResourceAsStream( name); if (is == null) { throw new ConfigurationError("Missing Resource: " + name); } } try { ObjectInputStream ois = new ObjectInputStream(is); return ois.readObject(); } catch (Exception e) { throw new ConfigurationError("Failed to load Resource " + name, e); } finally { CloseUtils.safeClose(is); } }
protected ImageReaderWriterFactory(String key, String def) { String val = System.getProperty(key, def); URL url; try { url = new URL(val); } catch (MalformedURLException e) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null || (url = cl.getResource(val)) == null) { if ((url = ImageReaderWriterFactory.class.getClassLoader() .getResource(val)) == null) { throw new ConfigurationError("missing resource: " + val); } } } InputStream is = null; try { is = url.openStream(); config.load(is); } catch (IOException e) { throw new ConfigurationError( "failed to load imageio configuration from " + url, e); } finally { CloseUtils.safeClose(is); } }
public int tagForName(String name) { if (tagClassName == null) { throw new UnsupportedOperationException( "No tag class associated to dictionary"); } try { if (tagClass == null) { tagClass = ResourceLocator.loadClass(tagClassName); } return tagClass.getField(name).getInt(null); } catch (IllegalAccessException e) { throw new Error(e); } catch (NoSuchFieldException e) { throw new IllegalArgumentException("Unknown Tag Name: " + name); } catch (Exception e) { throw new ConfigurationError(e); } }
public ImageWriter getWriterForTransferSyntax(String tsuid) { String s = config.getProperty(tsuid); if (s == null) { throw new UnsupportedOperationException( "No Image Writer available for Transfer Syntax:" + tsuid); } int delim = s.indexOf(','); if (delim == -1) { throw new ConfigurationError("Missing ',' in " + tsuid + "=" + s); } final String formatName = s.substring(0, delim); final String className = s.substring(delim+1); for (Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName(formatName); it.hasNext();) { ImageWriter r = it.next(); if (className.equals(r.getClass().getName())) { return r; } } throw new ConfigurationError("No Image Writer of class " + className + " available for format:" + formatName); }
public ImageReader getReaderForTransferSyntax(String tsuid) { String s = config.getProperty(tsuid); if (s == null) { throw new UnsupportedOperationException( "No Image Reader available for Transfer Syntax:" + tsuid); } int delim = s.indexOf(','); if (delim == -1) { throw new ConfigurationError("Missing ',' in " + tsuid + "=" + s); } int delim2 = s.indexOf(',', delim+1); final String formatName = s.substring(0, delim); final String className = s.substring(delim+1, delim2 == -1 ? s.length() : delim2); for (Iterator it = ImageIO.getImageReadersByFormatName(formatName); it.hasNext();) { ImageReader r = (ImageReader) it.next(); if (className.equals(r.getClass().getName())) { log.debug("Found reader "+className +" for "+tsuid); return r; } log.debug("Skipping image reader "+r.getClass().getName()); } throw new ConfigurationError("No Image Reader of class " + className + " available for format:" + formatName); }
public static List<String> findResources(Class<?> c) { ArrayList<String> list = new ArrayList<String>(); try { for (Enumeration<URL> configs = enumResources(PREFIX + c.getName()); configs.hasMoreElements();) { URL u = configs.nextElement(); InputStream in = u.openStream(); try { BufferedReader r = new BufferedReader( new InputStreamReader(in, "utf-8")); String ln; while ((ln = r.readLine()) != null) { int end = ln.indexOf('#'); if (end >= 0) ln = ln.substring(0, end); ln = ln.trim(); if (ln.length() > 0) list.add(ln); } } finally { CloseUtils.safeClose(in); } } return list; } catch (IOException e) { throw new ConfigurationError("Failed to find Resources for " + c, e); } }
Integer.parseInt(planarConfig)); } catch (NumberFormatException e) { throw new ConfigurationError( "Illegal value for Planar Configuration: " + s);