Package org.jboss.fresh.io

Examples of org.jboss.fresh.io.BufferInputStream


  private Thread callingThread;

  protected BufferInputStream getStdInStream() {
    if (instream == null) {
      instream = new BufferInputStream(in);
    }

    return instream;
  }
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;
          }
        }
      }
View Full Code Here

    String langName = null, fname = "unknown";

    //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));
            }
View Full Code Here

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

  protected void process(String exepath, String[] args) throws Exception {
    BufferObjectWriter out = new BufferObjectWriter(getStdOut());
    BufferInputStream in = getStdInStream();
    CBZip2InputStream bin = new CBZip2InputStream(in);
    ObjectInputStream oin = new ObjectInputStream(bin);
    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();
            bin.close();
            in.close();
          } else {
            throw ode;
          }
        }
      }
View Full Code Here

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

    // read image
    BufferedImage image = ImageIO.read(new BufferInputStream(getStdIn()));

    if (image == null) {
      throwException("No object recieved from the standard input.");
      return;
    }
View Full Code Here

    try {

      String param;


      InputStream ins = new BufferInputStream(getStdIn());

      BufferedImage image = null;


      boolean useCache = false;

      // Determine the scale.
      double scale;
      double scaleX;
      double scaleY;

//log.debug("width: " + width);
//log.debug("height: " + height);
//log.debug("maxWidth: " + maxWidth);
//log.debug("maxHeight: " + maxHeight);

//      if ((width == -1) && (height == -1)) {
//        width = maxWidth;
//        height = maxHeight;
//      }


      // READ IMAGE
      if (inType.equals(IMG_TYPE)) {
        image = ImageIO.read(ins);
        if (image == null) {
          throwException("No image retrieved from the pipeline!");
          return;
        }
      } else { //OBJ_TYPE
        BufferObjectReader oin = new BufferObjectReader(getStdIn());

        if (oin.hasNext()) {
          image = (BufferedImage) oin.next();
        }
        oin.close();

        if (image == null) {
          throwException("No image object retrieved from the pipeline!");
          return;
        }

      }


      if (!useCache) {

        int imgW = image.getWidth(null);
        int imgH = image.getHeight(null);
//log.debug("image width: " + imgW);
//log.debug("image height: " + imgH);

        float iRatio = imgW / (float) imgH;

        // if request for fullsize image truncate width and height to maximums
        if ((width == -1) && (height == -1)) {
          if (maxWidth != -1 && imgW > maxWidth) width = maxWidth;
          if (maxHeight != -1 && imgH > maxHeight) height = maxHeight;
        }


//log.debug("width: " + width);
//log.debug("height: " + height);
        // if max requested height is known calculate aspect ratio width.
        // If it is greater than the width specified set width with it.
        if (height != -1) {
          int altwidth = (int) (height * iRatio);
//log.debug("altwidth: " + altwidth);
          //if(altwidth>width && width!=-1) width=altwidth;
          if (altwidth > width) width = altwidth;
        }

        // if max requested width is known calculate aspect ratio height.
        // If it is greater than the height set the height width it.
        if (width != -1) {
          int altheight = (int) (width / iRatio);
//log.debug("altheight: " + altheight);
          //if(altheight>height && height!=-1) height=altheight;
          if (altheight > height) height = altheight;
        }
//log.debug("After ratio check: ");
//log.debug("width: " + width);
//log.debug("height: " + height);


        if ((width > maxWidth) && (maxWidth != -1)) {
          width = maxWidth;
//log.debug("Truncated width to maxWidth: " + width);
          height = (int) (width / iRatio);
//log.debug("Adapted height to : " + height);
        }

        if (width > imgW) {
          width = imgW;
//log.debug("Truncated width to img Width: " + width);
          height = (int) (width / iRatio);
//log.debug("Adapted height to : " + height);
        }

        if (((height == -1) || (height > maxHeight)) && (maxHeight != -1)) {
          height = maxHeight;
//log.debug("Truncated height to maxHeight: " + height);
          width = (int) (height * iRatio);
//log.debug("Adapted width to : " + width);
        }

        if (height > imgH) {
          height = imgH;
//log.debug("Truncated height to img Height: " + height);
          width = (int) (height * iRatio);
//log.debug("Adapted width to : " + width);
        }


//log.debug("width: " + width);
//log.debug("height: " + height);



        if ((imgW > imgH) || (height == -1)) {
          scale = (double) width / (double) imgW;
        } else {
          scale = (double) height / (double) imgH;
        }

        int scaledW = (int) (scale * imgW);
        int scaledH = (int) (scale * imgH);

        // Shit. No cache. Do some resizing.
        /*
         *  response.setHeader("Cache-Control", "post-check=900,pre-check=3600");
         *  response.addHeader("Expires", dt(timeout) );
         *  response.addHeader("Last-Modified", dt(0) );
         *  response.setHeader("Date", dt(0) );
         */
        // fetch the image

        // Create an image buffer in which to paint on.
        BufferedImage newImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
        // Set the scale.
        AffineTransform tx = new AffineTransform();

        // If the image is smaller than the desired image size,
        // don't bother scaling.
        if (scale < 1.0d) {
          tx.scale(scale, scale);
        }

        // Paint image.
        Graphics2D g2d = newImage.createGraphics();
        //RenderingHints rh = new RenderingHints(java.awt.RenderingHints.KEY_ANTIALIASING,java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
        RenderingHints rh = new RenderingHints(java.awt.RenderingHints.KEY_INTERPOLATION, java.awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        //rh.add(java.awt.RenderingHints.KEY_ANTIALIASING,java.awt.RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHints(rh);

        g2d.drawImage(image, tx, null);
        g2d.dispose();


        // 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();
*/
        } else { // OBJ_TYPE
          BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
          oout.writeObject(newImage);
          oout.close();
        }

        return;
      }

      ins.close();

    } catch (Exception e) {
      // If an Exception occurs, return the error to the client.
      if (canThrowEx()) {
        throw new RuntimeException("Invalid maxHeight.");
View Full Code Here

    // read image
    BufferedImage image = null;

    if (inType.equals(IMG_TYPE)) {
      BufferInputStream bis = new BufferInputStream(getStdIn());
      image = ImageIO.read(bis);
      bis.close();
    } else { // OBJ_TYPE
      Object obj = null;

      if (oin.hasNext()) {
        obj = oin.next();
View Full Code Here

    try {
      //String args = StringUtils.toStringList(Arrays.asList(params), false);

      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() {
        public void run() {
          try {
            IOUtils.copy(nis, sout, 80);
//log.debug("chk11");
            exitVal[0] = 0;
          } catch (Exception ex) {
            exitVal[0] = 1;
          }
        }
      };
//log.debug("chk3");
      treader.start();
//log.debug("chk4");

      sin.setAsyncMode(true);
      byte[] buf = new byte[80];
      int bc = sin.read(buf);

      while (bc != -1 && exitVal[0] == -1) {
        nout.write(buf, 0, bc);
        bc = sin.read(buf);
      }

//log.debug("chk5");
      proc.waitFor();
//log.debug("chk6");
View Full Code Here

TOP

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

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.