1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-20 12:42:06 +02:00

reformat Utils.java

This commit is contained in:
soloturn
2021-12-27 10:05:31 +01:00
parent 41b71e398e
commit 8ab3168541

View File

@@ -1,5 +1,22 @@
package com.rarchives.ripme.utils;
import com.rarchives.ripme.ripper.AbstractRipper;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.RollingFileAppender;
import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy;
import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -24,31 +41,13 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineEvent;
import com.rarchives.ripme.ripper.AbstractRipper;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.RollingFileAppender;
import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy;
import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
/**
* Common utility functions used in various places throughout the project.
*/
@@ -64,9 +63,9 @@ public class Utils {
private static PropertiesConfiguration config;
private static HashMap<String, HashMap<String, String>> cookieCache;
private static HashMap<ByteBuffer, String> magicHash = new HashMap<>();
private static final HashMap<ByteBuffer, String> magicHash = new HashMap<>();
private static ResourceBundle resourceBundle = null;
private static ResourceBundle resourceBundle;
static {
cookieCache = new HashMap<>();
@@ -242,7 +241,7 @@ public class Utils {
}
private static File getJarDirectory() {
File jarDirectory = Utils.class.getResource("/rip.properties").toString().contains("jar:")
File jarDirectory = Objects.requireNonNull(Utils.class.getResource("/rip.properties")).toString().contains("jar:")
? new File(System.getProperty("java.class.path")).getParentFile()
: new File(System.getProperty("user.dir"));
@@ -412,6 +411,7 @@ public class Utils {
if (directory != null && directory.exists()) {
// Get the list of the files contained in the package
String[] files = directory.list();
assert files != null;
for (String file : files) {
if (file.endsWith(".class") && !file.contains("$")) {
String className = pkgname + '.' + file.substring(0, file.length() - 6);
@@ -527,7 +527,7 @@ public class Utils {
if (!(file.isDirectory() && file.canWrite() && file.canExecute())) {
throw new IOException("Original directory \"" + file + "\" is no directory or not writeable.");
}
ArrayList<String> names = new ArrayList<>(Arrays.asList(file.list()));
ArrayList<String> names = new ArrayList<>(Arrays.asList(Objects.requireNonNull(file.list())));
for (String name : names) {
if (name.toLowerCase().equals(lastPart)) {
@@ -791,7 +791,7 @@ public class Utils {
public static String[] getSupportedLanguages() {
ArrayList<Path> filesList = new ArrayList<>();
try {
URI uri = Utils.class.getResource("/rip.properties").toURI();
URI uri = Objects.requireNonNull(Utils.class.getResource("/rip.properties")).toURI();
Path myPath;
if (uri.getScheme().equals("jar")) {
@@ -833,8 +833,7 @@ public class Utils {
* @param bytesCompleted How many bytes have been downloaded
* @param bytesTotal The total size of the file that is being
* downloaded
* @return Returns the formatted status text for rippers using the byte progress
* bar
* @return Returns the formatted status text for rippers using the byte progresbar
*/
public static String getByteStatusText(int completionPercentage, int bytesCompleted, int bytesTotal) {
return completionPercentage + "% - " + Utils.bytesToHumanReadable(bytesCompleted) + " / "