You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/05/28 23:16:19 UTC
[commons-release-plugin] branch master updated: Replace
construction of FileInputStream and FileOutputStream objects with Files NIO
APIs. (#44)
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-release-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 2a74c41 Replace construction of FileInputStream and FileOutputStream objects with Files NIO APIs. (#44)
2a74c41 is described below
commit 2a74c41ff599b704f9009de56e946d3358ca7219
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Sat May 29 01:16:12 2021 +0200
Replace construction of FileInputStream and FileOutputStream objects with Files NIO APIs. (#44)
---
.../plugin/mojos/CommonsDistributionDetachmentMojo.java | 9 +++++----
.../release/plugin/mojos/CommonsDistributionStagingMojo.java | 8 +++++---
.../release/plugin/mojos/CommonsSiteCompressionMojo.java | 12 +++++++-----
3 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
index 9719314..a044793 100755
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionDetachmentMojo.java
@@ -17,10 +17,11 @@
package org.apache.commons.release.plugin.mojos;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -153,7 +154,7 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
try {
final String artifactKey = getArtifactKey(artifact);
if (!artifactKey.endsWith(".asc")) { // .asc files don't need hashes
- try (FileInputStream fis = new FileInputStream(artifact.getFile())) {
+ try (InputStream fis = Files.newInputStream(artifact.getFile().toPath())) {
artifactSha512s.put(artifactKey, DigestUtils.sha512Hex(fis));
}
}
@@ -179,7 +180,7 @@ public class CommonsDistributionDetachmentMojo extends AbstractMojo {
private void writeAllArtifactsInSha512PropertiesFile() throws MojoExecutionException {
final File propertiesFile = new File(workingDirectory, "sha512.properties");
getLog().info("Writing " + propertiesFile);
- try (FileOutputStream fileWriter = new FileOutputStream(propertiesFile)) {
+ try (OutputStream fileWriter = Files.newOutputStream(propertiesFile.toPath())) {
artifactSha512s.store(fileWriter, "Release SHA-512s");
} catch (final IOException e) {
throw new MojoExecutionException("Failure to write SHA-512's", e);
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
index 7c16e9e..e067e80 100755
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsDistributionStagingMojo.java
@@ -17,11 +17,11 @@
package org.apache.commons.release.plugin.mojos;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -441,7 +441,8 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
//
// HEADER file
//
- try (Writer headerWriter = new OutputStreamWriter(new FileOutputStream(headerFile), StandardCharsets.UTF_8)) {
+ try (Writer headerWriter = new OutputStreamWriter(Files.newOutputStream(headerFile.toPath()),
+ StandardCharsets.UTF_8)) {
HeaderHtmlVelocityDelegate.builder().build().render(headerWriter);
} catch (final IOException e) {
final String message = "Could not build HEADER html file " + headerFile;
@@ -453,7 +454,8 @@ public class CommonsDistributionStagingMojo extends AbstractMojo {
// README file
//
final File readmeFile = new File(distRcVersionDirectory, README_FILE_NAME);
- try (Writer readmeWriter = new OutputStreamWriter(new FileOutputStream(readmeFile), StandardCharsets.UTF_8)) {
+ try (Writer readmeWriter = new OutputStreamWriter(Files.newOutputStream(readmeFile.toPath()),
+ StandardCharsets.UTF_8)) {
// @formatter:off
final ReadmeHtmlVelocityDelegate readmeHtmlVelocityDelegate = ReadmeHtmlVelocityDelegate.builder()
.withArtifactId(project.getArtifactId())
diff --git a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
index 9875848..d7c91d3 100755
--- a/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
+++ b/src/main/java/org/apache/commons/release/plugin/mojos/CommonsSiteCompressionMojo.java
@@ -17,9 +17,10 @@
package org.apache.commons.release.plugin.mojos;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
@@ -147,8 +148,9 @@ public class CommonsSiteCompressionMojo extends AbstractMojo {
*/
private void writeZipFile(final File outputDirectory, final File directoryToZip, final List<File> fileList)
throws IOException {
- try (FileOutputStream fos = new FileOutputStream(outputDirectory.getAbsolutePath() + "/site.zip");
- ZipOutputStream zos = new ZipOutputStream(fos)) {
+ try (OutputStream fos = Files.newOutputStream(new File(outputDirectory.getAbsolutePath() + "/site.zip")
+ .toPath());
+ ZipOutputStream zos = new ZipOutputStream(fos)) {
for (final File file : fileList) {
if (!file.isDirectory()) { // we only zip files, not directories
addToZip(directoryToZip, file, zos);
@@ -168,7 +170,7 @@ public class CommonsSiteCompressionMojo extends AbstractMojo {
* @throws IOException if adding the <code>file</code> doesn't work out properly.
*/
private void addToZip(final File directoryToZip, final File file, final ZipOutputStream zos) throws IOException {
- try (FileInputStream fis = new FileInputStream(file)) {
+ try (InputStream fis = Files.newInputStream(file.toPath())) {
// we want the zipEntry's path to be a relative path that is relative
// to the directory being zipped, so chop off the rest of the path
final String zipFilePath = file.getCanonicalPath().substring(