Skip to content

Commit

Permalink
add file reader
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenBloodDev committed Dec 7, 2023
1 parent 19d5541 commit 55883e0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ bin/

/API
/logs
/src/main/java/test
/src/main/java/test
9 changes: 9 additions & 0 deletions src/main/java/pl/nightdev701/OpenAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pl.nightdev701.database.DatabaseConnector;
import pl.nightdev701.database.formular.DatabaseFormular;
import pl.nightdev701.database.type.DatabaseType;
import pl.nightdev701.io.ScorpionFileReader;
import pl.nightdev701.key.UniqueValueKey;
import pl.nightdev701.key.ValueKey;
import pl.nightdev701.logger.AbstractLogger;
Expand Down Expand Up @@ -64,6 +65,14 @@ public static DatabaseConnector getDatabaseManager(DatabaseFormular formular, Da
return getDatabaseManager(formular, type, port, new DefaultLogger());
}

public static ScorpionFileReader getFileReader(String path, AbstractLogger logger){
return new ScorpionFileReader(path, logger);
}

public static ScorpionFileReader getFileReader(String path){
return getFileReader(path, new DefaultLogger());
}

/**
* manage database connections and command easy with logger implementation
*
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/pl/nightdev701/io/ScorpionFileReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package pl.nightdev701.io;

import pl.nightdev701.logger.AbstractLogger;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;

public class ScorpionFileReader {

private BufferedReader bufferedReader;
private String currentLine;
private AbstractLogger logger;

public ScorpionFileReader(String filePath, AbstractLogger logger) {

this.logger = logger;

try {
FileReader fileReader = new FileReader(filePath);
bufferedReader = new BufferedReader(fileReader);
currentLine = bufferedReader.readLine(); // Lese die erste Zeile
} catch (FileNotFoundException e) {
logger.log(Level.WARNING,"Die Datei wurde nicht gefunden: " + e.getMessage());
} catch (IOException e) {
logger.log(Level.WARNING,"Fehler beim Lesen der Datei: " + e.getMessage());
}
}

public String getCurrentLine() {
return currentLine;
}

public void readNextLine() {
try {
currentLine = bufferedReader.readLine(); // Gehe zur nächsten Zeile
} catch (IOException e) {
logger.log(Level.WARNING,"Fehler beim Lesen der nächsten Zeile: " + e.getMessage());
}
}

public void close() {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e) {
logger.log(Level.WARNING,"Fehler beim Schließen des Readers: " + e.getMessage());
}
}

}

0 comments on commit 55883e0

Please sign in to comment.