×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    Can anyone help me with this EOFException?

    HI.. in my program (inserted below) I used streams and then i get a EOFException when i initialise it but i do not understand what it
    means. The definition of EOFException is :

    "Signals that an end of file or end of stream has been reached
    unexpectedly during input. This exception is mainly used by data
    input streams, which generally expect a binary file in a specific
    format, and for which an end of stream is an unusual condition. Most other input streams return a special value on end of stream. "

    Could anyone pls have a look at my code and tell me if there is
    anything i did wrong? Thanks so much!

    --------------------Code snippet -----------------------------------

    public void openRecStore()
    {
    try
    {
    rs=RecordStore.openRecordStore(REC_STORE, true);
    }
    catch(Exception e)
    {
    db(e.toString());
    }
    }

    public void closeRecStore()
    {
    try
    {
    rs.closeRecordStore();
    }
    catch(Exception e)
    {
    db(e.toString());
    }
    }

    private void initInputStreams()
    {
    istrmBytes = new ByteArrayInputStream(recData);
    istrmDataType = new DataInputStream(istrmBytes);
    }

    private void initOutputStreams()
    {
    ostrmBytes = new ByteArrayOutputStream();
    ostrmDataType = new DataOutputStream(ostrmBytes);
    }

    protected void saveConfig(String name, String pass, String url,
    String port)
    {
    if (name == usernm && pass == passwd && url == urladd && port
    == portno)
    return;
    try
    {
    usernm = name;
    passwd = pass;
    urladd = url;
    portno = port;

    ostrmBytes.reset();

    ostrmDataType.writeUTF(usernm);
    ostrmDataType.writeUTF(passwd);
    ostrmDataType.writeUTF(urladd);
    ostrmDataType.writeUTF(portno);

    ostrmDataType.flush();

    byte[] record = ostrmBytes.toByteArray();

    if (rs.getNumRecords() == 0)
    rs.addRecord(record, 0 ,record.length);
    else
    rs.setRecord(1, record, 0, record.length);
    }
    catch (Exception e)
    {
    db(e.toString());
    }
    }

    private void refreshConfig()
    {
    try
    {
    //If recordstore is empty
    if (rs.getNumRecords() == 0)
    {
    //write default values
    saveConfig(usernm, passwd, urladd, portno);
    return;
    }
    istrmBytes.reset();

    rs.getRecord(1, recData, 0);
    usernm = istrmDataType.readUTF();
    passwd = istrmDataType.readUTF();
    urladd = istrmDataType.readUTF();
    portno = istrmDataType.readUTF();

    System.out.println("Username: " + usernm);
    System.out.println("Password: " + passwd);
    System.out.println("Url add: " + urladd);
    System.out.println("Port no: " + portno);
    }
    catch (Exception e)
    {
    db(e.toString());
    }
    }

    private void db(String str)
    {
    System.err.println("Record store error: " + str);
    }

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    393
    You are not calling initInputStreams() after retrieving the data from the recordstore - rs.getRecord(1, recData, 0);

    Also
    Strings are compared using String.equals(String) and not ==.

    [N]/Forum Nokia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×