Browse Source

Implements Serialization Logic for Credentials

feature-serializer
fdai5728 3 years ago
parent
commit
c017222eb9
  1. 4
      src/main/java/Credential.java
  2. 4
      src/main/java/CredentialList.java
  3. 8
      src/main/java/CredentialRepository.java

4
src/main/java/Credential.java

@ -1,4 +1,6 @@
public class Credential {
import java.io.Serializable;
public class Credential implements Serializable {
private String name, password; private String name, password;
private int id; private int id;

4
src/main/java/CredentialList.java

@ -0,0 +1,4 @@
import java.io.Serializable;
import java.util.ArrayList;
public class CredentialList extends ArrayList<Credential> implements Serializable{}

8
src/main/java/CredentialRepository.java

@ -1,8 +1,5 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.util.ArrayList;
/** /**
* Credential Repository for handling user credentials * Credential Repository for handling user credentials
@ -12,7 +9,7 @@ import java.util.ArrayList;
public class CredentialRepository implements CredentialRepositoryInterface{ public class CredentialRepository implements CredentialRepositoryInterface{
private int idCounter = 0; private int idCounter = 0;
private ArrayList<Credential> credentials;
private CredentialList credentials;
/** /**
* Konstruktor * Konstruktor
@ -21,7 +18,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{
*/ */
public CredentialRepository() public CredentialRepository()
{ {
this.credentials = new ArrayList<Credential>();
this.credentials = new CredentialList();
} }
@ -147,6 +144,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{
out.writeObject(this.credentials); out.writeObject(this.credentials);
} catch (Exception fail) { } catch (Exception fail) {
System.err.println("Serialization failed!"); System.err.println("Serialization failed!");
fail.printStackTrace();
} }
} }

Loading…
Cancel
Save