Package org.jboss.fresh.io

Examples of org.jboss.fresh.io.BufferOutputStream


    return instream;
  }

  protected BufferOutputStream getStdOutStream() {
    if (outstream == null) {
      outstream = new BufferOutputStream(out);
    }

    return outstream;
  }
View Full Code Here


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

  protected void process(String exepath, String[] args) throws Exception {
    BufferObjectReader in = new BufferObjectReader(getStdIn());
    BufferOutputStream out = getStdOutStream();
    GZIPOutputStream gout = new GZIPOutputStream(out);
    ObjectOutputStream oout = new ObjectOutputStream(gout);
    Object obj;
    try {
      while( !in.isFinished() ) {
        obj = in.readObject();
        oout.writeObject(obj);
        oout.flush();
        gout.flush();
        out.flush();
      }
      in.close();
    } 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());
      }
    }
    oout.close();
    gout.close();
    out.close();
  }
View Full Code Here

    //Variables to be declared to the BSFManager (are available in scripts under aliases)
    Writer out = null;
    Reader in = null;
    BufferInputStream inStream = null;
    BufferOutputStream outStream = null;
    Context context = null;
    Properties props = null;

    boolean isFile = false;

    if (helpRequested()) {
      printHelp();
      return;
    }


    PrintWriter err = new PrintWriter(new BufferWriter(getStdOut()), true);

    // now lookup ScriptingServices
    ScriptingCentral sc = (ScriptingCentral) getShell().getContext().get("ScriptingServices");
    if (sc == null) {
      if (canThrowEx()) {
        throw new RuntimeException("ScriptingServices not bound in context.");
      } else {
        err.println("ScriptingServices not bound in context.");
        return;
      }
    }

        String file = null;
        String vfile = null;
    Reader reader = null;
    String enc = shell.getEnvProperty("ENCODING");

    String [] args = null;


        if(params.length >0) {
            int i = 0;
            String temp = params[i];

            if("-f".equals(temp) || "--file".equals(temp)) {
                if(i<params.length-1) {
                    file = params[++i];
                } else {
                    error("File name missing after parameter: " + temp);
                    return;
                }
            } else if("-v".equals(params[0]) || "--vfile".equals(params[0])) {
                if(i<params.length-1) {
                    vfile = params[++i];
                } else {
                    error("File name missing after parameter: " + temp);
                    return;
                }
            }
        }


        if(file != null || vfile != null) {
            args = new String[params.length-2];
            for(int i=2; i<params.length; i++) {
                args[i-2] = params[i];
            }


            fname = file != null ? file : vfile;

            String ext = IOUtils.getExt(fname);
            if (ext == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("Can't determine scripting language - file has no extension.");
                } else {
                    err.println("Can't determine scripting language - file has no extension.");
                    return;
                }
            }


            langName = sc.getLanguageForExtension(ext);
            if (langName == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("No scripting language registered for the specified extensions: " + ext);
                } else {
                    err.println("No scripting language registered for the specified extensions: " + ext);
                    return;
                }
            }

            InputStream ins = null;
            if(file != null) {
                ins = new FileInputStream(file);
            } else {
                VFS vfs = shell.getVFS();
                FileName pwd = new FileName(shell.getEnvProperty("PWD"));
                FileName path = new FileName(vfile);
                if (path.isRelative())
                    path = pwd.absolutize(path);

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

                ins = new VFSInputStream(new SecureVFS(vfs, shell.getUserCtx()), path.toString());
            }

            if (enc == null || enc.trim().length() == 0) {
                reader = new BufferedReader(new InputStreamReader(ins));
            } else {
                reader = new BufferedReader(new InputStreamReader(ins, enc));
            }

            isFile = true;

        } else {
            args = params;

            InputStream ins = new BufferInputStream(getStdIn());
            if (enc == null || enc.trim().length() == 0) {
                reader = new BufferedReader(new InputStreamReader(ins));
            } else {
                reader = new BufferedReader(new InputStreamReader(ins, enc));
            }

            langName = ((BufferedReader) reader).readLine();

            if (langName.length() > 2)
                langName = langName.substring(2).trim();

            String lngName = sc.getLanguageForName(langName);
            if (lngName == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("Scripting language is not supported: " + langName);
                } else {
                    err.println("Scripting language is not supported: " + langName);
                    return;
                }
            }

            langName = lngName;
        }


    BSFManager manager = sc.getManager(langName);

    inStream = getStdInStream();
    outStream = getStdOutStream();
    context = shell.getContext();
    props = shell.getEnvProperties();
    out = new PrintWriter(new BufferedWriter(new BufferWriter(getStdOut())), true);
    in = new BufferedReader(new BufferReader(getStdIn()));
    InBuffer stdin = getStdIn();
    OutBuffer stdout = getStdOut();

    manager.declareBean("args", args, args.getClass());
    manager.declareBean("shell", shell, shell.getClass());
    manager.declareBean("instream", inStream, inStream.getClass());
    manager.declareBean("outstream", outStream, outStream.getClass());
    manager.declareBean("context", context, context.getClass());
    manager.declareBean("props", props, props.getClass());
    manager.declareBean("out", out, out.getClass());
    manager.declareBean("cin", in, in.getClass());
    manager.declareBean("stdin", stdin, stdin.getClass());
