Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: java.io.EOFException

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.io.EOFException

    I am new to java programming and have encountered the following error. I'd greatly appreciate advice and assistance in resolving this exception.

    The exception...

    java.io.EOFException
    at java.io.DataInputStream.readUnsignedShort(DataInpu tStream.java:340)
    at com.digitaldan.jomnilinkII.MessageFactory.objectSt atus(MessageFactory
    .java:393)
    at com.digitaldan.jomnilinkII.MessageFactory.fromByte s(MessageFactory.ja
    va:131)
    at com.digitaldan.jomnilinkII.Connection.sendAndRecei ve(Connection.java:
    275)
    at com.digitaldan.jomnilinkII.Connection.reqObjectSta tus(Connection.java
    :640)
    at com.digitaldan.jomnilinkII.Connection.reqObjectSta tus(Connection.java
    :570)
    at com.digitaldan.jomnilinkII.examples.Main.main(Main .java:182)
    Listing of the referenced lines...

    MessageFactory.java line 393
    case Message.OBJ_TYPE_UNIT:{
    393 ==> status[i] = new UnitStatus(in.readUnsignedShort(),
    in.readUnsignedByte(),in.readUnsignedShort());

    MessageFactory. java line 131
    case Message.MESG_TYPE_EXT_OBJ_STATUS:
    131 ==> return (ExtendedObjectStatus)objectStatus(in,len,true);

    Connection.java line 275
    writeLock.notifyAll();
    275 ==> return MessageFactory.fromBytes(ret.data());

    Connection.java line 640
    640 ==> msg = sendAndReceive(new ReqExtenedObjectStatus(objectType,current,next));

    Connection.java 570
    public ObjectStatus reqObjectStatus(int objectType, int startObject, int endObject) throws IOException, OmniNotConnectedException, OmniInvalidResponseException, OmniUnknownMessageTypeException
    {
    570 ==> return reqObjectStatus(objectType,startObject,endObject,f alse);


    Main.java line 182
    182 ==> ObjectStatus status = c.reqObjectStatus(Message.OBJ_TYPE_UNIT,1,max_unit s);

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: java.io.EOFException

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Are you trying to read past the end of a file? If so, don't. If you don't think that's the error, then you're going to have to show us more code so that we can see what the code is doing before this error occurs and what it's trying to do that is causing the error.

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.io.EOFException

    The code I am using can be found at https://code.google.com/p/jomnilink/ This is code that accesses a security controller. Code compiles successfully. But executing the code produces the above errors.

    Specifically, the code queries the controller and displays all the internal information such as security zone names and status of the zones etc. The code isn't reading any type of file such as a database file or text file.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: java.io.EOFException

    The code is reading something, and it has tried to read beyond the available data.

    This is my opinion, not anybody else's or this site's: When you borrow someone else's code for your own application, you assume total responsibility for making it suitable for your application. A factor in one's decision to use someone else's code should include whether the author of the code is available and willing to help with its adoption and the quality of the documentation available to understand and modify the code as needed to fit the desired application.

    If the author isn't willing, the documentation is poor, or the code is beyond your abilities to understand and modify, then perhaps you've borrowed the wrong code.

  5. #5
    Junior Member
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.io.EOFException

    Problem resolved. Using the above posted stack trace led me to line 182 in Main java which is..

    ObjectStatus status = c.reqObjectStatus(Message.OBJ_TYPE_UNIT,1,max_units);

    The max_units variable was initialized to 511 but it should have been initialized to a max value of 510. Thus, the 511 value was generating the error.

  6. #6

    Default Re: java.io.EOFException

    The best way to handle this would be to terminate your infinite loop with a proper condition.

    But since you asked for the exception handling:

    Try to use two catches. Your EOFException is expected, so there seems to be no problem when it occures. Any other exception should be handled.

    ...
    } catch (EOFException e) {
    // ... this is fine
    } catch(IOException e) {
    // handle exception which is not expected
    e.printStackTrace();
    }

Similar Threads

  1. [SOLVED] EOFException
    By elamre in forum Java Networking
    Replies: 33
    Last Post: July 27th, 2012, 03:24 PM
  2. EOFException on sending object
    By treshr in forum Java Networking
    Replies: 1
    Last Post: December 9th, 2011, 01:20 PM
  3. java.io.EOFException when sending object through socket
    By treshr in forum Java Networking
    Replies: 2
    Last Post: November 8th, 2011, 06:13 AM