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 8898529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:38:09+00:00 2026-06-15T00:38:09+00:00

I am seeing a strange behavior with ImageIO.read() method. I pass the InputStream to

  • 0

I am seeing a strange behavior with ImageIO.read() method.

I pass the InputStream to this method and when I try to read it for the second time it fails to read and returns null.

I am trying to upload images to the Amazon S3 and I want to create 3 version of the image. The original and 2 thumbnails. My problem is that when I want to create the 2 thumbnails I need to read the InputStream using the ImageIO.read(). If I run this method 2 for the same InputStream I get the null for the second read.

I can circumvent this problem by reading only one and passing the same BufferedImage to the scaling method. However I still need the InputStream that my method gets to pass to the AmazonS3 services in other to upload the original file as well.

So my question is does anyone have any idea what happens to the input stream after ImageIO reads it for the first time?

Code sample below

public String uploadImage(InputStream stream, String filePath, String fileName, String fileExtension) {
    try {

        String originalKey = filePath + fileName + "." + fileExtension;
        String smallThumbKey = filePath + fileName + ImageConst.Path.SMALL_THUMB + "." + fileExtension;
        String largetThumbKey = filePath + fileName + ImageConst.Path.LARGE_THUMB + "." + fileExtension;

        BufferedImage image = ImageIO.read(stream); 
        InputStream smallThumb = createSmallThumb(image, fileExtension);
        InputStream largeThumb = createLargeThumb(image, fileExtension);

        uploadFileToS3(originalKey, stream);
        uploadFileToS3(smallThumbKey, smallThumb);
        uploadFileToS3(largetThumbKey, largeThumb);

        return originalKey;

    } catch (IOException ex) {
        Logger.getLogger(ManageUser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
  • 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-06-15T00:38:10+00:00Added an answer on June 15, 2026 at 12:38 am

    I suppose, you could wrap your original input stream in a BufferedInputStream and use mark() to save the starting position within the stream, and reset() to return to it.

    To fully answer your question: every stream gets read sequentially (often there is some kind of internal pointer pointing to the current position). After the first ImageIO.read(), the stream is read until its end, thus, any further read operation won’t return any data (usually -1 to indicate the end of the stream). Using mark() you can save a certain position and later on return to it using reset().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm seeing this strange behavior where the runtime sometimes doesn't start a task Task.Factory.StartNew
I'm seeing strange behavior when I try to parse XML using the LINQ XmlReader
I am seeing strange behavior using log4j that I am completely stumped on. This
I have been seeing some strange behavior when I try to access a class
I'm seeing strange behavior when scaling Delayed::Job workers on Heroku. I have a few
I'm using MVC3 .NET4.0 (VB), and I'm seeing some strange behavior on a simple
Currently, I'm seeing a strange behavior in my .NET 2.0 WinForms application. Hosting a
I have a system where I am seeing strange behavior with the serial ports
Seeing some strange behavior, whereby connecting to Oracle database, and then calling external function,
I am seeing very, VERY strange behavior when I run certain reports: >> p

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.