View Full Code Here

       
    // if no name
    if (key == null) {
      // display all props
      // name=value
            PrintWriter2 pout = new PrintWriter2(new BufferedOutputStream(new BufferOutputStream(getStdOut())));
      Properties p = null;
      if(procid == null) {
        p = getProcess().getEnv().getEnvProperties();
      } else {
        SystemShellImpl ss = (SystemShellImpl) ((ShellImpl) getShell()).getSystemShell();
View Full Code Here

      pw.println();
      pw.flush();


      BufferedOutputStream bos = new BufferedOutputStream(new BufferOutputStream(getStdOut()));

      try {
        boolean freeOn = false;

        in = cli.getInputStream();
View Full Code Here


        // WRITE IMAGE

        if (outType.equals(IMG_TYPE)) {
          BufferOutputStream bos = new BufferOutputStream(getStdOut());
          ImageIO.write(newImage, "jpg", bos);
          bos.close();
/*
          OutputStream os = new BufferedOutputStream(new BufferOutputStream(getStdOut()));
          JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(os);
          jpegEncoder.encode(newImage);
          os.close();
View Full Code Here

    BufferedImage newImage = new BufferedImage(w, h, image.getType());
    newImage.setData(image.getData(new Rectangle(x, y, w, h)).createTranslatedChild(0, 0));

    // write new image to stream
    if (outType.equals(IMG_TYPE)) {
      BufferOutputStream bos = new BufferOutputStream(getStdOut());
      ImageIO.write(newImage, "jpg", bos);
      bos.close();
    } else { // OBJ_TYPE
      oout.writeObject(newImage);
      oout.close();
    }
View Full Code Here

      Process proc = Runtime.getRuntime().exec(params);

      BufferInputStream sin = new BufferInputStream(getStdIn());
      sin.setTimeout(1000);
      OutputStream nout = new BufferedOutputStream(proc.getOutputStream());
      final OutputStream sout = new BufferOutputStream(getStdOut());
      final InputStream nis = new BufferedInputStream(proc.getInputStream(), 80);

      // now copy from in to out and copy from out to in. This is not very nice
      // we need two threads
      Thread treader = new Thread() {
View Full Code Here

public class Bzip2Exe extends AbstractExecutable {
  public static final String VERSION = "$Header$";

  protected void process(String exepath, String[] args) throws Exception {
    BufferObjectReader in = new BufferObjectReader(getStdIn());
    BufferOutputStream out = getStdOutStream();
    CBZip2OutputStream bout = new CBZip2OutputStream(out);
    ObjectOutputStream oout = new ObjectOutputStream(bout);
    Object obj;
    try {
      while( !in.isFinished() ) {
        obj = in.readObject();
        oout.writeObject(obj);
        oout.flush();
        bout.flush();
        out.flush();
      }
      in.close();
    } 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());
      }
    }
    oout.close();
    bout.close();
    out.close();
  }
View Full Code Here

TOP

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

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.