File: MemoryMappingExample.java

package info (click to toggle)
libjavaewah-java 1.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,168 kB
  • sloc: java: 14,577; xml: 169; sh: 11; makefile: 3
file content (26 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import com.googlecode.javaewah.EWAHCompressedBitmap;
import java.io.*;
import java.nio.*;
import java.nio.channels.FileChannel;


public class MemoryMappingExample {
    
    public static void main(String[] args) throws IOException {
        File tmpfile = File.createTempFile("javaewah", "bin");
        tmpfile.deleteOnExit();
        final FileOutputStream fos = new FileOutputStream(tmpfile);
        EWAHCompressedBitmap ewahBitmap = EWAHCompressedBitmap.bitmapOf(0, 2, 55,
                                64, 1 << 30);
        System.out.println("Created the bitmap "+ewahBitmap);
        ewahBitmap.serialize(new DataOutputStream(fos));
        long totalcount = fos.getChannel().position();
        System.out.println("Serialized total count = "+totalcount+" bytes");
        fos.close();
        RandomAccessFile memoryMappedFile = new RandomAccessFile(tmpfile, "r");
        ByteBuffer bb = memoryMappedFile.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, totalcount);
        EWAHCompressedBitmap mapped = new EWAHCompressedBitmap(bb);
        System.out.println("Mapped the bitmap "+mapped);
        memoryMappedFile.close();
    }
}