Code smell reduction (#2554)

* Correct use of <> diamond operator

* Correct modifiers order

* Private constructor for utility class

* Correct use of diamond operator

* Corrected naming convention

* Correct modifier order

* Use not synchronized class

* Introduced try/resource in stream copy

* Removed unused private field

* Code reformat

Reformat of IOUtils.copy from to stream

* Add a space

Improved code formatting

* Code reformat

Only a new space

* Code reformat

Removed extra spaces
This commit is contained in:
Matteo Baccan 2021-04-14 12:31:32 +02:00 committed by GitHub
parent baf8bb592a
commit b3741409f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 24 deletions

View File

@ -44,7 +44,7 @@ public abstract class AbstractDirectory implements Directory {
return mFiles;
}
if (mFilesRecursive == null) {
mFilesRecursive = new LinkedHashSet<String>(mFiles);
mFilesRecursive = new LinkedHashSet<>(mFiles);
for (Map.Entry<String, ? extends Directory> dir : getAbstractDirs().entrySet()) {
for (String path : dir.getValue().getFiles(true)) {
mFilesRecursive.add(dir.getKey() + separator + path);
@ -93,7 +93,7 @@ public abstract class AbstractDirectory implements Directory {
@Override
public Map<String, Directory> getDirs(boolean recursive)
throws UnsupportedOperationException {
return new LinkedHashMap<String, Directory>(getAbstractDirs(recursive));
return new LinkedHashMap<>(getAbstractDirs(recursive));
}
@Override
@ -225,7 +225,7 @@ public abstract class AbstractDirectory implements Directory {
return mDirs;
}
Map<String, AbstractDirectory> dirs = new LinkedHashMap<String, AbstractDirectory>(mDirs);
Map<String, AbstractDirectory> dirs = new LinkedHashMap<>(mDirs);
for (Map.Entry<String, AbstractDirectory> dir : getAbstractDirs().entrySet()) {
for (Map.Entry<String, AbstractDirectory> subdir : dir.getValue().getAbstractDirs(
true).entrySet()) {
@ -260,15 +260,15 @@ public abstract class AbstractDirectory implements Directory {
return new ParsedPath(path.substring(0, pos), path.substring(pos + 1));
}
abstract protected void loadFiles();
abstract protected void loadDirs();
abstract protected InputStream getFileInputLocal(String name)
protected abstract void loadFiles();
protected abstract void loadDirs();
protected abstract InputStream getFileInputLocal(String name)
throws DirectoryException;
abstract protected OutputStream getFileOutputLocal(String name)
protected abstract OutputStream getFileOutputLocal(String name)
throws DirectoryException;
abstract protected AbstractDirectory createDirLocal(String name)
protected abstract AbstractDirectory createDirLocal(String name)
throws DirectoryException;
abstract protected void removeFileLocal(String name);
protected abstract void removeFileLocal(String name);
private class ParsedPath {

View File

@ -28,6 +28,10 @@ import java.util.logging.Logger;
public class DirUtil {
private static final Logger LOGGER = Logger.getLogger("");
private DirUtil() {
// Private constructor for utility class
}
public static void copyToDir(Directory in, Directory out)
throws DirectoryException {
for (String fileName : in.getFiles(true)) {

View File

@ -30,6 +30,10 @@ import java.util.zip.ZipOutputStream;
public class ZipUtils {
private static Collection<String> mDoNotCompress;
private ZipUtils() {
// Private constructor for utility class
}
public static void zipFolders(final File folder, final File zip, final File assets, final Collection<String> doNotCompress)
throws BrutException, IOException {

View File

@ -19,7 +19,7 @@ package brut.util;
import java.io.DataInput;
import java.io.IOException;
abstract public class DataInputDelegate implements DataInput {
public abstract class DataInputDelegate implements DataInput {
protected final DataInput mDelegate;
public DataInputDelegate(DataInput delegate) {

View File

@ -21,14 +21,11 @@ import org.apache.commons.io.IOUtils;
import java.io.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
abstract public class Jar {
private final static Set<String> mLoaded = new HashSet<String>();
private final static Map<String, File> mExtracted = new HashMap<String, File>();
public abstract class Jar {
private static final Map<String, File> mExtracted = new HashMap<>();
public static File getResourceAsFile(String name, Class clazz) throws BrutException {
File file = mExtracted.get(name);

View File

@ -72,11 +72,11 @@ public class OS {
continue;
}
try {
InputStream in = new FileInputStream(file);
OutputStream out = new FileOutputStream(destFile);
IOUtils.copy(in, out);
in.close();
out.close();
try (InputStream in = new FileInputStream(file)) {
try (OutputStream out = new FileOutputStream(destFile)) {
IOUtils.copy(in, out);
}
}
} catch (IOException ex) {
throw new BrutException("Could not copy file: " + file, ex);
}
@ -173,7 +173,7 @@ public class OS {
}
static class StreamCollector implements Runnable {
private final StringBuffer buffer = new StringBuffer();
private final StringBuilder buffer = new StringBuilder();
private final InputStream inputStream;
public StreamCollector(InputStream inputStream) {

View File

@ -17,8 +17,8 @@
package brut.util;
public class OSDetection {
private static String OS = System.getProperty("os.name").toLowerCase();
private static String Bit = System.getProperty("sun.arch.data.model").toLowerCase();
private static final String OS = System.getProperty("os.name").toLowerCase();
private static final String BIT = System.getProperty("sun.arch.data.model").toLowerCase();
public static boolean isWindows() {
return (OS.contains("win"));
@ -39,7 +39,7 @@ public class OSDetection {
return arch != null && arch.endsWith("64") || wow64Arch != null && wow64Arch.endsWith("64");
}
return Bit.equalsIgnoreCase("64");
return BIT.equalsIgnoreCase("64");
}
public static String returnOS() {