Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b0fa2f
commit 92fe17d
Showing
1 changed file
with
47 additions
and
0 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,47 @@ | ||
import java.io.ObjectInputStream; | ||
import java.io.FileInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.HashMap; | ||
|
||
public class Node implements Serializable { | ||
|
||
private static final FILENAME = "data"; | ||
|
||
protected HashMap<Integer, MusicObject> data; | ||
|
||
|
||
public Node() { | ||
this.data = new HashMap<Integer, MusicObject>(); | ||
} | ||
|
||
public void addMusicObject(MusicObject song) { | ||
this.data.put(song.getId(), song); | ||
} | ||
|
||
protected void writeToFile() { | ||
try { | ||
FileOutputStream fos = new FileOutputStream(FILENAME); | ||
ObjectOutputStream oos = new ObjectOutputStream(fos); | ||
|
||
oos.write(this.data); | ||
|
||
oos.close(); | ||
fos.close(); | ||
} catch (IOException e) { e.printStackTrace(); } | ||
} | ||
|
||
protected void readFromFile() { | ||
try { | ||
FileInputStreaInputStream fis = new FileInputStream(FILENAME); | ||
ObjectInputStream ois = new ObjectInputStream(fis); | ||
|
||
this.data = (HashMap<Integer, MusicObject>)ois.read(data); | ||
|
||
oos.close(); | ||
fos.close(); | ||
} catch (IOException e) { e.printStackTrace(); } | ||
} | ||
} |