Package org.jboss.fresh.shell.commands

Source Code of org.jboss.fresh.shell.commands.BinaryToBuffImgExe

package org.jboss.fresh.shell.commands;


import org.jboss.fresh.io.BufferInputStream;
import org.jboss.fresh.io.BufferObjectWriter;
import org.jboss.fresh.io.BufferWriter;
import org.jboss.fresh.shell.AbstractExecutable;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.PrintWriter;


// EX OK

public class BinaryToBuffImgExe extends AbstractExecutable {
  private static transient org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(BinaryToBuffImgExe.class);

  public void throwException(String msg) throws Exception {
    if (canThrowEx()) {
      throw new RuntimeException(msg);
    } else {
      PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
      out.println(msg);
      out.close();
      log.error(msg, new RuntimeException());
      return;
    }
  }

  public void process(String exename, String[] params) throws Exception {
    log.debug("entered");

    if (helpRequested()) {
      PrintWriter out = new PrintWriter(new BufferWriter(getStdOut()));
      out.print("Usage: bintobuffimg [-ex] [--help]");
      out.print("\n\n   Takes a binary image (contents of an image file) from the stream and pipes a BufferedImage object through the pipe.");
      out.print("\n\n --help : this help");
      out.close();
      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;
    }

    // write object
    BufferObjectWriter oout = new BufferObjectWriter(getStdOut());
    oout.writeObject(image);
    oout.close();

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

Related Classes of org.jboss.fresh.shell.commands.BinaryToBuffImgExe

TOP
Copyright © 2018 www.massapi.com. 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.