コード例 #1
0
ファイル: DTFStream.java プロジェクト: rlgomes/dtf
  public DTFInputStream getValueAsStream(String args) throws ParseException {
    String[] parts = args.split(",");

    if (args.length() < 1)
      throw new ParseException("Expecting more args for dtf.stream, got [" + args + "]");

    String name = parts[0];

    String arg1 = null;
    String[] arguments = new String[parts.length - 2];

    if (arguments.length > 0) {
      for (int i = 2; i < parts.length; i++) {
        arguments[i - 2] = parts[i];
      }
    }

    if (args.length() >= 2) arg1 = parts[1];

    long size = 0;
    if (arg1 != null) {
      try {
        size = new Long(arg1);
      } catch (NumberFormatException e) {
        throw new ParseException("Size should be a long not [" + arg1 + "]");
      }
    }
    Class<DTFInputStream> streamclass = _streams.get(name);

    if (streamclass == null) throw new ParseException("Unsupported stream [" + name + "]");

    try {
      Constructor<DTFInputStream> c =
          streamclass.getConstructor(new Class[] {long.class, String[].class});
      DTFInputStream stream = c.newInstance(new Object[] {size, arguments});
      DTFInputStream wrapper = new DTFInputStream(size, arguments);
      wrapper.setInputStream(stream);
      return wrapper;
    } catch (NoSuchMethodException e) {
      throw new ParseException("Error instantiating DTFInputStream.", e);
    } catch (IllegalArgumentException e) {
      throw new ParseException("Error instantiating DTFInputStream.", e);
    } catch (InstantiationException e) {
      throw new ParseException("Error instantiating DTFInputStream.", e);
    } catch (IllegalAccessException e) {
      throw new ParseException("Error instantiating DTFInputStream.", e);
    } catch (InvocationTargetException e) {
      throw new ParseException("Error instantiating DTFInputStream.", e);
    }
  }
コード例 #2
0
ファイル: DTFStream.java プロジェクト: rlgomes/dtf
 public static DTFInputStream getStringAsStream(String data) throws ParseException {
   DTFInputStream wrapper = new DTFInputStream(data.length(), new String[0]);
   wrapper.setInputStream(new StringInputStream(data));
   return wrapper;
 }