diff --git a/src/org/ice4j/socket/DelegatingSocket.java b/src/org/ice4j/socket/DelegatingSocket.java
index 39dfa9f..f9d2987 100644
--- a/src/org/ice4j/socket/DelegatingSocket.java
+++ b/src/org/ice4j/socket/DelegatingSocket.java
@@ -756,14 +756,7 @@ public class DelegatingSocket
outputStream = getOutputStream();
}
- int len = p.getLength();
- int off = p.getOffset();
- byte data[] = new byte[len + 2];
- data[0] = (byte) ((len >> 8) & 0xff);
- data[1] = (byte) (len & 0xff);
- System.arraycopy(p.getData(), off, data, 2, len);
- outputStream.write(data, 0, len + 2);
- data = null;
+ outputStream.write(p.getData(), p.getOffset(), p.getLength());
}
/**
@@ -802,9 +795,22 @@ public class DelegatingSocket
inputStream = this.getInputStream();
}
- inputStream.skip(2);
- len = inputStream.read(data);
- if (len > 0)
+ short desiredLength = (short)
+ (((inputStream.read() << 8) & 0xff) | (inputStream.read() & 0xff));
+
+ int readLen = 0;
+ int offset = 0;
+
+ while(readLen < desiredLength)
+ {
+ len = inputStream.read(data, offset, desiredLength - offset);
+ if(len == -1)
+ throw new SocketException("read failed");
+ offset += len;
+ readLen += len;
+ }
+
+ if (readLen == desiredLength)
{
p.setData(data);
p.setLength(len);
diff --git a/src/org/ice4j/socket/GoogleRelayedCandidateSocket.java b/src/org/ice4j/socket/GoogleRelayedCandidateSocket.java
index 7b69824..2818647 100644
--- a/src/org/ice4j/socket/GoogleRelayedCandidateSocket.java
+++ b/src/org/ice4j/socket/GoogleRelayedCandidateSocket.java
@@ -319,8 +319,8 @@ public class GoogleRelayedCandidateSocket
{
DatagramPacket p = new DatagramPacket(
b,
- off + 2,
- len - 2,
+ off,
+ len,
target);
send(p);
diff --git a/src/org/ice4j/socket/MultiplexingSocket.java b/src/org/ice4j/socket/MultiplexingSocket.java
index b6ae4b8..c12034f 100644
--- a/src/org/ice4j/socket/MultiplexingSocket.java
+++ b/src/org/ice4j/socket/MultiplexingSocket.java
@@ -61,6 +61,11 @@ public class MultiplexingSocket
*/
private final TCPInputStream inputStream = new TCPInputStream();
+ /**
+ * Custom OutputStream for this Socket.
+ */
+ private TCPOutputStream outputStream = null;
+
/**
* The Object which synchronizes the access to {@link #inReceive}.
*/
@@ -512,4 +517,18 @@ public class MultiplexingSocket
{
return inputStream;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public OutputStream getOutputStream()
+ throws IOException
+ {
+ if(outputStream == null)
+ {
+ outputStream = new TCPOutputStream(super.getOutputStream());
+ }
+
+ return outputStream;
+ }
}
diff --git a/src/org/ice4j/socket/TCPInputStream.java b/src/org/ice4j/socket/TCPInputStream.java
index f44c333..5f81c13 100644
--- a/src/org/ice4j/socket/TCPInputStream.java
+++ b/src/org/ice4j/socket/TCPInputStream.java
@@ -181,10 +181,12 @@ public class TCPInputStream
public int read()
throws IOException
{
- //getNextPacket();
+ getNextPacket();
+ int ret = currentPacket[currentPacketOffset];
+ currentPacketOffset++;
+ currentPacketLength--;
- // TODO Auto-generated method stub
- return 0;
+ return ret;
}
/**
diff --git a/src/org/ice4j/socket/TCPOutputStream.java b/src/org/ice4j/socket/TCPOutputStream.java
new file mode 100644
index 0000000..8b31d5c
--- /dev/null
+++ b/src/org/ice4j/socket/TCPOutputStream.java
@@ -0,0 +1,86 @@
+/*
+ * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
+ * Maintained by the SIP Communicator community (http://sip-communicator.org).
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.ice4j.socket;
+
+import java.io.*;
+
+/**
+ * TCP output stream for TCP socket. It is used to multiplex sockets and keep
+ * the OutputStream interface to users.
+ *
+ * @author Sebastien Vincent
+ */
+public class TCPOutputStream
+ extends OutputStream
+{
+ /**
+ * Original OutputStream that this class wraps.
+ */
+ private final OutputStream outputStream;
+
+ /**
+ * Initializes a new TCPOutputStream.
+ *
+ * @param outputStream original OutputStream
+ */
+ public TCPOutputStream(OutputStream outputStream)
+ {
+ this.outputStream = outputStream;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close()
+ throws IOException
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void flush()
+ throws IOException
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void write(byte[] b)
+ throws IOException
+ {
+ write(b, 0, b.length);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void write(byte[] b, int off, int len)
+ throws IOException
+ {
+ byte data[] = new byte[len + 2];
+ data[0] = (byte)((len >> 8) & 0xff);
+ data[1] = (byte)(len & 0xff);
+ System.arraycopy(b, off, data, 2, len);
+ outputStream.write(data, 0, len + 2);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void write(int arg0) throws IOException
+ {
+ // TODO Auto-generated method stub
+ }
+}