garydgregory commented on code in PR #135: URL: https://github.com/apache/commons-email/pull/135#discussion_r1123668685
########## 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. + * + * @return An ByteArrayDataSource instance which contain the email attachment. + * @throws IOException resolving the email attachment failed + */ + @Override + public InputStream getInputStream() throws IOException { + if (ds == null) { + //Only read attachment data to memory when getInputStream() is called. + ds = new ByteArrayDataSource(referenceInputStream, type); + ds.setName(name); + } + return ds.getInputStream(); + } + + /** + * Not supported. + * + * @return N/A + * @since 1.5 Review Comment: You already use `@since 1.5` on the class, that's all that is needed. ########## 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. Review Comment: Constructor... -> Constructs a new instance to read all necessary information for an email attachment. ########## 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. + * + * @return An ByteArrayDataSource instance which contain the email attachment. + * @throws IOException resolving the email attachment failed + */ + @Override + public InputStream getInputStream() throws IOException { + if (ds == null) { Review Comment: If this class is not meant to be thread-safe, then document that in the class comment. ########## src/test/java/org/apache/commons/mail/util/MimeMessageParserTest.java: ########## @@ -498,4 +503,61 @@ public void testParseInlineCID() throws Exception assertEquals(ds, mimeMessageParser.getAttachmentList().get(0)); } + @Test + public void testAttachmentNotLoaded() throws Exception + { + final MimeMessageParser mimeMessageParser = new MimeMessageParser(null); + final InputStream inputStream = createMock(InputStream.class); + final MimePart mimePart = getMockedMimePart(inputStream); + + // Create data source with mocked data. + final DataSource dataSource_new = mimeMessageParser.createDataSource(null,mimePart); + // Verify no inputStream.read() is made at this point (Lazy initialization). + verify(inputStream); + } + + + @Test + public void testAttachmentLoaded() throws Exception + { + final MimeMessageParser mimeMessageParser = new MimeMessageParser(null); + final InputStream inputStream = createMock(InputStream.class); + // Despite .getInputStream() called for 3 times, but the desk IO for attachment read should only happen once. + expect(inputStream.read(new byte[8192])).andReturn(0).once(); + final MimePart mimePart = getMockedMimePart(inputStream); + + // Create data source with mocked data. + final DataSource dataSource_new = mimeMessageParser.createDataSource(null,mimePart); Review Comment: No underscores in names, please, use camel case. ########## 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; + Review Comment: One blank line, not 2. ########## 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. + * + * @return An ByteArrayDataSource instance which contain the email attachment. + * @throws IOException resolving the email attachment failed + */ + @Override + public InputStream getInputStream() throws IOException { + if (ds == null) { + //Only read attachment data to memory when getInputStream() is called. + ds = new ByteArrayDataSource(referenceInputStream, type); + ds.setName(name); + } + return ds.getInputStream(); + } + + /** + * Not supported. + * + * @return N/A + * @since 1.5 + */ + @Override + public OutputStream getOutputStream() throws IOException { + throw new IOException("cannot do this"); + } + + /** + * Get the content type. + * + * @return A String. + * @since 1.5 Review Comment: You already use `@since 1.5` on the class, that's all that is needed. ########## 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. + * + * @return An ByteArrayDataSource instance which contain the email attachment. + * @throws IOException resolving the email attachment failed + */ + @Override + public InputStream getInputStream() throws IOException { + if (ds == null) { + //Only read attachment data to memory when getInputStream() is called. + ds = new ByteArrayDataSource(referenceInputStream, type); + ds.setName(name); + } + return ds.getInputStream(); + } + + /** + * Not supported. + * + * @return N/A + * @since 1.5 + */ + @Override + public OutputStream getOutputStream() throws IOException { + throw new IOException("cannot do this"); + } + + /** + * Get the content type. + * + * @return A String. + * @since 1.5 + */ + @Override + public String getContentType() { + return type; + } + + /** + * Get the name. + * + * @return A String. + * @since 1.5 Review Comment: You already use `@since 1.5` on the class, that's all that is needed. ########## 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: A getter "Gets...", "To..." -> "Gets..." ########## 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. + * + * @return An ByteArrayDataSource instance which contain the email attachment. + * @throws IOException resolving the email attachment failed + */ + @Override + public InputStream getInputStream() throws IOException { + if (ds == null) { + //Only read attachment data to memory when getInputStream() is called. + ds = new ByteArrayDataSource(referenceInputStream, type); + ds.setName(name); + } + return ds.getInputStream(); + } + + /** + * Not supported. + * + * @return N/A + * @since 1.5 + */ + @Override + public OutputStream getOutputStream() throws IOException { + throw new IOException("cannot do this"); + } + + /** + * Get the content type. Review Comment: "Get" -> "Gets". ########## 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. + * + * @return An ByteArrayDataSource instance which contain the email attachment. + * @throws IOException resolving the email attachment failed + */ + @Override + public InputStream getInputStream() throws IOException { + if (ds == null) { + //Only read attachment data to memory when getInputStream() is called. + ds = new ByteArrayDataSource(referenceInputStream, type); + ds.setName(name); + } + return ds.getInputStream(); + } + + /** + * Not supported. + * + * @return N/A + * @since 1.5 + */ + @Override + public OutputStream getOutputStream() throws IOException { + throw new IOException("cannot do this"); + } + + /** + * Get the content type. + * + * @return A String. + * @since 1.5 + */ + @Override + public String getContentType() { + return type; + } + + /** + * Get the name. Review Comment: "Gets..." ########## 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. + * + * @return An ByteArrayDataSource instance which contain the email attachment. + * @throws IOException resolving the email attachment failed + */ + @Override + public InputStream getInputStream() throws IOException { + if (ds == null) { + //Only read attachment data to memory when getInputStream() is called. + ds = new ByteArrayDataSource(referenceInputStream, type); + ds.setName(name); + } + return ds.getInputStream(); + } + + /** + * Not supported. + * + * @return N/A + * @since 1.5 + */ + @Override + public OutputStream getOutputStream() throws IOException { + throw new IOException("cannot do this"); Review Comment: There is an exception for that: `UnsupportedOperationException`. ########## src/main/java/org/apache/commons/mail/util/MimeMessageParser.java: ########## @@ -270,14 +267,8 @@ protected DataSource createDataSource(final Multipart parent, final MimePart par final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); - byte[] content; - try (InputStream inputStream = dataSource.getInputStream()) - { - content = this.getContent(inputStream); - } - final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); - result.setName(dataSourceName); + final LazyByteArrayDataSource result = new LazyByteArrayDataSource(dataSource.getInputStream(), contentType, dataSourceName); Review Comment: It seems the local variable is no longer needed. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
