javadataoutputstreambufferedoutputstream

Can you prevent a BufferedOutputStream (java) from transmitting?


I"m trying to write a string to an OutputStream using

public  SSLSocket         mClient;
private BufferedOutputStream  mOutputStream;

....

mOutputStream = new BufferedOutputStream( mClient.getOutputStream() );

public synchronized void WriteString( String asciiString )
{
    mOutputStream.write( asciiString.getBytes() );
    mOutputStream.write( 0 );
    mOutputStream.flush();
}

....

WriteString( "BASEL ..." );

I successfully transmit a different string using this method, and then (in response to a message received over the stream) try to send the message above.

On this call, the write operation is flushing the buffer immediately after the "B" is written, resulting in two packets being sent over the stream. The first is a single character; the second contains the rest of the string. This worked correctly on Linux until a recent update of the server.

Is there any way to force the OutputStream or BufferedOutputStream to treat the write() as an atomic operation, or to not transmit until the flush()?

I have also tried

private DataOutputStream  mOutputStream;
mOutputStream.writeBytes(asciiString);
mOutputStream.writeByte(0);
mOutputStream.flush();

with the same results.


Solution

  • The problem was in the change in implementation of the CDC encoding in the SSLSocket. To avoid a security issue it always breaks the message after the first byte.

    see stackoverflow.com/a/33360518/4454122 for the full explanation