Package org.jboss.fresh.io

Examples of org.jboss.fresh.io.BufferObjectWriter


    h = (History) context.get("History");

    if(h == null) return;

    BufferObjectWriter oout = null;
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

    String val = null;

    try {
      Iterator it = h.list().iterator();
      while(it.hasNext()) {
        HistoryItem hi = (HistoryItem) it.next();

        if(objs) {
          if(oout == null)
            oout = new BufferObjectWriter(getStdOut());
          oout.writeObject(pout);
        } else {
          StringBuffer sb = new StringBuffer();
          if(time) {
            sb.append(sdf.format(new Date(hi.getTime())));
            sb.append(" ");
View Full Code Here


      log.debug("done");
      return;
    }

    BufferObjectReader oin = new BufferObjectReader(getStdIn());
    BufferObjectWriter oout = new BufferObjectWriter(getStdOut());

    // if no params, just let through everything
    // if type param, do some filtering.
    if (params.length == 0) {
      log.info("No parameters specified. Just piping through.");
      while (!oin.isFinished()) {
        oout.writeObject(oin.readObject());
      }
      oout.close();
      log.debug("done");
      return;
    }


    HashMap typemap = new HashMap();
    typemap.put("type", "string");

    // filterparser mora pripraviti pogoje - Filter objekte. Filter objekt zna za vrednost dolo�enega tipa pogledati ali izpolnjuje set pogojev.
    // Seveda je normalno pogoj vezan na neko polje v neki podatkovni strukturi. Treba je samo ta field vedno posredovati temu filtru.
    // Treba je torej vedeti kateri field je vezan na kateri filter.
    // smiselno je enumerirati list filtrov. Vsak filter vpra�ati na kateri field se nana�a in ta field posredovati v preverjanje.

    FilterParser p = null;
    Filter[] filters = null;

    try {
      p = new MyFilterParser(typemap, params);
      filters = p.getFilters();
    } catch (Exception e) {
      if (canThrowEx()) {
        throw e;
      } else {
        PrintWriter err = new PrintWriter(new BufferWriter(getStdOut()));
        err.println("" + e);
      }
    }

    // now we do ...
    while (!oin.isFinished()) {
      FileInfo finf = (FileInfo) oin.readObject();

      boolean ok = false;

      for (int i = 0; i < filters.length; i++) {
        String fld = filters[i].getFieldName();
        log.debug("Field name: " + fld);
        if (fld.equals("type")) {
          ok = filters[i].check(cnv(finf.getFileType()));
          log.debug(finf.getFileName() + "  ok? : " + ok);
          if (!ok) break;
        }
      }

      if (ok) oout.writeObject(finf);
    }

    oout.close();

    log.debug("done");
  }
View Full Code Here

      }

    }

    BufferObjectReader in = new BufferObjectReader(getStdIn());
    BufferObjectWriter out = new BufferObjectWriter(getStdOut());

    Object obj;
    while (!in.isFinished()) {
      obj = in.readObject();
      // process input stream
      if (obj == null) {
        if (forceString) {
          log.debug("Object is null. Outputing empty String.");
          out.writeObject("");
        } else {
          log.debug("Object is null. Outputing empty Document.");
          out.writeObject(XMLHelper.getDocument());
        }
      } else if (obj instanceof Document) {
        if (forceDOM) {
          log.debug("Object is Document. Forced output to DOM, so just returning it.");
          if (log_xml.isDebugEnabled()) {
            log_xml.debug("Document -> Document: " + XMLHelper.getXML((Document) obj));
          }
          out.writeObject(obj);
        } else {
          try {
            String s = XMLHelper.getXML((Document) obj);
            log.debug("Object is Document. Returning string.");
            log_xml.debug("Document -> String: " + s);
            out.writeObject(s);
          } catch (IOException e) {
            log.error("Could not parse input Document into string! Weird.", e);
            if (err == null) {
              throw new RuntimeException("Could not parse input Document into string! Weird.", e);
            } else {
              err.write("Could not parse input Document into string! Weird.");
              e.printStackTrace(err);
            }
          }
        }
      } else if (obj instanceof Element) {
        if (forceDOM) {
          log.debug("Object is Element. Forced output to DOM, so just returning it.");
          if (log_xml.isDebugEnabled()) {
            log_xml.debug("Element -> Element: " + XMLHelper.getXML((Element) obj));
          }
          out.writeObject(obj);
        } else {
          try {
            String s = XMLHelper.getXML((Element) obj);
            log.debug("Object is Element. Returning string.");
            log_xml.debug("Element -> String: " + s);
            out.writeObject(s);
          } catch (IOException e) {
            log.error("Could not parse input Element into string! Weird.", e);
            if (err == null) {
              throw new RuntimeException("Could not parse input Element into string! Weird.", e);
            } else {
              err.write("Could not parse input Element into string! Weird.");
              e.printStackTrace(err);
            }
          }
        }
      } else if (obj instanceof DocumentFragment) {
        if (forceDOM) {
          log.debug("Object is DocumentFragment. Forced output to DOM, so just returning it.");
          if (log_xml.isDebugEnabled()) {
            log_xml.debug("DocumentFragment -> DocumentFragment: " + XMLHelper.getXML((DocumentFragment) obj));
          }
          out.writeObject(obj);
        } else {
          try {
            String s = XMLHelper.getXML((DocumentFragment) obj);
            log.debug("Object is DocumentFragment. Returning string.");
            log_xml.debug("DocumentFragment -> String: " + s);
            out.writeObject(s);
          } catch (IOException e) {
            log.error("Could not parse input DocumentFragment into string! Weird.", e);
            if (err == null) {
              throw new RuntimeException("Could not parse input DocumentFragment into string! Weird.", e);
            } else {
              err.write("Could not parse input DocumentFragment into string! Weird.");
              e.printStackTrace(err);
            }
          }
        }
      } else {
        if (log.isDebugEnabled() && (!(obj instanceof String))) {
          log.debug("We got this:" + (obj == null ? "<null>" : obj.getClass().getName()), new Throwable());
        }
        String s;

        if (obj instanceof char[]) {
          s = new String((char[]) obj);
        } else if (obj instanceof byte[]) {
          s = new String((byte[]) obj, "UTF8");
        } else {
          s = obj.toString();
        }
        if (forceString) {
          log.debug("Object is String. Forced output to String, so just returning it.");
          log_xml.debug("String -> String: " + s);
          out.writeObject(s);
        } else {
          try {
            log.debug("Object is String. Parsing it to DOM Document.");
            log_xml.debug("String -> Document: " + s);
            out.writeObject(XMLHelper.getDocument(s));
          } catch (Exception e) {
            log.error("Could not parse input string into DOM! Probably not a valid XML.", e);
            if (err == null) {
              throw new RuntimeException("Could not parse input string into DOM! Probably not a valid XML.", e);
            } else {
View Full Code Here

    }

    Object ret = new Object();

    BufferObjectReader in = new BufferObjectReader(getStdIn());
    BufferObjectWriter out = new BufferObjectWriter(getStdOut());

    Object[] input = (Object[]) in.readObject();

    System.out.println("Input Object[] is: " + String.valueOf(input));

    Object[] cons_params = (Object[]) input[0];
    System.out.println("Constructor params is: " + String.valueOf(cons_params));

    Object[] met_params = (Object[]) input[1];
    System.out.println("Method params is: " + String.valueOf(met_params));

    Class[] types = new Class[cons_params.length];

    for (int i = 0; i < cons_params.length; i++) {
      types[i] = cons_params[i].getClass();
    }

    System.out.println("Types is: " + String.valueOf(types));

    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class c = cl.loadClass(args[0]);
    Constructor con = c.getConstructor(types);
    Object thing = con.newInstance(cons_params);
    Method[] methods = c.getMethods();
    for (int i = 0; i < methods.length; i++) {
      Method m = methods[i];
      System.out.println("Method name: " + m.getName());
      if (m.getName().equals(args[1])) {
        ret = m.invoke(thing, met_params);
        System.out.println("Return Object is: " + String.valueOf(ret));
        break;
      }
    }

    out.writeObject(ret);
  }
View Full Code Here

    }

//    System.out.println("##[CatExe] : getStdOut():" + getStdOut());
//    System.out.println("##[CatExe] : getStdIn():" + getStdIn());

    BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
    BufferObjectReader oin = new BufferObjectReader(getStdIn());

    VFS vfs = shell.getVFS();

    FileName pwd = new FileName(shell.getEnvProperty("PWD"));

    List paths = new LinkedList();

    for (int i = 0; i < params.length; i++) {
      String param = params[i];

      FileName path = new FileName(param);
      if (path.isRelative())
        path = pwd.absolutize(path);

      path = vfs.resolve(shell.getUserCtx(), path, false);
      paths.add(path);
    }


//    List result = new LinkedList();

//    if no paths given, read from stdin
    if (!paths.isEmpty()) {
      Iterator it = paths.iterator();
      while (it.hasNext()) {
        FileName path = (FileName) it.next();

        FileOpInfo op = new FileOpInfo();
        op.filename = path;
//        op.offset = 0;
        FileReadInfo read = null;

        do {
          read = vfs.read(shell.getUserCtx(), op);

          // if file has no content(is asset, etc.) null is returned by vfs.read()
          if (read == null)
            break;

          op.tag = read.tag;
          op.offset += read.buf.length;
          oout.writeObject(read.buf);
        } while (read.more);
      }

    } else {
      while (!oin.isFinished()) {
        Object obj = oin.readObject();
        oout.writeObject(obj);
//        System.out.println("##[CatExe] writing to out: " + obj);
      }

    }

    oout.close();

    log.debug("done");

  }
View Full Code Here

          String origin = ec.produceOrigin(compName);

          // register it with the pattern
          ec.registerEventListener(origin, lis, patterns);
         
          BufferObjectWriter boo = new BufferObjectWriter(getStdOut());
          boo.writeObject(origin);
          boo.flush();

        }
        break;

      case LIST:
