-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add abstraction for reading and writing to account files with differe…
…nt formats
- Loading branch information
Showing
9 changed files
with
97 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[ | ||
{ | ||
"username": "test2", | ||
"homeDirectory": "C:\\Users\\wkacp\\Desktop" | ||
}, | ||
{ | ||
"username": "admin", | ||
"homeDirectory": "test", | ||
"hashedPassword": "7ee737c83ee689c96ef37d3a029068c390ebc8f8" | ||
}, | ||
{ | ||
"username": "admin2", | ||
"homeDirectory": "test", | ||
"hashedPassword": "7ee737c83ee689c96ef37d3a029068c390ebc8f8" | ||
}, | ||
{ | ||
"username": "admin3", | ||
"homeDirectory": "test", | ||
"hashedPassword": "7ee737c83ee689c96ef37d3a029068c390ebc8f8" | ||
}, | ||
{ | ||
"username": "sd", | ||
"homeDirectory": "" | ||
} | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
server/src/main/java/com/ftprx/server/account/AccountFileFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.ftprx.server.account; | ||
|
||
public enum AccountFileFormat { | ||
JSON | ||
} |
15 changes: 15 additions & 0 deletions
15
server/src/main/java/com/ftprx/server/account/AccountFileManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ftprx.server.account; | ||
|
||
import com.ftprx.server.account.Account; | ||
|
||
import java.io.Reader; | ||
import java.io.Writer; | ||
import java.util.List; | ||
|
||
/** | ||
* An interface for reading from and writing to a file containing account list. | ||
*/ | ||
public interface AccountFileManager { | ||
void write(Writer writer, List<Account> accounts); | ||
List<Account> read(Reader reader); | ||
} |
158 changes: 0 additions & 158 deletions
158
server/src/main/java/com/ftprx/server/account/FileAccountRepository.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
server/src/main/java/com/ftprx/server/account/JsonAccountFileManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ftprx.server.account; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import java.io.Reader; | ||
import java.io.Writer; | ||
import java.util.List; | ||
|
||
public class JsonAccountFileManager implements AccountFileManager { | ||
private final Gson gson; | ||
|
||
public JsonAccountFileManager() { | ||
this.gson = new GsonBuilder().setPrettyPrinting().create(); | ||
} | ||
|
||
@Override | ||
public void write(Writer writer, List<Account> accounts) { | ||
gson.toJson(accounts, writer); | ||
} | ||
|
||
@Override | ||
public List<Account> read(Reader reader) { | ||
return List.of(gson.fromJson(reader, Account[].class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters