AWT Encoding

Hi all,
(Cross posted in Java programming)
I've been banging my head on an AWT problem and would love some advice here.
I have a problem getting input from Non ASCII text in a TextField into a Unicode string.
If I take a valid Unicode string (Say Russian) and setText the TextField, it gives me ????? or High end ANSI nonsense (asc > 127) depending on what my default locale is set to. The Russian font is loaded on the platform (Win 2k using JRE 1.1.8).
In reverse, if I type in the Textfield, Russian chars are displayed if it's my default locale, or ANSI nonsense if it's not.
I've been writing test code all day trying to figure whats going on, using the Stirng.toBytes("CP1252") and new String(bytes, "CP1251") etc but not getting any joy.
Questian one:
How can I set text on a textfield to display the correct font.
Questian two:
If AWT is using peer controls, is it windows controling the painting of this control. If so, how can I get the NCS byte array from the textfield without going through a java string.
I have a strange feeling it has something to do with the font.properties file, but what?
Unfortunatly I can't use Java 2 as it has to run on a wide variaty of browsers.

Not surprized anyone answed this one. What a mare.
It appears that AWT components are a bit naughty in collecting text from the peer control.
I placed some Russian text in a text field and on pulling the 'string' out and looking at the chars found tha tit isn't actually Unicode. (All java strings are Unicode so evveryone keeps saying)
Well this is in fact CP1252 encoded, double byte string.
The A char in russian maps to a circle with a line through it, Unicode char 440 or something like that.
The char in the String is in fact 4F, which is an entirly differenct char in Unicode, but heyho it's the one I typed in CP1251. Now I'm no expert but CP1251 is not Unicode.
I managed to munge the string back to real unicode by reverting it to bytes and then removing every other (zero) byte. Then doing String(bytes, "CP1251") to get Unicode version, but that doesn't display as the OS is trying to map it the the CP1251 font.
Overall a nasty bussiness. I'm biting the bullet and going to use Swing. If the users don't like the plug in then they can go swing themselves!!