View Full Code Here

      out.close();
      log.debug("done.");
      return;
    }

    BufferObjectWriter bout = new BufferObjectWriter(getStdOut());

    for (int i = 0; i < params.length; i++) {
      bout.writeObject(params[i]);
    }

    bout.close();
    log.debug("done");
  }
View Full Code Here

            out.close();
            log.debug("done");
            return;
        }

        BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
        VFS vfs = shell.getVFS();

        FileName pwd = new FileName(shell.getEnvProperty("PWD"));

        String out = OUTPUT_STRING;
        boolean output = false;        // was out param already processed
        boolean longOut = false;
        boolean rslvLinks = true;
        // boolean help = false;

        List paths = new LinkedList();

        for (int i = 0; i < params.length; i++) {

            String param = params[i];

            if (!longOut && param.equals(OPTION_LONG))
                longOut = true;

            else if (!output && param.startsWith(OUTPUT)) {
                out = param.substring(OUTPUT.length());
                output = true;

            }
/*       else if (param.equals(HELP)) {
        help = true;
        oout.writeObject("Usage: ls [--help] [-ex] [-out=OUTPUT] [-l] [--help]\n");
        oout.writeObject("       OUTPUT = string | filename | fileinfo; String is default.\n");
        oout.writeObject("       -l = long output; Makes difference only with -out=string.\n");
        oout.writeObject("       --help = Prints this.\n");
        oout.close();
        System.out.println("[LsExe] : done.");
        return;

      }
*/
            else {
                FileName path = new FileName(param);
                if (path.isRelative())
                    path = pwd.absolutize(path);

//        path = vfs.resolve(shell.getUserCtx(), path, true);
                paths.add(path);
            }
        }

        // if no paths given, list working dir
        if (paths.isEmpty())
            paths.add(pwd);


        // now we have all paths resolved and absolute in FileName form in the 'paths' list
        //log.debug("Paths: " + paths);


        List expPaths = new LinkedList();
        Iterator it = paths.iterator();
        while (it.hasNext()) {
            FileName filename = (FileName) it.next();
            List children = vfs.list(shell.getUserCtx(), filename, !rslvLinks);
            //log.debug("Expanding children: " + children);
            expPaths.addAll(children);
        }
        paths = expPaths;

        //log.debug("Paths after expanding: " + paths);

        //log.debug("long output = " +longOut);
        //log.debug("output = " +out);
        //log.debug("pwd = " +pwd);
        //log.debug("paths = ");
        //StringUtils.printCollection(paths);

        List result = null;
        if (out.equals(OUTPUT_STRING)) {
            result = new LinkedList();
            it = paths.iterator();

            while (it.hasNext()) {
                FileInfo info = (FileInfo) it.next();

                if (longOut) {
                    List fields, lengths;
                    fields = new LinkedList();
                    lengths = new LinkedList();

                    // field pathname
                    fields.add(info.getFileName().toString());
                    lengths.add(pathLen);

                    // last modified
                    fields.add(info.isDirectory() ? "DIR" : info.isLink() ? "LINK" : "FILE");
                    lengths.add(typeLen);

                    // modified
                    fields.add(info.getLastModified().toString());
                    lengths.add(modifiedLen);


                    if (info.isLink()) {
                        // link
                        fields.add(info.getTarget().toString());
                        lengths.add(new Integer(0));

                    } else {
                        // length
                        fields.add(new Long(info.getLength()).toString());
                        lengths.add(new Integer(0));
                    }

//          System.out.println("Adding to results (1): " + StringUtils.row(fields, lengths)+"\n");
                    result.add(StringUtils.row(fields, lengths) + "\r\n");

                } else {
//          System.out.println("Adding to results (2) info: " + info);
//          System.out.println("Adding to results (2) info.FileName: " + info.getFileName());
//          System.out.println("Adding to results (2): " + info.getFileName().toString() + "\n");
                    result.add(info.getFileName().toString() + "\r\n");
                }
            }

        } else if (out.equals(OUTPUT_FILEINFO)) {
//      System.out.println("Setting paths as result: " + paths);
            result = paths;

        } else if (out.equals(OUTPUT_FILENAME)) {
//      System.out.println("Iterating paths and replacing infos with names: " + paths);
            result = new LinkedList();
            it = paths.iterator();

            while (it.hasNext()) {
                FileInfo info = (FileInfo) it.next();
                result.add(info.getFileName());
            }
        }

        it = result.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
