Fixes #68 & Reformatted code

This commit is contained in:
simon 2017-12-30 10:35:56 -05:00
parent fd73a47796
commit fe0be03ab8

View File

@ -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;
@ -118,20 +120,20 @@ 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;
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++) {
changed = false;
try {
long dirFile = Long.parseLong(files[f].getName().substring(0, (files[f].getName().length() - 4)));
if (f < size && sorted[f] == null) {
@ -148,36 +150,32 @@ public class FileUtils {
if (s == sorted.length - 1) {
sorted[s] = files[f];
} else if(nextSortedFile == null) {
nextSortedFile = sorted[s];
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 {