Skip to content

Commit

Permalink
Use Files.newInputStream and update deprecated Commons Compress APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck committed Apr 15, 2024
1 parent 6a7797e commit c8c7e21
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/main/java/de/dentrassi/rpm/builder/RpmUnpackMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -171,15 +170,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

try (final RpmInputStream in =
new RpmInputStream(new BufferedInputStream(new FileInputStream(this.rpmFile)))) {
new RpmInputStream(new BufferedInputStream(Files.newInputStream(this.rpmFile.toPath())))) {
final InputHeader<RpmTag> header = in.getPayloadHeader();
header.getEntry(RpmTag.FILE_GROUPNAME);
header.getEntry(RpmTag.FILE_USERNAME);

final CpioArchiveInputStream cpio = in.getCpioStream();
CpioArchiveEntry entry;

while ((entry = cpio.getNextCPIOEntry()) != null) {
while ((entry = cpio.getNextEntry()) != null) {
unpackEntry(header, cpio, entry, targetDir);
}
} catch (final IllegalArgumentException | IllegalStateException e) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/dentrassi/rpm/builder/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
package de.dentrassi.rpm.builder;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import com.google.common.base.Strings;
import com.google.common.io.CharStreams;
Expand Down Expand Up @@ -61,7 +61,7 @@ public String makeScriptContent() throws IOException {
}

if (this.file != null) {
try (Reader reader = new InputStreamReader(new FileInputStream(this.file), StandardCharsets.UTF_8)) {
try (Reader reader = new InputStreamReader(Files.newInputStream(this.file.toPath()), StandardCharsets.UTF_8)) {
return CharStreams.toString(reader);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/dentrassi/rpm/builder/SigningHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*******************************************************************************/
package de.dentrassi.rpm.builder;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -46,7 +46,7 @@ public static PGPPrivateKey loadKey(final Signature signature, final Logger logg
throw new MojoFailureException(signature, "'passphrase' parameter not set", "Signing requires the 'passphrase' parameter to be set.");
}

try (InputStream input = new FileInputStream(signature.getKeyringFile())) {
try (InputStream input = Files.newInputStream(signature.getKeyringFile().toPath())) {
final PGPPrivateKey privateKey = PgpHelper.loadPrivateKey(input, signature.getKeyId(), signature.getPassphrase());
if (privateKey == null) {
throw new MojoFailureException(String.format("Unable to load GPG key '%s' from '%s'", signature.getKeyId(), signature.getKeyringFile()));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/dentrassi/rpm/builder/YumMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

if (this.files != null) {
paths.addAll(this.files.stream().map(f -> f.toPath()).collect(Collectors.toList()));
paths.addAll(this.files.stream().map(File::toPath).collect(Collectors.toList()));
}
if (this.directories != null) {
for (final File dir : this.directories) {
Expand Down Expand Up @@ -245,7 +245,7 @@ private void addSinglePackage(final Path path, final Context context) throws IOE

try (CpioArchiveInputStream cpio = ris.getCpioStream()) {
CpioArchiveEntry cpioEntry;
while ((cpioEntry = cpio.getNextCPIOEntry()) != null) {
while ((cpioEntry = cpio.getNextEntry()) != null) {
providedFiles.add(RpmInformations.normalize(cpioEntry.getName()));
}
}
Expand Down

0 comments on commit c8c7e21

Please sign in to comment.