//      System.out.println("Writing to out: ");
//      System.out.println(obj);
            oout.writeObject(obj);

        }


        finish:
        oout.close();

        log.debug("done");
  }
View Full Code Here

*/
public class GunzipExe extends AbstractExecutable {
  public static final String VERSION = "$Header: /store/cvsroot2/java/cp2/coderoot/cp2/cp2-systemshell/src/com/parsek/shell/commands/GunzipExe.java,v 1.3 2004/07/22 13:38:56 boky Exp $";

  protected void process(String exepath, String[] args) throws Exception {
    BufferObjectWriter out = new BufferObjectWriter(getStdOut());
    BufferInputStream in = getStdInStream();
    GZIPInputStream gin = new GZIPInputStream(in);
    ObjectInputStream oin = new ObjectInputStream(gin);
    Object obj;
    try {
      boolean eof = false;
      while( !eof ) {
        try {
          obj = oin.readObject();
          out.writeObject(obj);
        } catch (java.io.OptionalDataException ode) {
          if(ode.eof) {
            eof = true;
            oin.close();
            gin.close();
            in.close();
          } else {
            throw ode;
          }
        }
      }
    } catch (Exception e) {
      if(canThrowEx()) {
        throw e;
      } else {
        org.jboss.fresh.io.BufferWriter bw = new BufferWriter(getStdOut());
        PrintWriter tOut = new PrintWriter(bw);
        tOut.write(e.toString());
      }
    }
    out.close();
  }
View Full Code Here

