From 4c2fca64579061c9cd635a53065b055b78a2b89f Mon Sep 17 00:00:00 2001
From: Pieter12345
Date: Thu, 21 Mar 2019 23:35:43 +0100
Subject: [PATCH] Replace some FileUtils calls with direct methods
Not wrapping these calls in FileUtils methods makes the code cleaner and easier to understand (FileUtils is very poorly documented, whereas direct calls contain proper documentation).
---
app/src/processing/app/Base.java | 11 ++---------
.../packages/uploaders/MergeSketchWithBooloader.java | 8 ++++----
arduino-core/src/processing/app/BaseNoGui.java | 6 +++---
3 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java
index 8544e6c41..ef4d9b30a 100644
--- a/app/src/processing/app/Base.java
+++ b/app/src/processing/app/Base.java
@@ -1691,19 +1691,12 @@ public class Base {
});
boolean ifound = false;
-
for (File subfolder : files) {
- if (FileUtils.isSCCSOrHiddenFile(subfolder)) {
- continue;
- }
-
- if (!subfolder.isDirectory()) continue;
-
- if (addSketchesSubmenu(menu, subfolder.getName(), subfolder)) {
+ if (!FileUtils.isSCCSOrHiddenFile(subfolder) && subfolder.isDirectory()
+ && addSketchesSubmenu(menu, subfolder.getName(), subfolder)) {
ifound = true;
}
}
-
return ifound;
}
diff --git a/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java b/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
index a6f34b265..bbab2bd7b 100644
--- a/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
+++ b/arduino-core/src/cc/arduino/packages/uploaders/MergeSketchWithBooloader.java
@@ -29,19 +29,19 @@
package cc.arduino.packages.uploaders;
-import processing.app.helpers.FileUtils;
-
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.List;
public class MergeSketchWithBooloader {
public void merge(File sketch, File bootloader) throws IOException {
- List mergedSketch = FileUtils.readFileToListOfStrings(sketch);
+ List mergedSketch = Files.readAllLines(sketch.toPath(), StandardCharsets.UTF_8);
mergedSketch.remove(mergedSketch.size() - 1);
- mergedSketch.addAll(FileUtils.readFileToListOfStrings(bootloader));
+ mergedSketch.addAll(Files.readAllLines(bootloader.toPath(), StandardCharsets.UTF_8));
FileWriter writer = null;
try {
diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java
index 67d3cef69..6f14eff27 100644
--- a/arduino-core/src/processing/app/BaseNoGui.java
+++ b/arduino-core/src/processing/app/BaseNoGui.java
@@ -485,8 +485,8 @@ public class BaseNoGui {
} catch (JsonProcessingException | SignatureVerificationFailedException e) {
File indexFile = indexer.getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
File indexSignatureFile = indexer.getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME + ".sig");
- FileUtils.deleteIfExists(indexFile);
- FileUtils.deleteIfExists(indexSignatureFile);
+ indexFile.delete();
+ indexSignatureFile.delete();
throw e;
}
indexer.syncWithFilesystem();
@@ -502,7 +502,7 @@ public class BaseNoGui {
librariesIndexer.parseIndex();
} catch (JsonProcessingException e) {
File librariesIndexFile = librariesIndexer.getIndexFile();
- FileUtils.deleteIfExists(librariesIndexFile);
+ librariesIndexFile.delete();
}
if (discoveryManager == null) {