mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 10:36:43 +00:00
Fixes #68 & Reformatted code
This commit is contained in:
parent
fd73a47796
commit
fe0be03ab8
@ -1,5 +1,7 @@
|
||||
package net.simon987.server.io;
|
||||
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -50,7 +52,7 @@ public class FileUtils {
|
||||
File file = directory.toFile();
|
||||
|
||||
//If the directory exists or the directory created successfully return true
|
||||
if(file.exists() || file.mkdir()) {
|
||||
if (file.exists() || file.mkdir()) {
|
||||
return true;
|
||||
|
||||
} else {
|
||||
@ -118,66 +120,62 @@ public class FileUtils {
|
||||
File[] files = new File(DIR_PATH.toString()).listFiles();
|
||||
File[] sorted = new File[size];
|
||||
|
||||
File nextSortedFile = null;
|
||||
File currentFile = null;
|
||||
boolean changed = false;
|
||||
File currentFile;
|
||||
boolean changed;
|
||||
|
||||
for(int i = 0; i < files.length / 2; i++) {
|
||||
if (files != null) {
|
||||
for (int i = 0; i < files.length / 2; i++) {
|
||||
currentFile = files[i];
|
||||
files[i] = files[files.length - i - 1];
|
||||
files[files.length - i - 1] = currentFile;
|
||||
}
|
||||
|
||||
currentFile = null;
|
||||
|
||||
for(int f = 0; f < files.length; f++) {
|
||||
for (int f = 0; f < files.length; f++) {
|
||||
changed = false;
|
||||
long dirFile = Long.parseLong(files[f].getName().substring(0, (files[f].getName().length() -4)));
|
||||
|
||||
if(f < size && sorted[f] == null) {
|
||||
try {
|
||||
long dirFile = Long.parseLong(files[f].getName().substring(0, (files[f].getName().length() - 4)));
|
||||
|
||||
if (f < size && sorted[f] == null) {
|
||||
sorted[f] = files[f];
|
||||
|
||||
} else {
|
||||
|
||||
for(int s = 0; s < sorted.length; s++) {
|
||||
for (int s = 0; s < sorted.length; s++) {
|
||||
|
||||
long sortedFile = Long.parseLong(sorted[s].getName().substring(0, (sorted[s].getName().length() -4)));
|
||||
long sortedFile = Long.parseLong(sorted[s].getName().substring(0, (sorted[s].getName().length() - 4)));
|
||||
|
||||
if(dirFile > sortedFile) {
|
||||
if (dirFile > sortedFile) {
|
||||
|
||||
if(s == sorted.length - 1) {
|
||||
sorted[s] = files[f];
|
||||
|
||||
} else if(nextSortedFile == null) {
|
||||
nextSortedFile = sorted[s];
|
||||
if (s == sorted.length - 1) {
|
||||
sorted[s] = files[f];
|
||||
|
||||
} else {
|
||||
currentFile = sorted[s];
|
||||
sorted[s] = nextSortedFile;
|
||||
nextSortedFile = currentFile;
|
||||
sorted[s] = files[f];
|
||||
}
|
||||
|
||||
nextSortedFile = null;
|
||||
currentFile = null;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(changed == false) {
|
||||
if (!changed) {
|
||||
files[f].delete();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
LogManager.LOGGER.info("Non-save file in history directory: " + files[f].getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte array into human readable format using the provided encoding
|
||||
*
|
||||
* @param bytes
|
||||
* data to be encoded to String
|
||||
* @param bytes data to be encoded to String
|
||||
* @return a String containing the encoded bytes
|
||||
*/
|
||||
public static String byteArrAsString(byte[] bytes) throws UnsupportedEncodingException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user