From c0d3fb7be0bf70a1cdc62f78ce6fc8bf4bf21682 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 14 Oct 2021 16:30:13 +0200 Subject: [PATCH] Fixed deprecated code. --- build.num | 2 +- src/fr/devinsy/unix/EtcGroupFileReader.java | 6 ++---- src/fr/devinsy/unix/EtcPasswdFile.java | 11 +---------- src/fr/devinsy/unix/EtcPasswdFileReader.java | 9 +++------ src/fr/devinsy/unix/Unix.java | 12 +++++------- src/fr/devinsy/unix/acl/AclManager.java | 6 ++---- src/fr/devinsy/unix/linux/Linux.java | 19 +++++++++---------- src/fr/devinsy/unix/util/ChangeableFile.java | 9 +-------- 8 files changed, 24 insertions(+), 50 deletions(-) diff --git a/build.num b/build.num index 89f8ffe..3592977 100644 --- a/build.num +++ b/build.num @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Thu May 04 22:58:25 CEST 2017 +#Thu Oct 14 16:30:13 CEST 2021 build.number=0 diff --git a/src/fr/devinsy/unix/EtcGroupFileReader.java b/src/fr/devinsy/unix/EtcGroupFileReader.java index 7cc566c..8727a70 100644 --- a/src/fr/devinsy/unix/EtcGroupFileReader.java +++ b/src/fr/devinsy/unix/EtcGroupFileReader.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2010,2013-2014,2017-2018 Christian Pierre MOMON + * Copyright (C) 2006-2021 Christian Pierre MOMON * * This file is part of Devinsy-unix. * @@ -65,7 +65,7 @@ public class EtcGroupFileReader Group group = new Group(); group.setName(tokens[0]); group.setPassword(tokens[1]); - group.setGid((new Integer(tokens[2])).intValue()); + group.setGid(Integer.valueOf(tokens[2]).intValue()); // Manage the case of empty shell. if (tokens.length == 4) @@ -105,5 +105,3 @@ public class EtcGroupFileReader return result; } } - -// //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/unix/EtcPasswdFile.java b/src/fr/devinsy/unix/EtcPasswdFile.java index fd7498b..ab4e75c 100644 --- a/src/fr/devinsy/unix/EtcPasswdFile.java +++ b/src/fr/devinsy/unix/EtcPasswdFile.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2010,2013-2014,2017-2018 Christian Pierre MOMON + * Copyright (C) 2006-2021 Christian Pierre MOMON * * This file is part of Devinsy-unix. * @@ -18,15 +18,10 @@ */ package fr.devinsy.unix; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import fr.devinsy.unix.util.ChangeableFile; /** * The Class EtcPasswdFile. - * - * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class EtcPasswdFile extends ChangeableFile { @@ -36,8 +31,6 @@ public class EtcPasswdFile extends ChangeableFile private static final EtcPasswdFile instance = new EtcPasswdFile(); } - private static final Logger logger = LoggerFactory.getLogger(EtcPasswdFile.class); - private Users users; /** @@ -152,5 +145,3 @@ public class EtcPasswdFile extends ChangeableFile return result; } } - -// //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/unix/EtcPasswdFileReader.java b/src/fr/devinsy/unix/EtcPasswdFileReader.java index a940f67..91c9e03 100644 --- a/src/fr/devinsy/unix/EtcPasswdFileReader.java +++ b/src/fr/devinsy/unix/EtcPasswdFileReader.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2010,2013-2014,2017-2018 Christian Pierre MOMON + * Copyright (C) 2006-2021 Christian Pierre MOMON * * This file is part of Devinsy-unix. * @@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory; /** * The Class EtcPasswdFileReader. * - * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class EtcPasswdFileReader { @@ -66,8 +65,8 @@ public class EtcPasswdFileReader User user = new User(); user.setLogin(tokens[0]); user.setPassword(tokens[1]); - user.setUid((new Integer(tokens[2])).intValue()); - user.setGid((new Integer(tokens[3])).intValue()); + user.setUid(Integer.valueOf(tokens[2]).intValue()); + user.setGid(Integer.valueOf(tokens[3]).intValue()); user.setRealName(tokens[4]); user.setHomeDirectory(tokens[5]); @@ -109,5 +108,3 @@ public class EtcPasswdFileReader return result; } } - -// //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/unix/Unix.java b/src/fr/devinsy/unix/Unix.java index e231aaa..1bc372b 100644 --- a/src/fr/devinsy/unix/Unix.java +++ b/src/fr/devinsy/unix/Unix.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2010,2013-2015,2017-2018 Christian Pierre MOMON + * Copyright (C) 2006-2021 Christian Pierre MOMON * * This file is part of Devinsy-unix. * @@ -735,7 +735,7 @@ public class Unix { try { - String[] command = ArrayUtils.add(args, 0, "setfacl"); + String[] command = ArrayUtils.insert(0, args, "setfacl"); sudo(command); } catch (CmdExecException exception) @@ -745,8 +745,8 @@ public class Unix } /** - * As 'passwd' command has not the option '--stdin' in all systems (eg. Debian), - * this method uses the 'chpasswd' command. + * As 'passwd' command has not the option '--stdin' in all systems (eg. + * Debian), this method uses the 'chpasswd' command. * * @param login * the login @@ -854,7 +854,7 @@ public class Unix if (SystemUtils.IS_OS_UNIX) { - String[] newCommand = ArrayUtils.add(command, 0, SUDO); + String[] newCommand = ArrayUtils.insert(0, command, SUDO); result = CmdExecUtils.run(newCommand); } else @@ -945,5 +945,3 @@ public class Unix } } } - -// //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/unix/acl/AclManager.java b/src/fr/devinsy/unix/acl/AclManager.java index 8757fdd..c01ea5d 100644 --- a/src/fr/devinsy/unix/acl/AclManager.java +++ b/src/fr/devinsy/unix/acl/AclManager.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010,2013-2015,2017-2018 Christian Pierre MOMON + * Copyright (C) 2010-2021 Christian Pierre MOMON * * This file is part of Devinsy-unix. * @@ -516,7 +516,7 @@ public class AclManager { try { - String[] newArgs = ArrayUtils.add(args, 0, "setfacl"); + String[] newArgs = ArrayUtils.insert(0, args, "setfacl"); Unix.sudo(newArgs); } catch (CmdExecException exception) @@ -525,5 +525,3 @@ public class AclManager } } } - -// //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/unix/linux/Linux.java b/src/fr/devinsy/unix/linux/Linux.java index 1f76a74..5fc6c28 100644 --- a/src/fr/devinsy/unix/linux/Linux.java +++ b/src/fr/devinsy/unix/linux/Linux.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Christian Pierre MOMON + * Copyright (C) 2017-2021 Christian Pierre MOMON * * This file is part of Devinsy-unix. * @@ -20,6 +20,7 @@ package fr.devinsy.unix.linux; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -236,7 +237,7 @@ public class Linux { String result; - result = FileUtils.readFileToString(new File("/proc/cpuinfo")); + result = FileUtils.readFileToString(new File("/proc/cpuinfo"), StandardCharsets.UTF_8); // return result; @@ -253,7 +254,7 @@ public class Linux { String result; - result = FileUtils.readFileToString(new File("/proc/meminfo")); + result = FileUtils.readFileToString(new File("/proc/meminfo"), StandardCharsets.UTF_8); // return result; @@ -269,7 +270,7 @@ public class Linux { String result; - result = FileUtils.readFileToString(new File("/proc/uptime")); + result = FileUtils.readFileToString(new File("/proc/uptime"), StandardCharsets.UTF_8); // return result; @@ -286,7 +287,7 @@ public class Linux { String result; - result = FileUtils.readFileToString(new File("/proc/version")); + result = FileUtils.readFileToString(new File("/proc/version"), StandardCharsets.UTF_8); // return result; @@ -309,16 +310,16 @@ public class Linux if (debianFile.exists()) { - result = "Debian " + FileUtils.readFileToString(debianFile); + result = "Debian " + FileUtils.readFileToString(debianFile, StandardCharsets.UTF_8); } else if (redhatFile.exists()) { - result = FileUtils.readFileToString(redhatFile); + result = FileUtils.readFileToString(redhatFile, StandardCharsets.UTF_8); } else if (suseFile.exists()) { // TODO - result = "SUSE " + FileUtils.readFileToString(debianFile); + result = "SUSE " + FileUtils.readFileToString(debianFile, StandardCharsets.UTF_8); } else { @@ -336,5 +337,3 @@ public class Linux return result; } } - -// //////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/fr/devinsy/unix/util/ChangeableFile.java b/src/fr/devinsy/unix/util/ChangeableFile.java index 5c36c7e..b0a884d 100644 --- a/src/fr/devinsy/unix/util/ChangeableFile.java +++ b/src/fr/devinsy/unix/util/ChangeableFile.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2010,2013-2014,2017-2018 Christian Pierre MOMON + * Copyright (C) 2006-2021 Christian Pierre MOMON * * This file is part of Devinsy-unix. * @@ -20,9 +20,6 @@ package fr.devinsy.unix.util; import java.io.File; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * The Class CachedFile. * @@ -31,8 +28,6 @@ import org.slf4j.LoggerFactory; public class ChangeableFile { - private static final Logger logger = LoggerFactory.getLogger(ChangeableFile.class); - private File sourceFile; private long sourceTime; @@ -119,5 +114,3 @@ public class ChangeableFile this.sourceTime = 0; } } - -// ////////////////////////////////////////////////////////////////////////