iRiver: The audio init fix caused problems if a voice file was present.
[kugel-rb.git] / songdbj / RuntimeDatabase.java
blobe96e8207cced0a48ec524866e0b66d99ec35b815
1 import java.util.*;
2 import java.io.*;
3 import java.lang.reflect.Array;
5 /*
6 TreeSet for runtimedatabase with entry hash used in compareto
7 fix commandline interface.
8 */
10 public class RuntimeDatabase {
11 protected static RuntimeDatabase instance=null;
12 protected TreeMap entries;
13 protected int entrycount;
14 public static final int headersize = 8;
16 protected RuntimeDatabase() {
17 entries=new TreeMap();
20 public static RuntimeDatabase getInstance() {
21 if(instance==null)
22 instance=new RuntimeDatabase();
23 return instance;
26 public RundbEntry getEntry(FileEntry file) {
27 Integer key = new Integer(file.getHash());
28 if(!entries.containsKey(key)) {
29 RundbEntry e = new RundbEntry(file);
30 entries.put(key,e);
31 return e;
33 else
34 return (RundbEntry)entries.get(key);
37 protected void calcOffsets() {
38 Collection values = entries.values();
39 Iterator i;
40 int offset=headersize;
41 i=values.iterator();
42 while(i.hasNext()) {
43 Entry e = (Entry) i.next();
44 e.setOffset(offset);
45 offset+=RundbEntry.entrySize();
47 entrycount=values.size();
50 public int isDirty() {
51 return 0;
54 protected void writeHeader(DataOutputStream w) throws IOException {
55 w.write('R');
56 w.write('R');
57 w.write('D');
58 w.write(0x1);
59 w.writeInt(entrycount);
62 public void prepareWrite() {
63 System.out.println("Calculating Runtime Database Offsets..");
64 calcOffsets();
67 public void writeDatabase(File f) throws IOException {
68 int x;
69 Iterator i;
70 DataOutputStream w = new DataOutputStream(new FileOutputStream(f));
71 System.out.println("Writing runtime database..");
72 writeHeader(w);
73 i=entries.values().iterator();
74 while(i.hasNext()) {
75 Entry e = (Entry) i.next();
76 e.write(w);
78 w.flush();
79 w.close();