Updated various places that used File.separator when they could have used Paths.get()

This commit is contained in:
CalDescent 2021-12-22 15:57:40 +00:00
parent 67db0f950b
commit 87b724ec72
5 changed files with 11 additions and 11 deletions

View File

@ -40,7 +40,7 @@ public class HTMLParser {
for (Element element : href) { for (Element element : href) {
String elementHtml = element.attr("href"); String elementHtml = element.attr("href");
if (this.shouldReplaceLink(elementHtml)) { if (this.shouldReplaceLink(elementHtml)) {
String slash = (elementHtml.startsWith("/") ? "" : File.separator); String slash = (elementHtml.startsWith("/") ? "" : "/");
element.attr("href", this.linkPrefix + slash + element.attr("href")); element.attr("href", this.linkPrefix + slash + element.attr("href"));
} }
} }
@ -48,7 +48,7 @@ public class HTMLParser {
for (Element element : src) { for (Element element : src) {
String elementHtml = element.attr("src"); String elementHtml = element.attr("src");
if (this.shouldReplaceLink(elementHtml)) { if (this.shouldReplaceLink(elementHtml)) {
String slash = (elementHtml.startsWith("/") ? "" : File.separator); String slash = (elementHtml.startsWith("/") ? "" : "/");
element.attr("src", this.linkPrefix + slash + element.attr("src")); element.attr("src", this.linkPrefix + slash + element.attr("src"));
} }
} }
@ -60,7 +60,7 @@ public class HTMLParser {
ArrayList<String> newParts = new ArrayList<>(); ArrayList<String> newParts = new ArrayList<>();
for (String part : parts) { for (String part : parts) {
part = part.trim(); part = part.trim();
String slash = (elementHtml.startsWith("/") ? "" : File.separator); String slash = (elementHtml.startsWith("/") ? "" : "/");
String newPart = this.linkPrefix + slash + part; String newPart = this.linkPrefix + slash + part;
newParts.add(newPart); newParts.add(newPart);
} }

View File

@ -371,7 +371,7 @@ public class ArbitraryDataReader {
byte[] secret = this.secret58 != null ? Base58.decode(this.secret58) : null; byte[] secret = this.secret58 != null ? Base58.decode(this.secret58) : null;
if (secret != null && secret.length == Transformer.AES256_LENGTH) { if (secret != null && secret.length == Transformer.AES256_LENGTH) {
try { try {
Path unencryptedPath = Paths.get(this.workingPath.toString() + File.separator + "zipped.zip"); Path unencryptedPath = Paths.get(this.workingPath.toString(), "zipped.zip");
SecretKey aesKey = new SecretKeySpec(secret, 0, secret.length, "AES"); SecretKey aesKey = new SecretKeySpec(secret, 0, secret.length, "AES");
AES.decryptFile("AES", aesKey, this.filePath.toString(), unencryptedPath.toString()); AES.decryptFile("AES", aesKey, this.filePath.toString(), unencryptedPath.toString());

View File

@ -19,6 +19,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.NoSuchFileException; import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -88,7 +89,7 @@ public class ArbitraryDataRenderer {
try { try {
String filename = this.getFilename(unzippedPath, inPath); String filename = this.getFilename(unzippedPath, inPath);
String filePath = unzippedPath + File.separator + filename; String filePath = Paths.get(unzippedPath, filename).toString();
if (HTMLParser.isHtmlFile(filename)) { if (HTMLParser.isHtmlFile(filename)) {
// HTML file - needs to be parsed // HTML file - needs to be parsed
@ -136,8 +137,8 @@ public class ArbitraryDataRenderer {
// Locate index file // Locate index file
List<String> indexFiles = ArbitraryDataRenderer.indexFiles(); List<String> indexFiles = ArbitraryDataRenderer.indexFiles();
for (String indexFile : indexFiles) { for (String indexFile : indexFiles) {
String filePath = directory + File.separator + indexFile; Path path = Paths.get(directory, indexFile);
if (Files.exists(Paths.get(filePath))) { if (Files.exists(path)) {
return userPath + indexFile; return userPath + indexFile;
} }
} }

View File

@ -184,7 +184,7 @@ public class ArbitraryDataWriter {
private void compress() throws InterruptedException, DataException { private void compress() throws InterruptedException, DataException {
// Compress the data if requested // Compress the data if requested
if (this.compression != Compression.NONE) { if (this.compression != Compression.NONE) {
this.compressedPath = Paths.get(this.workingPath.toString() + File.separator + "data.zip"); this.compressedPath = Paths.get(this.workingPath.toString(), "data.zip");
try { try {
if (this.compression == Compression.ZIP) { if (this.compression == Compression.ZIP) {
@ -212,7 +212,7 @@ public class ArbitraryDataWriter {
} }
private void encrypt() throws DataException { private void encrypt() throws DataException {
this.encryptedPath = Paths.get(this.workingPath.toString() + File.separator + "data.zip.encrypted"); this.encryptedPath = Paths.get(this.workingPath.toString(), "data.zip.encrypted");
try { try {
// Encrypt the file with AES // Encrypt the file with AES
LOGGER.info("Encrypting..."); LOGGER.info("Encrypting...");

View File

@ -40,8 +40,7 @@ public class ResourceList {
/* Filesystem */ /* Filesystem */
private Path getFilePath() { private Path getFilePath() {
String pathString = String.format("%s%s%s.json", Settings.getInstance().getListsPath(), String pathString = String.format("%s.json", Paths.get(Settings.getInstance().getListsPath(), this.name));
File.separator, this.name);
return Paths.get(pathString); return Paths.get(pathString);
} }