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

  • SEARCH
  • Home
  • 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 844859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:21:14+00:00 2026-05-15T06:21:14+00:00

I’m working on a Java program that needs to send an image (preferably in

  • 0

I’m working on a Java program that needs to send an image (preferably in PNG format, though I could perhaps use another format if necessary) over the network. The logical way to do this is, of course, to first send the length of the PNG image data, then the data itself. Problem: I don’t see any method in ImageIO or anywhere else that will give me the length of the image data. Does this exist somewhere in the Java 1.6 standard library?

I know I could just write it to a ByteArrayOutputStream and get the length of the resulting array, but before resorting that I wanted to make sure I’m not missing something built in. And besides, that makes an extra copy of the image data, which I’d rather not do if it’s not necessary.

  • 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. Editorial Team
    Editorial Team
    2026-05-15T06:21:15+00:00Added an answer on May 15, 2026 at 6:21 am

    This information is not available since the final content length is not exactly predictable beforehand. You would need to generate the entire image first.


    On the other hand, what network protocol are you using? You may want to check if the protocol in question supports sending the data in chunks.

    To take HTTP as an example, you can use Transfer-Encoding: chunked for this. With this you can make use of a byte[] buffer to send the chunks. Basically, first send a chunk header denoting the chunk length, then a CRLF and then the whole chunk and then two CRLF’s and so on until end of stream and then send a chunk header of 0 length.

    You can of course also invent your own proprietary network protocol with different encodings, but it’ll be after all easy if you use a standard protocol like HTTP since there exist lot of API-provided or 3rd party tools for this like java.net.URLConnection and Apache HttpComponents Client, both of which has builtin support for sending data in chunks as well.

    See also:

    • Chunked Transfer Encoding in Wikipedia
    • Answer containing an example of ChunkedOutputStream which may be of use
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Linq-to-SQL is a very easy to learn, easy to use… May 15, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer Not possible. Maven checks the repositories in their declaration order… May 15, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer EDIT2: Generics on superclasses and interfaces are not erased. You… May 15, 2026 at 4:19 pm

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.