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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:36:24+00:00 2026-06-14T11:36:24+00:00

The result I’m getting is that files of the same type are returning the

  • 0

The result I’m getting is that files of the same type are returning the same md5 hash value. For example two different jpgs are giving me the same result. However, a jpg vs a apk are giving different results.

Here is my code…

public static String checkHashURL(String input) {
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        InputStream is = new URL(input).openStream();

        try {
            is = new DigestInputStream(is, md);

            int b;

            while ((b = is.read()) > 0) {
                ;
            }
        } finally {
            is.close();
        }
        byte[] digest = md.digest();
        StringBuffer sb = new StringBuffer();

        for (int i = 0; i < digest.length; i++) {
            sb.append(
                    Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(
                            1));
        }
        return sb.toString();

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
  • 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-14T11:36:27+00:00Added an answer on June 14, 2026 at 11:36 am

    This is broken:

    while ((b = is.read()) > 0)
    

    Your code will stop at the first byte of the stream which is 0. If the two files have the same values before the first 0 byte, you’ll fail. If you really want to call the byte-at-a-time version of read, you want:

    while (is.read() != -1) {}
    

    The parameterless InputStream.read() method returns -1 when it reaches the end of the stream.

    (There’s no need to assign a value to b, as you’re not using it.)

    Better would be to read a buffer at a time:

    byte[] ignoredBuffer = new byte[8 * 1024]; // Up to 8K per read
    while (is.read(ignoredBuffer) > 0) {}
    

    This time the condition is valid, because InputStream.read(byte[]) would only ever return 0 if you pass in an empty buffer. Otherwise, it will try to read at least one byte, returning the length of data read or -1 if the end of the stream has been reached.

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

Sidebar

Related Questions

I had a result that i wanted (getting max value.) with using keypath feature
Example: result = ActiveRecord::Base.connection.execute(select 'ABC') How can I get the 'ABC' value from result
My result tables/images will be displayed in the same page. But the submit button
the result i want is a textarea that hooks up to WMD (markdown editor).
The result of the square border turns out to be different width, it seems
I have a result set that I want to trim a 2 digit suffix
My result set come from a group/count query: SELECT m.type, COUNT(m.type) FROM sent_message m
Result from SELECT statement is different from the result from SELECT inside VIEW. How
The result I would need is that when cloning a repository the code is
I've tracked down a weird MySQL problem to the two different ways I was

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.