Package org.fusesource.hawtdb.internal.io

Examples of org.fusesource.hawtdb.internal.io.MemoryMappedFile


    @org.junit.Test
    public void basicOps() throws IOException {
        File file = new File("target/foo.data");
        file.delete();

        MemoryMappedFile mmf = new MemoryMappedFile(file, 1024*1024*100, false);
       
        int PAGE_SIZE = 1024*4;
        int LAST_PAGE = 100;
       
        byte expect[] = createData(PAGE_SIZE);
       
        mmf.write(0, expect);
        mmf.write(LAST_PAGE *PAGE_SIZE, expect);
       
        // Validate data on the first page.
        byte actual[] = new byte[PAGE_SIZE];
        mmf.read(0, actual);
        Assert.assertEquals('a', actual[0]);
        Assert.assertEquals('a', actual[26]);
        Assert.assertEquals('z', actual[26+25]);

        // Validate data on the 3rd page.
        actual = new byte[PAGE_SIZE];
        mmf.read(PAGE_SIZE*LAST_PAGE, actual);
        Assert.assertEquals('a', actual[0]);
        Assert.assertEquals('a', actual[26]);
        Assert.assertEquals('z', actual[26+25]);

        mmf.sync();
        mmf.close();

    }
View Full Code Here

TOP

Related Classes of org.fusesource.hawtdb.internal.io.MemoryMappedFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.