(geronimo-mail) branch main updated: GERONIMO-6906 - rewrite the MimeUtility.getBytes implementations independently

[email protected] Sat, 18 Jul 2026 19:24:31 +0000
Newsgroups gmane.comp.java.geronimo.cvs
Message-ID <178440267110.3029623.7591477106069287939@gitbox3-he-fi.apache.org>
This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/geronimo-mail.git


The following commit(s) were added to refs/heads/main by this push:
     new ed3517f  GERONIMO-6906 - rewrite the MimeUtility.getBytes implementations independently
ed3517f is described below

commit ed3517f3cc0561cef0e30b688c7f1a289db04a28
Author: Richard Zowalla <[email protected]>
AuthorDate: Sat Jul 18 21:24:25 2026 +0200

    GERONIMO-6906 - rewrite the MimeUtility.getBytes implementations independently
---
 .../java/jakarta/mail/internet/MimeUtility.java    | 28 +++++-----------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/geronimo-mail_2.1_spec/src/main/java/jakarta/mail/internet/MimeUtility.java b/geronimo-mail_2.1_spec/src/main/java/jakarta/mail/internet/MimeUtility.java
index 49231fe..90202cb 100644
--- a/geronimo-mail_2.1_spec/src/main/java/jakarta/mail/internet/MimeUtility.java
+++ b/geronimo-mail_2.1_spec/src/main/java/jakarta/mail/internet/MimeUtility.java
@@ -1341,12 +1341,10 @@ public class MimeUtility {
      * @since JavaMail 2.1
      */
     public static byte[] getBytes(final String s) {
-        final char[] chars = s.toCharArray();
-        final int size = chars.length;
-        final byte[] bytes = new byte[size];
-
-        for (int i = 0; i < size; i++) {
-            bytes[i] = (byte) chars[i];
+        final byte[] bytes = new byte[s.length()];
+        // the conversion keeps only the low 8 bits of every character
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = (byte) s.charAt(i);
         }
         return bytes;
     }
@@ -1360,22 +1358,8 @@ public class MimeUtility {
      * @since JavaMail 2.1
      */
     public static byte[] getBytes(final InputStream is) throws IOException {
-        int len;
-        int size = 1024;
-        byte[] buf;
-        if (is instanceof ByteArrayInputStream) {
-            size = is.available();
-            buf = new byte[size];
-            len = is.read(buf, 0, size);
-        } else {
-            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            buf = new byte[size];
-            while ((len = is.read(buf, 0, size)) != -1) {
-                bos.write(buf, 0, len);
-            }
-            buf = bos.toByteArray();
-        }
-        return buf;
+        // drain the stream completely
+        return is.readAllBytes();
     }
 }