Skip to content

Commit

Permalink
Added 'Node' class
Browse files Browse the repository at this point in the history
  • Loading branch information
joemirizio committed Apr 18, 2012
1 parent 5b0fa2f commit 92fe17d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Node.java
@@ -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(); }
}
}

0 comments on commit 92fe17d

Please sign in to comment.