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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:29:53+00:00 2026-06-14T13:29:53+00:00

I have to encode in base64 an array of bytes (that is a byte

  • 0

I have to encode in base64 an array of bytes (that is a byte stream of a Zipfile) but the array is too big. So I split the array in two parts, encode the first half, then the second one, and in the end I append the second part to the first part. The thing is that sometimes when i decode the result the zipfile seems to be corrupted.

    FileInputStream fis = new FileInputStream(new File(filePath));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    while((len = fis.read(buffer)) >= 0) {
        baos.write(buffer);
    }

    byte[] bArray = baos.toByteArray();

    int bArrayLength = bArray.length;

    byte[] part1 = new byte[bArray.length / 2];
    byte[] part2 = new byte[ (bArrayLength%2 == 0) ? (bArray.length / 2) : (bArray.length / 2 + 1)];

    System.arraycopy(bArray, 0, part1, 0, part1.length);
    System.arraycopy(bArray, part1.length, part2, 0, part2.length);

    resultArray[0] = Base64.encodeBytes(part1);
    resultArray[1] = Base64.encodeBytes(part2);

What is the problem? Is that split that causes the issue?

  • 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-14T13:29:54+00:00Added an answer on June 14, 2026 at 1:29 pm

    This probably doesn’t work because of padding. The Base64 algorithm pads its output with a == if its encoding results in a trailing group (of 24 bits) that contains only 1 byte, or = if it contains only 2 bytes. That means you cannot just add two encoded strings together and expect to get the correct result.

    But how do you know the array is too big — do you get an OutOfMemoryException?

    You may try to split not exactly at the halfway point, but choose a different point until you no longer get a trailing = for that part.

    See also http://en.wikipedia.org/wiki/Base64.

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

Sidebar

Related Questions

I have a simple question. Should I return a byte-array or simply base64 encode
I have an array of bytes (any length), and I want to encode this
I have a long function, as seen below: hash_correct = hashlib.md5(salt + password)).digest().encode(base64) I'd
I am trying to encode a matrix that i have (after calculating frame differences)
How to decode a base64 encoded string to byte array on Android API level
I have a java code base that generates an URL safe base64 encoded hash
I have to send a byte array (encoded photo) from my PHP client to
I have a Base64 encoded String that contains PDF data. Using the EncdDecd unit
So I have some code that reads a certain amount of bytes from a
Can we convert a byte array into an InputStream in Java? I have been

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.