This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-email.git
commit 313352295492fdd4035bc82640b83efa2fc9d046 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Dec 16 14:19:00 2023 -0500 Support OpenOptions for streams in new Path classes --- .../commons/mail/activation/PathDataSource.java | 10 +++++++--- .../commons/mail/activation/package-info.java | 21 +++++++++++++++++++++ .../mail/resolver/DataSourcePathResolver.java | 13 +++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/mail/activation/PathDataSource.java b/src/main/java/org/apache/commons/mail/activation/PathDataSource.java index 8c33a0d..467ca7b 100644 --- a/src/main/java/org/apache/commons/mail/activation/PathDataSource.java +++ b/src/main/java/org/apache/commons/mail/activation/PathDataSource.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; +import java.nio.file.OpenOption; import java.nio.file.Path; import java.util.Objects; @@ -40,6 +41,7 @@ public class PathDataSource implements DataSource { private final Path path; private final FileTypeMap typeMap; + private final OpenOption[] options; /** * Creates a new instance from a Path. @@ -63,10 +65,12 @@ public class PathDataSource implements DataSource { * * @param path the path, non-null. * @param typeMap the type map, non-null. + * @param options Options for opening streams. */ - public PathDataSource(final Path path, final FileTypeMap typeMap) { + public PathDataSource(final Path path, final FileTypeMap typeMap, final OpenOption... options) { this.path = Objects.requireNonNull(path, "path"); this.typeMap = Objects.requireNonNull(typeMap, "typeMap"); + this.options = options; } /** @@ -92,7 +96,7 @@ public class PathDataSource implements DataSource { */ @Override public InputStream getInputStream() throws IOException { - return Files.newInputStream(path); + return Files.newInputStream(path, options); } /** @@ -114,7 +118,7 @@ public class PathDataSource implements DataSource { */ @Override public OutputStream getOutputStream() throws IOException { - return Files.newOutputStream(path); + return Files.newOutputStream(path, options); } /** diff --git a/src/main/java/org/apache/commons/mail/activation/package-info.java b/src/main/java/org/apache/commons/mail/activation/package-info.java new file mode 100644 index 0000000..a7d8d06 --- /dev/null +++ b/src/main/java/org/apache/commons/mail/activation/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +/** + * Contains activation classes. + */ +package org.apache.commons.mail.activation; diff --git a/src/main/java/org/apache/commons/mail/resolver/DataSourcePathResolver.java b/src/main/java/org/apache/commons/mail/resolver/DataSourcePathResolver.java index a17be23..4029381 100644 --- a/src/main/java/org/apache/commons/mail/resolver/DataSourcePathResolver.java +++ b/src/main/java/org/apache/commons/mail/resolver/DataSourcePathResolver.java @@ -18,10 +18,12 @@ package org.apache.commons.mail.resolver; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.Paths; import javax.activation.DataSource; +import javax.activation.FileTypeMap; import org.apache.commons.mail.activation.PathDataSource; @@ -34,12 +36,13 @@ public final class DataSourcePathResolver extends DataSourceBaseResolver { /** The base directory of the resource when resolving relative paths */ private final Path baseDir; + private final OpenOption[] options; /** * Constructs a new instance. */ public DataSourcePathResolver() { - baseDir = Paths.get("."); + this(Paths.get(".")); } /** @@ -48,7 +51,7 @@ public final class DataSourcePathResolver extends DataSourceBaseResolver { * @param baseDir the base directory of the resource when resolving relative paths */ public DataSourcePathResolver(final Path baseDir) { - this.baseDir = baseDir; + this(baseDir, false); } /** @@ -56,10 +59,12 @@ public final class DataSourcePathResolver extends DataSourceBaseResolver { * * @param baseDir the base directory of the resource when resolving relative paths * @param lenient shall we ignore resources not found or complain with an exception + * @param options options for opening streams. */ - public DataSourcePathResolver(final Path baseDir, final boolean lenient) { + public DataSourcePathResolver(final Path baseDir, final boolean lenient, final OpenOption... options) { super(lenient); this.baseDir = baseDir; + this.options = options; } /** @@ -91,7 +96,7 @@ public final class DataSourcePathResolver extends DataSourceBaseResolver { } if (Files.exists(file)) { - result = new PathDataSource(file); + result = new PathDataSource(file, FileTypeMap.getDefaultFileTypeMap(), options); } else if (!isLenient) { throw new IOException("Cant resolve the following file resource :" + file.toAbsolutePath()); }