2424 */
2525public class ActiveConnection implements Closeable
2626{
27- private final Socket socket ;
27+ private Socket socket ;
2828
2929 private OutputStream privOutputStream ;
3030
@@ -49,13 +49,7 @@ public class ActiveConnection implements Closeable
4949 */
5050 public ActiveConnection (Socket socket )
5151 {
52- if (socket == null )
53- throw new NullPointerException ("Socket cannot be null." );
54-
55- if (!socket .isConnected ())
56- throw new IllegalStateException ("Socket should have a valid connection." );
57-
58- this .socket = socket ;
52+ setSocket (socket );
5953 }
6054
6155 /**
@@ -734,6 +728,27 @@ public void setInternalCacheLimit(int internalCacheLimit)
734728 this .internalCacheLimit = internalCacheLimit ;
735729 }
736730
731+ /**
732+ * Update the socket instance with the given socket.
733+ * <p>
734+ * This method is in place so that you can upgrade to a secure connection (usually wrapped around the same socket
735+ * instance).
736+ *
737+ * In any case, the remote should also be ready for the change.
738+ *
739+ * @param socket The socket instance.
740+ */
741+ public void setSocket (Socket socket )
742+ {
743+ if (socket == null )
744+ throw new NullPointerException ("Socket cannot be null." );
745+
746+ if (!socket .isConnected ())
747+ throw new IllegalStateException ("Socket should have a valid connection." );
748+
749+ this .socket = socket ;
750+ }
751+
737752 /**
738753 * Verify that the given description is open and can read/write data.
739754 *
@@ -883,8 +898,8 @@ public synchronized Description writeBegin(long flags, long totalLength) throws
883898 * Finalize the write operation that was started with {@link #writeBegin(long, long)}.
884899 *
885900 * @param description The description object representing the operation.
886- * @throws IOException If an IO error occurs, or {@link CancelledException} if the operation is
887- * cancelled.
901+ * @throws IOException If an IO error occurs, or {@link CancelledException} if the operation is
902+ * cancelled.
888903 * @throws SizeUnderflowException If the operation is not chunked, and there are bytes left.
889904 */
890905 public synchronized void writeEnd (Description description ) throws IOException
0 commit comments