You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "HiuKwok (via GitHub)" <gi...@apache.org> on 2023/03/04 05:15:27 UTC

[GitHub] [commons-email] HiuKwok commented on a diff in pull request #135: EMAIL-204: Disable eager attachment loading on MimeMessageParser

HiuKwok commented on code in PR #135:
URL: https://github.com/apache/commons-email/pull/135#discussion_r1125353219


##########
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.mail;
+
+import javax.activation.DataSource;
+import javax.mail.util.ByteArrayDataSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * <p>Wrapper class for ByteArrayDataSource, which contain reference of MimePartDataSource for given attachment.
+ * Both type and name are duplicated stored in this class, in order to delay the load of attachment binary till getInputStream() is called.
+ * </p>
+ *
+ * @since 1.5
+ */
+public class LazyByteArrayDataSource implements DataSource {
+
+    /** InputStream reference for the email attachment binary. */
+    private final InputStream referenceInputStream;
+
+    /** ByteArrayDateSource instance which contain email attachment binary in the form of byte array. */
+    private ByteArrayDataSource ds;
+
+    /** Name of the attachment. */
+    private final String name;
+
+    /** Type of the attachment. */
+    private final String type;
+
+
+    /**
+     * Constructor for this class to read all necessary information for an email attachment.
+     *
+     * @param is the InputStream which represent the attachment binary.
+     * @param type the type of the attachment.
+     * @param name the name of the attachment.
+     */
+    public LazyByteArrayDataSource(InputStream is, String type, String name) {
+        this.referenceInputStream = is;
+        this.type = type;
+        this.name = name;
+    }
+
+    /**
+     * To return an {@code ByteArrayDataSource} instance which represent the email attachment.

Review Comment:
   how about `Gets an {@code ByteArrayDataSource} instance to represent the email attachment.`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org