Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.mapdb;
 
 import org.junit.Test;
 
 import java.io.*;
 import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
 
public class Issue183Test {
    @Test
    public void main(){
        File f = UtilsTest.tempDbFile();
        Map<StringStringmap1;
        TxMaker txMaker = DBMaker
                .newFileDB(f)
                .closeOnJvmShutdown()
                .cacheDisable()
                .makeTxMaker();
        DB db = txMaker.makeTx();
        map1 = db.createTreeMap("map1")
                .valueSerializer(new StringSerializer())
                .makeOrGet();
        map1.put("foo""bar");
        db.commit();
        db.close();
        txMaker.close();
        txMaker = DBMaker
                .newFileDB(f)
                .closeOnJvmShutdown()
                .cacheDisable()
                .makeTxMaker();
        db = txMaker.makeTx();
        map1 = db.createTreeMap("map1")
                .valueSerializer(new StringSerializer())
                .makeOrGet();
        assertEquals("bar"map1.get("foo"));
        map1.put("foo2""bar2");
        db.commit();
        db.close();
        txMaker.close();
    }
    private static final class StringSerializer implements Serializer<String>, Serializable {
        private static final long serialVersionUID = -8356516782418439492L;
        @Override
        public void serialize(DataOutput outString valuethrows IOException {
            out.writeUTF(value);
        }
        @Override
        public String deserialize(DataInput inint availablethrows IOException {
            return in.readUTF();
        }
        @Override
        public int fixedSize() {
            return -1;
        }
    }
New to GrepCode? Check out our FAQ X