From 5814160fbb72d4f63bd935c69c5a8ebf5eaed741 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= <valtri@civ.zcu.cz>
Date: Thu, 14 Oct 2021 14:56:36 +0200
Subject: [PATCH] Warning and deprecation fixes
---
.../java/org/apache/hadoop/tar/HadoopTar.java | 33 +++++++++----------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/apache/hadoop/tar/HadoopTar.java b/src/main/java/org/apache/hadoop/tar/HadoopTar.java
index cf663db..f3bd585 100644
--- a/src/main/java/org/apache/hadoop/tar/HadoopTar.java
+++ b/src/main/java/org/apache/hadoop/tar/HadoopTar.java
@@ -23,8 +23,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
-import java.net.URI;
import java.util.List;
+import java.util.Arrays;
import java.util.LinkedList;
import org.apache.commons.cli.PosixParser;
@@ -33,18 +33,13 @@ import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
-import org.apache.commons.cli.Parser;
import org.apache.commons.logging.*;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.GzipCodec;
-import org.apache.hadoop.io.LongWritable;
-import org.apache.hadoop.io.Text;
-import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.util.Tool;
@@ -52,7 +47,6 @@ import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission;
@@ -68,6 +62,7 @@ public class HadoopTar extends Configured implements Tool {
public static final Log LOG = LogFactory.getLog(HadoopTar.class);
+ @SuppressWarnings("static-access")
private Option createBoolOption(String name, String longopt, String desc){
if( name.isEmpty() ){
return OptionBuilder.withDescription(desc)
@@ -79,6 +74,8 @@ public class HadoopTar extends Configured implements Tool {
.create(name);
}
}
+
+ @SuppressWarnings("static-access")
private Option createOption(String name, String longopt,
String desc,
String argName, int max,
@@ -101,6 +98,7 @@ public class HadoopTar extends Configured implements Tool {
.create(name);
}
}
+
private void setupOptions() {
Option verbose = createBoolOption("v", "verbose", "print verbose output");
Option create = createBoolOption("c", "create", "create a new archive" );
@@ -156,7 +154,7 @@ public class HadoopTar extends Configured implements Tool {
}
//Almost a copy of IOUtils.java:copyBytes
- //except it explicitlys set how many bytes to copy
+ //except it explicitly set how many bytes to copy
private void copyBytes(InputStream in, OutputStream out,
int buffSize, long size ) throws IOException {
if( size == 0 ) {
@@ -200,7 +198,7 @@ public class HadoopTar extends Configured implements Tool {
name.charAt(0) == '/' ) {
name = name.substring(1);
}
- if( fileStatus.isDir() ) {
+ if( fileStatus.isDirectory() ) {
entry.setName(name + "/");
entry.setSize(0);
os.putNextEntry(entry);
@@ -234,12 +232,11 @@ public class HadoopTar extends Configured implements Tool {
return p;
}
- private Path [] getTopSrcPaths(Path curDirPath, List args,
+ private Path [] getTopSrcPaths(Path curDirPath, List<String> args,
boolean keepAbsolutePath ) throws IOException {
List<Path> listOfPath = new LinkedList<Path>();
- for (Object arg : args ) {
- String str = (String) arg;
- Path p = new Path(str);
+ for (String arg : args ) {
+ Path p = new Path(arg);
if( p.isAbsolute() && !keepAbsolutePath ) {
System.err.println("Removing leading '/' from member names");
}
@@ -260,7 +257,7 @@ public class HadoopTar extends Configured implements Tool {
return listOfPath.toArray(new Path[0] );
}
- private void create(OutputStream os, Path curDirPath, List args,
+ private void create(OutputStream os, Path curDirPath, List<String> args,
boolean keepAbsolutePath, boolean optionVerbose )
throws IOException {
@@ -295,8 +292,8 @@ public class HadoopTar extends Configured implements Tool {
FileSystem ofs = curDirPath.getFileSystem(getConf());
if( ! dryrun ) {
- if( !ofs.isDirectory(curDirPath) ) {
- fail("No such directory [" + curDirPath.makeQualified(ofs) + "]");
+ if( !ofs.getFileStatus(curDirPath).isDirectory() ) {
+ fail("No such directory [" + ofs.makeQualified(curDirPath) + "]");
}
}
@@ -399,9 +396,9 @@ public class HadoopTar extends Configured implements Tool {
String curDir = (String)cmdLine.getOptionValue("directory", ".");
Path curDirPath = new Path(curDir);
- curDirPath = curDirPath.makeQualified(curDirPath.getFileSystem(getConf()));
+ curDirPath = curDirPath.getFileSystem(getConf()).makeQualified(curDirPath);
- List list = cmdLine.getArgList() ;
+ List<String> list = Arrays.asList(cmdLine.getArgs());
CompressionCodec codec = null;
if( cmdLine.hasOption("compress")) {
--
GitLab