root / trunk / libraries / libGDBMS / src / com / hardcode / gdbms / engine / data / indexes / FixedDiskIndexSet.java @ 466
History | View | Annotate | Download (2.11 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
package com.hardcode.gdbms.engine.data.indexes; |
3 |
|
4 |
import java.io.File; |
5 |
import java.io.FileInputStream; |
6 |
import java.io.FileOutputStream; |
7 |
import java.io.IOException; |
8 |
|
9 |
|
10 |
/**
|
11 |
* Implementaci?n de FixedIndexSet que escribe los ?ndices en un fichero
|
12 |
*
|
13 |
* @author Fernando Gonz?lez Cort?s
|
14 |
*/
|
15 |
public class FixedDiskIndexSet extends DiskIndexSet implements FixedIndexSet{ |
16 |
private long size = 0; |
17 |
|
18 |
public FixedDiskIndexSet(long size) { |
19 |
this.size = size;
|
20 |
} |
21 |
|
22 |
/**
|
23 |
* @see com.hardcode.gdbms.engine.data.indexes.VariableIndexSet#getIndex(long)
|
24 |
*/
|
25 |
public long getIndex(long nth) throws IOException { |
26 |
buffer.clear(); |
27 |
inputChannel.read(buffer, nth * 8);
|
28 |
buffer.flip(); |
29 |
|
30 |
return buffer.getLong();
|
31 |
} |
32 |
|
33 |
/**
|
34 |
* @see com.hardcode.gdbms.engine.data.indexes.VariableIndexSet#getIndexCount()
|
35 |
*/
|
36 |
public long getIndexCount() { |
37 |
return size;
|
38 |
} |
39 |
|
40 |
/**
|
41 |
* @see com.hardcode.gdbms.engine.data.indexes.VariableIndexSet#open(java.io.File)
|
42 |
*/
|
43 |
public void open(File f) throws IOException { |
44 |
file = f; |
45 |
fos = new FileOutputStream(f); |
46 |
outputChannel = fos.getChannel(); |
47 |
fis = new FileInputStream(file); |
48 |
inputChannel = fis.getChannel(); |
49 |
} |
50 |
|
51 |
/**
|
52 |
* @see com.hardcode.gdbms.engine.data.indexes.VariableIndexSet#close()
|
53 |
*/
|
54 |
public void close() throws IOException { |
55 |
inputChannel.close(); |
56 |
fis.close(); |
57 |
outputChannel.close(); |
58 |
fos.close(); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* @see com.hardcode.gdbms.engine.data.indexes.FixedIndexSet#setIndex(long, long)
|
63 |
*/
|
64 |
public void setIndex(long index, long value) throws IOException { |
65 |
buffer.put((byte) (index >>> 56)); |
66 |
buffer.put((byte) (index >>> 48)); |
67 |
buffer.put((byte) (index >>> 40)); |
68 |
buffer.put((byte) (index >>> 32)); |
69 |
buffer.put((byte) (index >>> 24)); |
70 |
buffer.put((byte) (index >>> 16)); |
71 |
buffer.put((byte) (index >>> 8)); |
72 |
buffer.put((byte) (index >>> 0)); |
73 |
|
74 |
buffer.flip(); |
75 |
|
76 |
outputChannel.write(buffer, index*8);
|
77 |
|
78 |
buffer.clear(); |
79 |
|
80 |
size++; |
81 |
|
82 |
} |
83 |
} |