Similar Messages

  • Charset, Encoding and AWT

    Hi there,
    I'im working on an applet which is supposed to be used by Polish people (encoding iso8859-2), but I have absolutely no idea about how I could make it display correctly polish characters : The applet downloads a properties file, by calling
    Properties.load(URL)
    The file the url points to contains strange polish characters, which can be seen correctly by using the appropriate encoding in any navigator, but the applet still display ? and squares instead of the polish characters
    Does anybody has a clue or a solution??
    Thanks,
    Etienne

    I have a similar problem. What I've discovered so far is:'
    Chars seem to display OK in any given language, as long as that language is your default locale and you have just typed them in. If you try to read these chars in code, the getText on the TextField returns ???? and the bte codes appear to be NCS codes.
    If the language is NOT default locale, then they do not display correctly, however their byte code is the correct Unicode number!!
    I think this has to do with the AWT controls being native controls and so there is a strange interaction between the OS and the JVM.
    Anyone have a clue how to take non ASCII chars in and then display them correctly?

  • Problem while encoding JPEG image from JFrame paintComponent in a servlet

    Hello!
    I m developing webapplication in which I made one servlet that calls JFrame developed by me, and then encoding into JPEG image to send response on client browser. I m working on NetBeans 5.5 and the same code runs well. But my hosting server is Linux and I m getting the following error:
    java.awt.HeadlessException:
    No X11 DISPLAY variable was set, but this program performed an operation which requires it.
         java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
         java.awt.Window.<init>(Window.java:406)
         java.awt.Frame.<init>(Frame.java:402)
         java.awt.Frame.<init>(Frame.java:367)
         javax.swing.JFrame.<init>(JFrame.java:163)
         pinkConfigBeans.pinkInfo.pinkModel.pinkChartsLib.PinkChartFrame.<init>(PinkChartFrame.java:36)
         pinkConfigBeans.pinkController.showLastDayRevenueChart.processRequest(showLastDayRevenueChart.java:77)
         pinkConfigBeans.pinkController.showLastDayRevenueChart.doGet(showLastDayRevenueChart.java:107)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
    I m building the application in NetBeans and when runs then it runs well, even while browsing from LAN. But when I place the web folder creted under buil directory of NetBeans in the Tomcat on Linux, then it gives above error.
    Under given is the servlet code raising exception
    response.setContentType("image/jpeg"); // Assign correct content-type
    ServletOutputStream out = response.getOutputStream();
    /* TODO GUI output on JFrame */
    PinkChartFrame pinkChartFrame;
    pinkChartFrame = new PinkChartFrame(ssnGUIAttrInfo.getXjFrame(), ssnGUIAttrInfo.getYjFrame(), headingText, xCordText, yCordText, totalRevenueDataList);
    pinkChartFrame.setTitle("[::]AMS MIS[::] Monthly Revenue Chart");
    pinkChartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    //pinkChartFrame.setVisible(true);
    //pinkChartFrame.plotDataGUI();
    int width = 760;
    int height = 460;
    try {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    pinkChartFrame.pinkChartJPanel.paintComponent(g2);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(image);
    } catch (ImageFormatException ex) {
    ex.printStackTrace();
    response.sendRedirect("index.jsp");
    } catch (IOException ex) {
    ex.printStackTrace();
    response.sendRedirect("index.jsp");
    out.flush();
    Do resolve anybody!
    Edited by: pinkVag on Oct 15, 2007 10:19 PM

    >
    I m developing webapplication in which I made one servlet that calls JFrame developed by me, and then encoding into JPEG image to send response on client browser. I m working on NetBeans 5.5 and the same code runs well. But my hosting server is Linux and I m getting the following error:
    java.awt.HeadlessException: >That makes sense. It is saying that you cannot open a JFrame in an environment (the server) that does not support GUIs!
    To make this so it will work on the server, it will need to be recoded so that it uses the command line only - no GUI.
    What is it exactly that PinkChartFrame is generated an image of? What does it do? (OK probably 'generate a chart') But what APIs does it use (JFreeChart or such)?

  • Help with java.awt.Headless

    I added the following line to the catalina.sh file:
    JAVA_OPTS=-Djava.awt.headless=true
    My image was rendered the first time round but when I hit refresh it goes away and is replaced by just a black background. I have been working on this issue of rendering/resizing an image for months and I am just getting frustrated that I can 't seem to find out the problem.
    Here is my code:
    public static byte[] getResizedImage(byte[] imageData, int thumbWidth, int thumbHeight, int quality) throws IOException{
    //create instance of Image from byte array
    Image image = Toolkit.getDefaultToolkit().createImage(imageData);
    // determine thumbnail size from WIDTH and HEIGHT
    double thumbRatio = (double)thumbWidth / (double)thumbHeight;
    int imageWidth = image.getWidth(null);
    int imageHeight = image.getHeight(null);
    double imageRatio = (double)imageWidth / (double)imageHeight;
    if (thumbRatio < imageRatio) {
    thumbHeight = (int)(thumbWidth / imageRatio);
    } else {
    thumbWidth = (int)(thumbHeight * imageRatio);
    // draw original image to thumbnail image object and
    // scale it to the new size on-the-fly
    BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
    // set quality of thumbnail and doing resizing
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
    quality = Math.max(0, Math.min(quality, 100));
    param.setQuality((float)quality / 100.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(thumbImage);
    //return byte array
    return os.toByteArray();
    }

    MediaTracker mt = new MediaTracker(new Label());You say this is a servlet; this code is running within a J2EE app server, not where a user can see any GUI components. So the question in the first place is, why are you creating a Label GUI object in this code?
    Don't do that.

  • Background image in extended awt.Button doesn't show.

    Hi all
    I have an applet that has only an awt.Button visible on the page. Because of layout requirements I need to style that button with a background image. I have extended the java.awt.Button like this:
         class ImageButton extends Button {
              public void paint(Graphics g) {
                   super.paint(g);
                   g.drawImage(getImage(getDocumentBase(), "../img/loadSertificate.jpg"),
                             0, 0, null);
         }and use the extended:
         public void init() {
              mSignButton = new ImageButton();
              mSignButton.setLocation(0, 0);
              Dimension appletSize = this.getSize();
              mSignButton.setSize(appletSize);
              mSignButton.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        signSelectedFile();
              this.setLayout(null);
              this.add(mSignButton);
         }Now everiting is ok but when the applet is loaded the background image doesn't show and only a plain gray button is visible. The interesting part is that the image does show after I click somewhere in the browser's window and later on it's always visible as expected.
    Below is part from the log from the java console:
    basic: Applet started
    basic: Told clients applet is started
    Loaded image: http://ip:8080/UserManagement/img/loadSertificate.jpg
    network: Cache entry found [url: http://ip:8080/UserManagement/img/loadSertificate.jpg, version: null]
    network: Connecting http://ip:8080/UserManagement/img/loadSertificate.jpg with proxy=DIRECT
    network: Connecting http://ip:8080/UserManagement/img/loadSertificate.jpg with cookie "JSESSIONID=8A0936441BDA3215A10D9798742C4685"
    network: CleanupThread used 39850 us
    network: ResponseCode for http://ip:8080/UserManagement/img/loadSertificate.jpg : 304
    network: Encoding for http://ip:8080/UserManagement/img/loadSertificate.jpg : null
    network: Disconnect connection to http://ip:8080/UserManagement/img/loadSertificate.jpg
    Loaded image: http://ip:8080/UserManagement/img/loadSertificate.jpgAny suggestions how to fix this issue?!
    Edited by: factor5 on Nov 12, 2009 1:27 AM
    Edited by: factor5 on Nov 12, 2009 1:28 AM

    xmm sry but this was a forgotten repaint() :
              public void paint(Graphics g) {
                   // call super's paint method
                   super.paint(g);
                   g.drawImage(getImage(getDocumentBase(), APPLET_BUTTON_IMAGE_URL),
                             0, 0, null);
                   repaint();
              }Now it seems to work fine.
    Edited by: factor5 on Nov 12, 2009 1:44 AM

  • How to display Chinese in AWT (Urgent!)

    I have to problems,
    My computer is Win2K Traditional Chinese
    I try to run an application which Display chinese characters on the component of AWT. Although the application can run and can display correctly, there are exceptions. It throws the following error continuously,
    sun.io.UnknownCharacterException
    sun.io.UnknownCharacterException
    at sun.io.CharToByteISO8859_1.convert(Unknown Source)
    at sun.awt.PlatformFont.makeConvertedMultiFontChars(Unknown Source)
    at sun.awt.PlatformFont.makeConvertedMultiFontString(Unknown Source)
    at sun.awt.windows.WToolkit.eventLoop(Native Method)
    at sun.awt.windows.WToolkit.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    sun.io.UnknownCharacterException
    sun.io.UnknownCharacterException
    at sun.io.CharToByteISO8859_1.convert(Unknown Source)
    at sun.awt.PlatformFont.makeConvertedMultiFontChars(Unknown Source)
    at sun.awt.PlatformFont.makeConvertedMultiFontString(Unknown Source)
    at sun.awt.windows.WToolkit.eventLoop(Native Method)
    at sun.awt.windows.WToolkit.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    I try to encodes the string as follow, however, it throws another exception
    String x = new String("ChineseWordHere".getBytes("ISO-8859-1"), "Big5");
    It throws exception:
    java.io.UnsupportedEncodingException: Big-5
    at sun.io.Converters.getConverterClass(Unknown Source)
    at sun.io.Converters.newConverter(Unknown Source)
    at sun.io.ByteToCharConverter.getConverter(Unknown Source)
    at java.lang.String.getBTCConverter(Unknown Source)
    at java.lang.String.<init>(Unknown Source)
    at java.lang.String.<init>(Unknown Source)
    at Test1.<init>(Test1.java:8)
    at Test1.main(Test1.java:13)
    Do you know how to solve these two problems??
    (The most concern is that how to display Chinese in AWT)
    Thanks

    For starters, you shouldn't use the 8859 encoding since it only supports single byte representations. You should be able to successfully use UTF-8. Then to actually display the characters...or to type them, make sure you have an input method editor (IME) that supports the language - in theory if you are using a Chinese Win2k, you already have this with windows - just use the right font (I think MS Gothic should work) to show the characters. You might want to consider switching to Swing.
    Good luck

  • Substitute of java.awt.ToolKit.getDefaultToolKit.beep()

    Hello everybody. I am designing a Swing Application and there I am using java.awt.ToolKit.getDefaultToolKit.beep() method to generate sound in various operations. I want to know is it possible to generate own sound as a substitute of this method? I think it is possible. How can I do this? Thank you.

    Thank you for giving reply.
    As I wish to play .mp3 file I had downloaded an API from Javalobby . I tried it, here is my code :
    package player;
    import java.io.File;
    import java.io.IOException;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.SourceDataLine;
    * @author Tanmoy
    * @Super Scientific Calculator
    * @version 1.2010
    public class Player {
         private File audioFile;
         public Player(String path) {
              this.audioFile = new File(path);
         public void play() {
              AudioInputStream din = null;
              try {
                   AudioInputStream in = AudioSystem.getAudioInputStream(audioFile);
                   AudioFormat baseFormat = in.getFormat();
                   AudioFormat decodedFormat = new AudioFormat(
                        AudioFormat.Encoding.PCM_SIGNED,
                        baseFormat.getSampleRate(), 16, baseFormat.getChannels(),
                        baseFormat.getChannels() * 2, baseFormat.getSampleRate(),
                        false);
                   din = AudioSystem.getAudioInputStream(decodedFormat, in);
                   DataLine.Info info = new DataLine.Info(SourceDataLine.class, decodedFormat);
                   SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
                   if (line != null) {
                        line.open(decodedFormat);
                        byte[] data = new byte[4096];
                        line.start();
                        int nBytesRead;
                        while ((nBytesRead = din.read(data, 0, data.length)) != -1) {
                             line.write(data, 0, nBytesRead);
                        line.drain();
                        line.stop();
                        line.close();
                        din.close();
              } catch (Exception e) {
              } finally {
                   if (din != null) {
                        try {
                             din.close();
                        } catch (IOException e) {
    }And the calling, piece of code is :
    try {
                                  Parser parser = new Parser(parsingString, displayPanel.getCurrentBase(),
                                       displayPanel.getCurrentBase(), displayPanel.getTrigoMode(),
                                       displayPanel.getScale());
                                  String output = parser.solve();
                                  displayPanel.outputTextField.setText(output);
                                  displayPanel.outputTextField.setCaretPosition(displayPanel.outputTextField.getText().length());
                                  displayPanel.charLabel.setText((Integer.toString(output.length())));
                                  if (message == null) {
                                       message = "No Exception";
                             } catch (InvalidSyntaxException invalidSyntaxException) {
                                  message = invalidSyntaxException.getMessage();
                                  JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);
                                  new Player("/resources/what_the_hell.mp3").play();
                                  displayPanel.outputTextField.setText("0");
                                  displayPanel.charLabel.setText("0");
                             }But I can not able to here the sound.
    What to do now?
    Thank you.

  • Saving current Applet using AWT classes only

    Hey Guys,
    Can any one please help me out for saving current applet view using AWT and not SWING plese .
    I tried this code pls check if there is any improvement.
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.lang.*;
    import java.net.*;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    import java.io.*;
    import com.sun.image.codec.jpeg.*;
    public class temp extends Applet implements ActionListener
    Image myImg;
    Button b1;
         public void init()
              myImg = getImage(getCodeBase(),"temp.jpg");
              b1 = new Button("Save");
              add(b1);
              b1.addActionListener(this);
         public void paint(Graphics g)
              g.drawImage(myImg, 5, 10, this);
              g.fillOval(10,10,20,20);
         public void actionPerformed(ActionEvent ev)
              BufferedImage bin = new BufferedImage( 200, 200,BufferedImage.TYPE_INT_RGB );
              Graphics page = bin.getGraphics();
              page.setColor( java.awt.Color.BLUE );
              page.drawString( "BLUE", 100, 100 );
              ImageIO.write( bin, "JPEG", new java.io.File( "Test7.jpeg" ) );
    PLESE HELP ME SOOOON

    Hi ,Thanx for your concern.
    I am the same sayjava but I lost my password dats why the name is changed.
    Now about the querry i have completely changed the coding and have successfully created a new JPEG image .
    Can u please tell me how can I save it I have tried the following coding but it doent seem to work...
    File file = new File("images", "imgOne.jpg");
    FileOutputStream out = new FileOutputStream(file);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
    param.setQuality(1.0f, false);
    encoder.setJPEGEncodeParam(param);
    encoder.encode(bi); //bi is the BufferedImage
    Thanks Again.

  • Problems when jpeg encoding multiple images

    Hi, im trying to write a servlet which generates multiple thumbs. However when encoding for the second time i get an error java.io.IOException: reading encoded JPEG Stream.
    I can't figure out the problem
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.awt.Image;
    import java.awt.Graphics2D;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import javax.swing.ImageIcon;
    import com.sun.image.codec.jpeg.JPEGCodec;
    import com.sun.image.codec.jpeg.JPEGImageEncoder;
    public class Thumbs extends HttpServlet {
      private String dbDriver = "com.mysql.jdbc.Driver";
      private String dbURL = "jdbc:mysql://localhost/shopper?";
      private String userID = "javauser";
      private String passwd = "javadude";
      private Connection dbConnection;
      //Initialize global variables
      public void init() throws ServletException {
      //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try{
          String foreignNr = request.getParameterValues("p")[0];
          String maxDim = request.getParameterValues("s")[0];
          if (foreignNr != null){
            int foreignID = Integer.parseInt(foreignNr);
            int maxDimension = Integer.parseInt(maxDim);
            response.setContentType("image/jpeg");
            OutputStream out = response.getOutputStream();
            writeThumbnailPictures(out,foreignID,maxDimension);
        } catch (Exception ex){
            log(ex.getMessage());
      public void writeThumbnailPictures(OutputStream out,int foreignID,int maxDimension){
        try{
          Class.forName(dbDriver);
          dbConnection = DriverManager.getConnection(dbURL, userID, passwd);
          PreparedStatement pageStatement;
          pageStatement = dbConnection.prepareStatement(
              "select * from pictures where ForeignID = ?");
          pageStatement.setInt(1, foreignID);
          ResultSet recs = pageStatement.executeQuery();
          while (recs.next()) {
            byte[] data = recs.getBytes("Picture");
            if (data != null) {
              Image inImage = new ImageIcon(data).getImage();
              // Determine the scale.
               double scale = (double)maxDimension / (double)inImage.getHeight(null);
               if (inImage.getWidth(null) > inImage.getHeight(null)) {
                   scale = (double)maxDimension /(double)inImage.getWidth(null);
               // Determine size of new image.
               // One of them should equal maxDim.
               int scaledW = (int)(scale*inImage.getWidth(null));
               int scaledH = (int)(scale*inImage.getHeight(null));
               // Create an image buffer in
               //which to paint on.
               BufferedImage outImage = 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 = outImage.createGraphics();
               g2d.drawImage(inImage, tx, null);
               g2d.dispose();
               // JPEG-encode the image
               JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
               encoder.encode(outImage);
          out.close();
        catch(Exception ex){
          ex.printStackTrace();
      //Clean up resources
      public void destroy() {
    }

    Hi,
    I am facing same problem while generating the thumbs. Did you figure out what the problem is? if you have the solution, do post it.
    Thanks in advance
    Mo

  • Aleatory One factory fails for the operation "encode"-JPEG

    I've a very strange problem with JAI.write using JPEG, but is happening aleatory. Some times it works, some times I get the exception and some other times don't. What I've seen is that when I got first this error, then all the rest of the images throws it. I mean, I'm working OK and then I got the exception, from there, all the images, no matter that they were not trowing exceptions before, now they do, so I don't know what is happening. I'll post some code snippets and the full stack trace of the exception. Hope you can help me:
    First, I have a class that is a JSP-Tag:
    RenderedOp outputImage = JAI.create("fileload", imgFile.getAbsolutePath());
    int widthSize = outputImage.getWidth();
    int heightSize = outputImage.getHeight();
    try{
        outputImage.dispose();                         
    }catch(Exception e){}
    outputImage = null;That's the first thing, now, the second, this is a Servlet that writes the image to the browser (GetImageServlet its name, which appears in the stack trace):
    FileSeekableStream fss = new FileSeekableStream(file);
    RenderedOp outputImage = JAI.create("stream", fss);
    int widthSize = outputImage.getWidth();
    int heightSize = outputImage.getHeight();
    if ((outputImage.getWidth() > 0) && (outputImage.getHeight() > 0)) {
                        if ((isThumbnail) && ((outputImage.getWidth() > 60) || (outputImage.getHeight() > 60))) {
                             outputImage = ImageManagerJAI.thumbnail(outputImage, 60);
                        } else if (outputRotate != 0) {
                             outputImage = ImageManagerJAI.rotate(outputImage, outputRotate);
                        OutputStream os = resp.getOutputStream();
    resp.setContentType("image/jpeg");
         ImageManagerJAI.writeResult(os, outputImage, "JPEG");
                        outputImage.dispose();
                        os.flush();
                        os.close();
    outputImage = null;
    imgFile = null;The code of ImageManagerJAI.writeResult, which is a method I use above:
    public static void writeResult(OutputStream os, RenderedOp image, String type) throws IOException {
              if ("GIF".equals(type)) {
                   GifEncoder encoder = new GifEncoder(image.getAsBufferedImage(), os);
                   encoder.encode();
              } else {
                   JAI.create("encode", image, os, type, null);
         }And the full exception trace is:
    Error: One factory fails for the operation "encode"
    Occurs in: javax.media.jai.ThreadSafeOperationRegistry
    java.lang.reflect.InvocationTargetException
         at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
         at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
         at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
         at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
         at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
         at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
         at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:888)
         at javax.media.jai.JAI.createNS(JAI.java:1099)
         at javax.media.jai.JAI.create(JAI.java:973)
         at javax.media.jai.JAI.create(JAI.java:1668)
         at com.syc.image.ImageManagerJAI.writeResult(ImageManagerJAI.java:27)
         at GetImageServlet.doGet(GetImageServlet.java:214)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: com.sun.media.jai.codecimpl.util.ImagingException
         at com.sun.media.jai.codecimpl.ImagingListenerProxy.errorOccurred(ImagingListenerProxy.java:63)
         at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:280)
         at com.sun.media.jai.opimage.EncodeRIF.create(EncodeRIF.java:70)
         ... 31 more
    Caused by: com.sun.media.jai.codecimpl.util.ImagingException: IOException occurs when encode the image.
         ... 33 more
    Caused by: java.io.IOException: reading encoded JPEG Stream
         at sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream(Native Method)
         at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:472)
         at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:228)
         at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:277)
         ... 32 more
    javax.media.jai.util.ImagingException: All factories fail for the operation "encode"
         at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1687)
         at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
         at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
         at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
         at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
         at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:888)
         at javax.media.jai.JAI.createNS(JAI.java:1099)
         at javax.media.jai.JAI.create(JAI.java:973)
         at javax.media.jai.JAI.create(JAI.java:1668)
         at com.syc.image.ImageManagerJAI.writeResult(ImageManagerJAI.java:27)
         at GetImageServlet.doGet(GetImageServlet.java:214)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.reflect.InvocationTargetException
         at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
         at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
         ... 26 more
    Caused by: com.sun.media.jai.codecimpl.util.ImagingException
         at com.sun.media.jai.codecimpl.ImagingListenerProxy.errorOccurred(ImagingListenerProxy.java:63)
         at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:280)
         at com.sun.media.jai.opimage.EncodeRIF.create(EncodeRIF.java:70)
         ... 31 more
    Caused by: com.sun.media.jai.codecimpl.util.ImagingException: IOException occurs when encode the image.
         ... 33 more
    Caused by: java.io.IOException: reading encoded JPEG Stream
         at sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream(Native Method)
         at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:472)
         at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:228)
         at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:277)
         ... 32 more
    Caused by:
    java.lang.reflect.InvocationTargetException
         at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
         at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
         at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
         at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
         at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
         at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
         at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:888)
         at javax.media.jai.JAI.createNS(JAI.java:1099)
         at javax.media.jai.JAI.create(JAI.java:973)
         at javax.media.jai.JAI.create(JAI.java:1668)
         at com.syc.image.ImageManagerJAI.writeResult(ImageManagerJAI.java:27)
         at GetImageServlet.doGet(GetImageServlet.java:214)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: com.sun.media.jai.codecimpl.util.ImagingException
         at com.sun.media.jai.codecimpl.ImagingListenerProxy.errorOccurred(ImagingListenerProxy.java:63)
         at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:280)
         at com.sun.media.jai.opimage.EncodeRIF.create(EncodeRIF.java:70)
         ... 31 more
    Caused by: com.sun.media.jai.codecimpl.util.ImagingException: IOException occurs when encode the image.
         ... 33 more
    Caused by: java.io.IOException: reading encoded JPEG Stream
         at sun.awt.image.codec.JPEGImageEncoderImpl.writeJPEGStream(Native Method)
         at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:472)
         at sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:228)
         at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:277)
         ... 32 moreI'm using JDK 1.6, Tomcat 5.5, Windows XP, and JAI 1.1.2_01 (the jars are in the WEB-INF/lib of the project AND in the jdk 6/jre/lib/ext, while the dlls are only on jdk 6/jre/bin)
    Please help, I don't know what to do, I've weeks with this problem. Dukes available pleaseeee!

    Hi
    you can check if you get in the error logs an message like 'Could not load mediaLib accelerator wrapper classes. Continuing in pure Java mode.' may be the problem of JAI native accelerator

  • Problems with the apache ij tool, encoding error?

    Hello
    I try running a method in the ij.class from within my application. I always receive an error, which I believe is to do with encoding.
    int i = org.apache.derby.tools.ij.runScript(getDatabase("test").getConnection(),
             in,"ASCII", System.out, "UTF8");gives me:
    Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.apache.derby.iapi.tools.i18n.LocalizedResource.getNewEncodedOutput(Ljava/io/OutputStream;Ljava/lang/String;)Lorg/apache/derby/iapi/tools/i18n/LocalizedOutput;
    at org.apache.derby.tools.ij.runScript(Unknown Source)
    The method getNewEncodedOutput() is not in the class specified, as indicated by the exception. However, I was hoping the problem was me not using the encoding correct. I have tried different comb. of "ASCII" and "UTF8".
    Regard
    Fluid

    Hello
    I try running a method in the ij.class from within my
    application. I always receive an error, which I
    believe is to do with encoding.
    int i =
    org.apache.derby.tools.ij.runScript(getDatabase("test"
    ).getConnection(),
    in,"ASCII", System.out, "UTF8");
    gives me:
    Exception in thread "AWT-EventQueue-0"
    java.lang.NoSuchMethodError:
    org.apache.derby.iapi.tools.i18n.LocalizedResource.get
    NewEncodedOutput(Ljava/io/OutputStream;Ljava/lang/Stri
    ng;)Lorg/apache/derby/iapi/tools/i18n/LocalizedOutput;
    at
    org.apache.derby.tools.ij.runScript(Unknown Source) The method getNewEncodedOutput() is not in the class
    specified, as indicated by the exception. However, I
    was hoping the problem was me not using the encoding
    correct. I have tried different comb. of "ASCII" and
    "UTF8". Yeah, mismatch.
    Alternatively, you could do away with ij if you are simply running a script. For example, if you had a script that looked like this:
    CREATE TABLE HOCKEY_TEAMS(
      TEAM_NAME  VARCHAR(30)  NOT NULL,
      CITY                 VARCHAR(50)
    )You could simply read this file, build a query and perform a statement.executeQuery(String query);good luck.

  • Encoding JPEG renders "blurry"

    I have created a java servlet that dynamically renders an image for use as a heading for each page. The servlets works fine, except for when a "background image" is used to go behind the text.
    Here is what the result looks like:
    http://www.mikelukenonline.com/servlets/lmp-framework?page_name=dynamicText&fontName=Old%20English%20Text%20MT&fontColor=168~167~167&shaddow=Y&fontSize=28&backgroundColor=white&text=Welcome%20to%20this%20site&width=500&x=11&y=21&height=34&backgroundImage=http://www.mikelukenonline.com/images/headings/titleblank2.jpg
    One of the parameters in the URL is called "backgroundImage" which takes a URL of a jpg and draws that first. In this example, the background image is:
    http://www.mikelukenonline.com/images/headings/titleblank2.jpg
    Now if you look at the background image that I just listed, you see that it looks pretty clear. However, if you look at the full link above, you can see that the baclground image is "blurry" or "pixilated" - not sure the best work to describe it!
    It is also worth noting that it is only when using the background image that it looks bad. If you remove the backgroundImage parameter, the text is rendered just fine:
    http://www.mikelukenonline.com/servlets/lmp-framework?page_name=dynamicText&fontName=Old%20English%20Text%20MT&fontColor=168~167~167&shaddow=Y&fontSize=28&backgroundColor=white&text=Welcome%20to%20this%20site&width=500&x=11&y=21&height=34
    I have tried everything I can think of and I can't get past this issue. Below are samples from the servlet. Any thoughts at all would be greatly appreciated!
    This is the code that "draws" the final image:
    private java.awt.Graphics.Graphics graphics = null;
    private java.awt.Image.Image image = null;
    private java.awt.Frame.Frame frame = null;
    public Image getImage(){
         drawImage();
         if (image == null)
              image = getFrame().createImage(getWidth(), getHeight());
         return image;
    private Frame getFrame() {
         frame = new Frame();
         frame.addNotify();
         return frame;
    private Graphics getGraphics() {
         if ( image == null )
              image = getFrame().createImage(getWidth(), getHeight());
         if ( graphics == null )
              graphics = image.getGraphics();
         return graphics;
    private void drawImage() {
         getGraphics().setColor(getBackgroundColor());
         getGraphics().fillRect(0, 0, getWidth(), getHeight());
         getGraphics().setColor(Color.white);
         if(getBackgroundImage() != null && getBackgroundImage().trim().length() > 0) {
              try {
                   Frame f = new Frame();
                   f.addNotify(); 
                   Image im = Toolkit.getDefaultToolkit().createImage(new URL(getBackgroundImage()));
                   MediaTracker mt = new MediaTracker(f);
                   mt.addImage(im, 0);           
                   mt.waitForAll();
                   getGraphics().drawImage(im,0,0,null);
                   im.flush();
                   im = null;
                   f.removeNotify();
                   frame = null;
              } catch (Exception e) {}     
         Font f = null;
         try {
              f = new Font(getFontName(), Font.PLAIN, getFontSize());
         } catch (Exception e) {
              f = new Font("TimesRoman", Font.PLAIN, getFontSize());
         getGraphics().setFont(f);          
         if(showShaddow()) {
              getGraphics().setColor(new Color(229, 229, 229));     
              getGraphics().drawString(getText(),getXPos()+3,getYPos()+3);
         getGraphics().setColor(getFontColor());
         getGraphics().drawString(getText(),getXPos(),getYPos());     
    }This is part of a class later that takes this image and encodes it and renders it to the browser:
    public void transform(HttpServletRequest request, HttpServletResponse response) {
         try {
              Frame frame = null;       
              Graphics graphics = null;       
              try {           
                   frame = new Frame();           
                   frame.addNotify();           
                   MediaTracker mt = new MediaTracker(frame);
                   Image image = getImage(); // returns the image from the previous code
                   mt.addImage(image, 0);           
                   mt.waitForAll();           
                   int w = image.getWidth(frame);           
                   int h = image.getHeight(frame); 
                   BufferedImage offscreen = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);       
                   graphics = offscreen.getGraphics();    
                   graphics.drawImage(image, 0, 0, frame);           
                         graphics.dispose();
                   com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(response.getOutputStream());
                   com.sun.image.codec.jpeg.JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(offscreen);
                   param.setQuality(1, false);
                   encoder.setJPEGEncodeParam(param);   
                   encoder.encode(offscreen);      
              } catch (Exception e) {
              } finally {           
                   if (graphics != null) {               
                        graphics.dispose();           
                   if (frame != null) {               
                        frame.removeNotify();           
                   getImage().flush();
                   response.flushBuffer();
         } catch (Exception e) {}
    }

    Hi,
    Well, you could try fixing the memory leak in
    JPEGAsyncDecoder. :)

  • Error: One factory fails for the operation "encode"

    Dear all,
    This is my first attempt to use JAI. I am getting the following error message. Any ideas why this could happen?
    Thanks
    Error: One factory fails for the operation "encode"
    Occurs in: javax.media.jai.ThreadSafeOperationRegistry
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:494)
         at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
         at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
         at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
         at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
         at com.sun.media.jai.opimage.FileStoreRIF.create(FileStoreRIF.java:138)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:494)
         at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
         at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
         at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
         at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
         at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
         at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
         at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:888)
         at javax.media.jai.JAI.createNS(JAI.java:1099)
         at javax.media.jai.JAI.create(JAI.java:973)
         at javax.media.jai.JAI.create(JAI.java:1668)
         at RectifyIt.actionPerformed(RectifyIt.java:715)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1834)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2152)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
         at java.awt.Component.processMouseEvent(Component.java:5463)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3052)
         at java.awt.Component.processEvent(Component.java:5228)
         at java.awt.Container.processEvent(Container.java:1961)
         at java.awt.Component.dispatchEventImpl(Component.java:3931)
         at java.awt.Container.dispatchEventImpl(Container.java:2019)
         at java.awt.Component.dispatchEvent(Component.java:3779)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4203)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3883)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3813)
         at java.awt.Container.dispatchEventImpl(Container.java:2005)
         at java.awt.Window.dispatchEventImpl(Window.java:1757)
         at java.awt.Component.dispatchEvent(Component.java:3779)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Caused by: java.lang.OutOfMemoryError: Java heap space
    Error: One factory fails for the operation "filestore"
    Occurs in: javax.media.jai.ThreadSafeOperationRegistry
    java.lang.reflect.InvocationTargetException

    I'm not an expert in JAI either, but I noticed you have an OutOfMemoryError at the bottom of your stacktrace. I'd focus on that.
    Are you dealing with a large image? Maybe try holding as little of the image in memory as possible. Do you have a small Java heap size? Maybe try increasing the footprint. etc...
    CowKing

  • Sun.awt.image.ToolkitImage

    Hi
    I'm integrating with a 3rd party package which delivers various images.
    These come in different objects, mostly BASE64DecoderStream and BufferedImage. But, GIF files are delivered as a ToolkitImage object.
    For the BufferedImage I do something like
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ImageIO.write(image, "JPG", stream);and puts it in DB. I just can't figure out a way to do the same for ToolkitImage.
    My questions are:
    1. Is there a way to convert/cast the ToolkitImage so i can format/encode it and put it in DB, similar to the example above?
    2. Where is the API documentation for the internal classes in package "sun.awt.image"?
    Hope you experts can help me out here :)

    > Didn't know it could be casted to an Image.
    Do you know of any documentation on sun.awt.image in general?
    Why Developers Should Not Write Programs That Call 'sun' Packages
    The classes that Sun includes with the Java 2 SDK, Standard Edition, fall into package groups java.*, javax.*, org.* and sun.*. All but the sun.* packages are a standard part of the Java platform and will be supported into the future. In general, packages such as sun.*, that are outside of the Java platform, can be different across OS platforms (Solaris, Windows, Linux, Macintosh, etc.) and can change at any time without notice with SDK versions (1.2, 1.2.1, 1.2.3, etc). Programs that contain direct calls to the sun.* packages are not 100% Pure Java. In other words:
    The java.*, javax.* and org.* packages documented in the Java 2 Platform Standard Edition API Specification make up the official, supported, public interface.
    If a Java program directly calls only API in these packages, it will operate on all Java-compatible platforms, regardless of the underlying OS platform.
    The sun.* packages are not part of the supported, public interface.
    A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.
    For these reasons, there is no documentation available for the sun.* classes. Platform-independence is one of the great advantages of developing in the Java programming language. Furthermore, Sun and our licensees of Java technology are committed to maintaining backward compatibility of the APIs for future versions of the Java platform. (Except for code that relies on serious bugs that we later fix.) This means that once your program is written, the class files will work in future releases.
    Each company that implements the Java platform will do so in their own private way. The classes in sun.* are present in the SDK to support the Sun implementation of the Java platform: the sun.* classes are what make the Java platform classes work "under the covers" for the Sun Java 2 SDK. These classes will not in general be present on another vendor's Java platform. If your Java program asks for a class "sun.package.Foo" by name, it may fail with ClassNotFoundError, and you will have lost a major advantage of developing in Java.
    Technically, nothing prevents your program from calling into sun.* by name. From one release to another, these classes may be removed, or they may be moved from one package to another, and it's fairly likely that their interface (method names and signatures) will change. (From the Sun point of view, since we are committed to maintaining the Java platform, we need to be able to change sun.* to refine and enhance the platform.) In this case, even if you are willing to run only on the Sun implementation, you run the risk of a new version of the implementation breaking your program.
    In general, writing java programs that rely on sun.* is risky: they are not portable, and are not supported.
    ~

  • How to decide if an object was completely encoded using XMLEncoder

    Hi, 'completely encoded' means that the object reconstructed from XMLDecoder is equal to the original object. Here is an example class which is not 'completely encoded' (because one of its properties is of type java.awt.geom.Point2D):
    public static class SomeBean {
      private Dimension size;
      private Point2D location;
      public Dimension getSize() {
        return size;
      public void setSize(Dimension size) {
        this.size = size;
      public Point2D getLocation() {
        return location;
      public void setLocation(Point2D point) {
        this.location = point;
      public String toString() {
        return getClass().getName() + "[location=" + location +
          ",size=" + size + "]";
    here is the corresponding XML representation:
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.5.0_12" class="java.beans.XMLDecoder">
      <object class="XML_Persistence$SomeBean">
        <void property="location">
          <object class="java.awt.geom.Point2D$Float"/>
        </void>
        <void property="size">
          <object class="java.awt.Dimension">
            <int>42</int>
            <int>42</int>
          </object>
        </void>
      </object>
    </java>
    By printing out the two objects, you can see that they are not equal:
    Serializing: XML_Persistence$SomeBean[location=Point2D.Float[42.0, 42.0],size=java.awt.Dimension[width=42,height=42]]
    Deserialzed: XML_Persistence$SomeBean[location=Point2D.Float[0.0, 0.0],size=java.awt.Dimension[width=42,height=42]]
    It isn't problematic for my app if an object cannot be 'completely encoded', i'm just looking for a reliable way to know.
    Thanks, Hans

    ejp wrote:
    This is very odd. The XMLEncoder already does a trial decode to make sure it has serialized the object.
    Doesn't a line like this one
    <object class="java.awt.geom.Point2D$Float"/>
    indicate that an object (as part of an object graph) was encoded without any additional information?Exactly. But the XMLEncoder assumes wevertying is a Java bean, with getters and setters. Any object without set methods isn't going to be serialized correctly. You need to add your own PersistenceDelegate for any such classes you find.Thanks, ejp - knowing that an object cannot be reconstructed by encoding/decoding it would be sufficient. Currently my strategy is:
    a) Encode the object to memory, using XMLEncoder.
    b) If no exceptions were thrown, parse the resulting XML for lines of the form "<object ... />". If any such line is found, the object is no candidate for XML-serialization.
    c) If the object (or a super-class) overrides Object.equals, the XML is decoded and the resulting object is compared to the original one.

Maybe you are looking for

  • How to use the Output clause for the updated statment

    How to use the output clause for the below update stament, DECLARE @MyTableVar table(     sname int NOT NULL) update A set stat ='USED'  from (select top 1 * from #A  where stat='AVAILABLE' order by sno)A Output inserted.sname INTO @MyTableVar; SELEC

  • SQL on Server 2012 Essentials

    What are the options and/or limits for running SQL server (Standard or Express, 2012 or 2008 or 2005) on Server 2012 Essentials? Thank you.

  • Sapscript: Print Dialog not coming up!!!!!!!

    Dear All, One of my SapScript program is behaving abnormally. When I execute it using the login of ABAP, the Print Dialog Box appears where the user can select the output device etc for printing but when I do the same from some other login, other tha

  • Broken VoIP connection E61 to asterisk server afte...

    After upgrading and restoring settings from backed up data the mobile phone finds it's WLAN connection and shows an established VoIP connection (as before). But no incoming or outgoing calls are possible over VoIP. At server side nothing was changed.

  • Can't Save a Big TIFF 16 bit RGB Image to JPEG

    Hi all, I'm using Photoshop CS5 Extended on Windows 7 64 bit (Home Premium). I've stitched a panorama in Photoshop using merge from 19 RAW files (Canon 5D mkII) in 16 bit. All was fine, I saved the merged image as TIFF 16 and worked on it. Resolution