      out.close();
      log.debug("done");
      return;
    }

    BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
    VFS vfs = shell.getVFS();

    FileName pwd = new FileName(shell.getEnvProperty("PWD"));
    String out = OUTPUT_STRING;
    FileName target = null;
    Collection result = new HashSet();


    if (params.length <= 2) {
      for (int i = 0; i < params.length; i++) {
        String param = params[i];

        if (param.startsWith(OUTPUT))
          out = param.substring(OUTPUT.length());

        else {
          FileName path = new FileName(param);
          if (path.isRelative())
            path = pwd.absolutize(path);

          target = path;
        }
      }
    }

    if ((params.length >= 3) || (target == null)) {
      if (canThrowEx()) {
        throw new RuntimeException("Usage: lslns [-out=string|filename|fileinfo] TARGET");
      } else {
        PrintWriter pw = new PrintWriter(new BufferWriter(getStdOut()));
        pw.println("Usage: lslns [-out=string|filename|fileinfo] TARGET");
      }
    } else {
      Collection links = vfs.getLinks(shell.getUserCtx(), target, true);
      Iterator it = links.iterator();

      if (out.equals(OUTPUT_STRING)) {
        result = new LinkedList();

        while (it.hasNext()) {
          FileInfo info = (FileInfo) it.next();
          result.add(info.getFileName().toString() + "\n");
        }

      } else if (out.equals(OUTPUT_FILEINFO))
        result = links;

      else if (out.equals(OUTPUT_FILENAME)) {
        while (it.hasNext()) {
          FileInfo info = (FileInfo) it.next();
          result.add(info.getFileName());
        }
      }

      it = result.iterator();
      while (it.hasNext()) {
        Object obj = it.next();
        oout.writeObject(obj);
        System.out.println(obj);
      }
    }

    finish:
    oout.close();

    log.debug("done");
  }
View Full Code Here

TOP

Related Classes of org.jboss.fresh.io.BufferObjectWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.