 +}
 +
  #endif
-diff --git a/jni/java/org/apache/tomcat/jni/ssl/OpenSSLEngine.java b/jni/java/org/apache/tomcat/jni/ssl/OpenSSLEngine.java
-index 1837029..351adf5 100644
---- a/jni/java/org/apache/tomcat/jni/ssl/OpenSSLEngine.java
-+++ b/jni/java/org/apache/tomcat/jni/ssl/OpenSSLEngine.java
-@@ -93,7 +93,7 @@ public class OpenSSLEngine extends javax.net.ssl.SSLEngine {
-                 if (len > buffer.capacity())
-                     throw new RuntimeException("Buffer pool write overflow");
- 
--                buffer.put(src.array(), src.position(), len);
-+                buffer.put((ByteBuffer)src.slice().limit(len));
-                 int sslWrote = SSL.writeToSSL(ssl, address, len);
-                 if (sslWrote > 0) {
-                     written.set(sslWrote);
-@@ -118,7 +118,7 @@ public class OpenSSLEngine extends javax.net.ssl.SSLEngine {
-                 if (len > buffer.capacity())
-                     throw new RuntimeException("Buffer pool write overflow");
- 
--                buffer.put(src.array(), src.position(), len);
-+                buffer.put(src.slice());
-                 int netWrote = SSL.writeToBIO(networkBIO, address, len);
-                 if (netWrote > -1) {
-                     written.set(netWrote);
-@@ -142,8 +142,7 @@ public class OpenSSLEngine extends javax.net.ssl.SSLEngine {
-                 int sslRead = SSL.readFromSSL(ssl, address, buffer.limit());
-                 if (sslRead > 0) {
-                     read.set(sslRead);
--                    buffer.get(dst.array(), dst.position(), sslRead);
--                    dst.position(dst.position() + sslRead);
-+                    dst.put(buffer);
-                 }
-             }
-         };
-@@ -166,8 +165,7 @@ public class OpenSSLEngine extends javax.net.ssl.SSLEngine {
-                 if (bioRead > 0) {
-                     read.set(bioRead);
-                     buffer.limit(bioRead);
--                    buffer.get(dst.array(), dst.position(), bioRead);
--                    dst.position(dst.position() + bioRead);
-+                    dst.put(buffer);
-                 }
-             }
-         };

+                if (len > buffer.capacity())
+                    throw new RuntimeException("Buffer pool write overflow");
+
+                buffer.put(src.array(), src.position(), len);
+                int sslWrote = SSL.writeToSSL(ssl, address, len);
+                if (sslWrote > 0) {
+                    written.set(sslWrote);

+                if (len > buffer.capacity())
+                    throw new RuntimeException("Buffer pool write overflow");
+
+                if (src.hasArray()) {
+                    buffer.put(src.array(), src.position(), len);
+                } else {
+                    int pos = src.position();
+                    int lim = src.limit();
+                    src.limit(len);
+                    buffer.put(src);
+                    src.position(pos).limit(lim);
+                }
+                int netWrote = SSL.writeToBIO(networkBIO, address, len);
+                if (netWrote > -1) {
+                    written.set(netWrote);
