Tried to fix Metrics Output Stream issue

This commit is contained in:
alisolarflare 2016-11-26 18:51:27 -05:00
parent bdc467db30
commit 7e5b244585
2 changed files with 16 additions and 12 deletions

0
metrics/metrics.txt Normal file
View file

View file

@ -2,6 +2,7 @@ package alisolarflare.components.metrics.files;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
@ -17,33 +18,36 @@ public class MetricsFile {
this.fileName = directory; this.fileName = directory;
} }
public void AddLine(String string){ public void AddLine(String string){
BufferedWriter outputStream = null; BufferedWriter inputStream = null;
try { try {
outputStream = new BufferedWriter(new FileWriter(fileName, true)); File file = new File("metrics/playerLogins.txt");
outputStream.write(string); TBMCCoreAPI.sendDebugMessage("Metrics File Exists: " + file.exists());
outputStream.newLine(); inputStream = new BufferedWriter(new FileWriter(fileName, true));
outputStream.close(); TBMCCoreAPI.sendDebugMessage("Input Stream Created!");
inputStream.write(string);
inputStream.newLine();
inputStream.close();
} catch (IOException e) { } catch (IOException e) {
TBMCCoreAPI.SendException(fileName +" Output Stream could not be created!", e); TBMCCoreAPI.SendException(fileName +" Input Stream could not be created! ", e);
} }
} }
public List<String> toArrayList(){ public List<String> toArrayList(){
BufferedReader inputStream = null; BufferedReader outputStream = null;
try { try {
inputStream = new BufferedReader(new FileReader(fileName)); outputStream = new BufferedReader(new FileReader(fileName));
List<String> outputList = new ArrayList<String>(); List<String> outputList = new ArrayList<String>();
String currentLine; String currentLine;
while ((currentLine = inputStream.readLine()) != null){ while ((currentLine = outputStream.readLine()) != null){
outputList.add(currentLine); outputList.add(currentLine);
} }
inputStream.close(); outputStream.close();
return outputList; return outputList;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
TBMCCoreAPI.SendException(" could not be found", e); TBMCCoreAPI.SendException(fileName + " could not be found", e);
} catch (IOException e1) { } catch (IOException e1) {
TBMCCoreAPI.SendException("encountered an I/O Exception!", e1); TBMCCoreAPI.SendException(fileName + "encountered an I/O Exception!", e1);
} }
return new ArrayList<String>(); return new ArrayList<String>();
} }