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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:16:52+00:00 2026-05-16T05:16:52+00:00

As other posts here at stackoverflow has already explained, the EOFException occurs when the

  • 0

As other posts here at stackoverflow has already explained, the EOFException occurs when the end of the stream is reached unexpectedly.
I have a method, which converts a byte array into a long number. This byte array is an uint64_t number which I retrieved over my java binding from a database in C. I do know the problems with uint64_t and casting to long numbers (the signed bit).

Here is my method:

    public long castByteArrayToLong(byte[] bb){
    ByteArrayInputStream stream = new ByteArrayInputStream(bb);
    DataInputStream di = new DataInputStream(stream);
    long number=-2;
    try {
        number = di.readLong();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return number;
}

This method sometimes(!) throws this Exception:

java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readLong(DataInputStream.java:399)
at TreeManager.castByteArrayToLong(TreeManager.java:191)
at TreeManager.test2(TreeManager.java:442)
at TreeManager.main(TreeManager.java:72)

What I do not understand is why can I get that Exception? I did not specify myself the length of the byte array, but I just pass the byte array to the ByteArrayInputStream, so theoretically I shouldn’t get an such exception, I think.

(Please forgive me, if the solution is obviously)

  • 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-16T05:16:52+00:00Added an answer on May 16, 2026 at 5:16 am

    check the bytearray if it really has 8 bytes and is not null

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

Sidebar

Related Questions

Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
There have been a number of posts on stackoverflow and other places detailing how
As with a few other posts here on StackOverflow, I'm looking to load in
(Well what I gone through a lot of posts here on stackoverflow and other
I've read the other posts here about this topic, but I can't seems to
I have checked few other posts and found some UIAnimation transitions that kind-of give
I have read the other posts, e.g., vim: Executing a list of editor commands
I have seen the other posts but I am still having trouble. Below is
Okay I've read the other StackOverflow postings, forum posts on MSDN, everywhere. I CANNOT
This is a question that I know has been asked here and several other

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.