Symbian
Symbian OS Library

FAQ-0965 When my MIDlet writes data to a (Data)OutputStream it fails to arrive at the connection endpoint. Why is this?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: J2ME MIDP
Created: 01/19/2004 Modified: 01/27/2004
Number: FAQ-0965
Platform: Symbian OS v6.1, Symbian OS v7.0, Symbian OS v7.0s

Question:
When my MIDlet writes data to a (Data)OutputStream it fails to arrive at the connection endpoint. Why is this?

Answer:
The most likely reason is failure to call the (Data)OutputStream flush() method which according to the Java documentation "Flushes this output stream and forces any buffered output bytes to be written out. "

    This must be called after writing to OutputStreams on Symbian's MIDP implementation (MIDP 1.0 and 2.0). For example
    String message = "Hello";
    byte[] buf= message.getBytes();
    try{
    StreamConnection conn = (StreamConnection)Connector.open(url);
    DataOutputStream out = conn.openDataOutputStream();
    out.write(buf);
    out.flush();//must be called
    out.close();
    }catch(IOException ioe) {...}

    .