Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 127655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:30:40+00:00 2026-05-11T05:30:40+00:00

I have a Java Applet that I’m making some edits to and am running

  • 0

I have a Java Applet that I’m making some edits to and am running into performance issues. More specifically, the applet generates an image which I need to export to the client’s machine.

This is really at the proof-of-concept stage so bear with me. For right now, the image is exported to the clients machine at a pre-defined location (This will be replaced with a save-dialog or something in the future). However, the process takes nearly 15 seconds for a 32kb file.

I’ve done some ‘shoot-by-the-hip’ profiling where I have printed messages to the console at logical intervals throughout the method in question. I’ve found, to my surprise, that the bottleneck appears to be with the actual data stream writing process, not the jpeg encoding.

KEEP IN MIND THAT I ONLY HAVE A BASIC KNOWLEDGE OF JAVA AND ITS METHODS

So go slow :p – I’m mainly looking for suggestions to solve the problem rather the solution itself.

Here is the block of code where the magic happens:

ByteArrayOutputStream jpegOutput = new ByteArrayOutputStream(); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(jpegOutput); encoder.encode(biFullView); byte[] imageData = jpegOutput.toByteArray();  String myFile='C:' + File.separator + 'tmpfile.jpg'; File f = new File(myFile);  try { dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myFile),512)); dos.writeBytes(byteToString(imageData)); dos.flush(); dos.close(); } catch (SecurityException ee) {     System.out.println('writeFile: caught security exception'); } catch (IOException ioe) {     System.out.println('writeFile: caught i/o exception'); } 

Like I mentioned, using system.out.println() I’ve narrowed the performance bottleneck to the DataOutputStream block. Using a variety of machines with varying hardware stats seems to have little effect on the overall performance.

Any pointers/suggestions/direction would be much appreciated.

EDIT: As requested, byteToString():

public String byteToString(byte[] data){   String text = new String();   for ( int i = 0; i < data.length; i++ ){     text += (char) ( data[i] & 0x00FF );   }   return text; } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:30:40+00:00Added an answer on May 11, 2026 at 5:30 am

    If you don’t need the image data byte array you can encode directly to the file:

    String myFile='C:' + File.separator + 'tmpfile.jpg'; File f = new File(myFile); FileOutputStream fos = null; try {     fos = new FileOutputStream(f);     JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(                              new BufferedOutputStream(fos));     encoder.encode(biFullView); } catch (SecurityException ee) {     System.out.println('writeFile: caught security exception'); } catch (IOException ioe) {     System.out.println('writeFile: caught i/o exception'); }finally{     if(fos != null) fos.close(); } 

    If you need the byte array to perform other operations it’s better to write it directly to the FileOutputStream:

    //... fos = new FileOutputStream(myFile)); fos.write(imageData, 0, imageData.length); //... 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In this case, I'd just create an index on the… May 11, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer A bone is a frame of reference for a collection… May 11, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer Your suspicion is correct - JS-generated content cannot be relied… May 11, 2026 at 6:02 pm

Related Questions

I have a Java Applet that I'm making some edits to and am running
I have a Java Applet that uses AWT. In some (rare) circumstances, the platform
I have a Component which I am using both in a standalone Java application
I have a Java applet consisting of a wizard-like form with three steps. At
I have a paint application that runs as a Java applet. I need to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.