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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:58:29+00:00 2026-05-15T01:58:29+00:00

I have some CLOB columns in a database that I need to put Base64

  • 0

I have some CLOB columns in a database that I need to put Base64 encoded binary files in.
These files can be large, so I need to stream them, I can’t read the whole thing in at once.

I’m using org.apache.commons.codec.binary.Base64InputStream to do the encoding, and I’m running into a problem. My code is essentially this

FileInputStream fis = new FileInputStream(file);
Base64InputStream b64is = new Base64InputStream(fis, true, -1, null);
BufferedReader reader = new BufferedReader(new InputStreamReader(b64is));

preparedStatement.setCharacterStream(1, reader);

When I run the above code, I get one of these during the execution of the update
java.io.IOException: Underlying input stream returned zero bytes, it is thrown deep in the InputStreamReader code.

Why would this not work? It seems to me like the reader would attempt to read from the base 64 stream, which would read from the file stream, and everything should be happy.

  • 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-15T01:58:30+00:00Added an answer on May 15, 2026 at 1:58 am

    This appears to be a bug in Base64InputStream. You’re calling it correctly.

    You should report this to the Apache commons codec project.

    Simple test case:

    import java.io.*;
    import org.apache.commons.codec.binary.Base64InputStream;
    
    class tmp {
      public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream(args[0]);
        Base64InputStream b64is = new Base64InputStream(fis, true, -1, null);
    
        while (true) {
          byte[] c = new byte[1024];
          int n = b64is.read(c);
          if (n < 0) break;
          if (n == 0) throw new IOException("returned 0!");
          for (int i = 0; i < n; i++) {
            System.out.print((char)c[i]);
          }
        }
      }
    }
    

    the read(byte[]) call of InputStream is not allowed to return 0. It does return 0 on any file which is a multiple of 3 bytes long.

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

Sidebar

Related Questions

Have some audio and video files that users are to download, however depending on
I'm not the first to have these issues, and will list some reference posts
I have some javascript code that is used in a few different pages in
I have some automatic de-serialization code that will set an object's properties using KVC
I have some trivial markup that looks like the following: <li class=someclass> <=% t'model.attr'
I have some objects which I draw onto a Canvas as part of a
I have some difficulties grasping some concepts. Grateful for help. Let's say you have
I have some asynchronous operations being performed on the main thread of my application.
Morning, I'm having some trouble creating tables/loading fixtures. (symfony 1.4.6 with the bundled Doctrine
I'm trying to do some basic queries using the groovy.sql.Sql object, and I'm getting

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.