Return unwrapped SocketOutputStream from PseudoTcpSocket

JDK17 introduced a wrapper around SocketOutputStream in
Socket.getOutputStream that doesn't forward flush. Directly return
our implementation in PseudoTcpSocket making sure that the original
intent of closing the socket when the stream is closed is still
followed.
This commit is contained in:
Ingo Bauersachs 2021-11-09 00:01:59 +01:00
parent a1b3c9b503
commit 626c35e460
4 changed files with 17 additions and 4 deletions

View File

@ -245,6 +245,7 @@ public class PseudoTcpSocket extends Socket
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public synchronized void close() public synchronized void close()
throws IOException throws IOException
{ {
@ -256,6 +257,12 @@ public class PseudoTcpSocket extends Socket
} }
} }
@Override
public OutputStream getOutputStream() throws IOException
{
return socketImpl.getOutputStream();
}
/** /**
* Allows to set up the remote address directly. * Allows to set up the remote address directly.
* Otherwise, when using the other <tt>accept</tt> methods, * Otherwise, when using the other <tt>accept</tt> methods,

View File

@ -1160,6 +1160,7 @@ class PseudoTcpSocketImpl
@Override @Override
public void close() throws IOException public void close() throws IOException
{ {
PseudoTcpSocketImpl.this.close();
} }
} }

View File

@ -91,11 +91,15 @@ public class PseudoTcpStreamTest
{ {
client.setDebugName("R"); client.setDebugName("R");
client.connect(serverAddress, 5000); client.connect(serverAddress, 5000);
OutputStream os = client.getOutputStream();
// write single array // write single array
for (int i = 0; i < singleStepCount; i++) for (int i = 0; i < singleStepCount; i++)
client.getOutputStream().write(bufferSingle[i]); os.write(bufferSingle[i]);
// write whole array // write whole array
client.getOutputStream().write(bufferA); os.write(bufferA);
// write by parts // write by parts
int partCount = 7; int partCount = 7;
boolean notExact = sizeB % partCount != 0; boolean notExact = sizeB % partCount != 0;
@ -111,11 +115,11 @@ public class PseudoTcpStreamTest
int written = 0; int written = 0;
for (int j : partsSize) for (int j : partsSize)
{ {
client.getOutputStream().write(bufferB, written, j); os.write(bufferB, written, j);
written += j; written += j;
} }
assertEquals(sizeB, written); assertEquals(sizeB, written);
client.getOutputStream().flush(); os.flush();
client.close(); client.close();
} }
catch (IOException ex) catch (IOException ex)

View File

@ -51,6 +51,7 @@ java.util.logging.ConsoleHandler.formatter = org.ice4j.util.Ice4jLogFormatter
# Things coming from ice4j # Things coming from ice4j
org.ice4j.level = INFO org.ice4j.level = INFO
org.ice4j.pseudotcp.PseudoTCPBase.level = SEVERE
test.level = INFO test.level = INFO
#org.ice4j.ice.checks.levell = FINEST #org.ice4j.ice.checks.levell = FINEST
#org.ice4j.ice.ConnectivityCheckClient.level = FINER #org.ice4j.ice.ConnectivityCheckClient.level = FINER