Ignore:
Timestamp:
2013-04-07T17:07:27+02:00 (12 years ago)
Author:
akks
Message:

JOSM/ImageryCache: updated MapDB (no more deadlocks, Java 1.6 compatible), less crashes, multiple-JOSM support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagerycache/src/org/mapdb/CompressLZF.java

    r29363 r29484  
    5353import java.io.DataOutput;
    5454import java.io.IOException;
    55 import java.io.Serializable;
    5655import java.util.Arrays;
    5756
     
    297296        @Override
    298297        public void serialize(DataOutput out, byte[] value) throws IOException {
    299             if (value == null) return;
     298            if (value == null|| value.length==0){
     299                //in this case do not compress data, write 0 as indicator
     300                Utils.packInt(out, 0);
     301                out.write(value);
     302                return;
     303            }
    300304
    301305            CompressLZF lzf = LZF.get();
     
    341345     * Wraps existing serializer and compresses its input/output
    342346     */
    343     public static <E> Serializer<E> serializerCompressWrapper(Serializer<E> serializer) {
    344         return new SerializerCompressWrapper<E>(serializer);
    345     }
    346 
    347 
    348     protected static class SerializerCompressWrapper<E> implements Serializer<E>, Serializable {
    349         protected final Serializer<E> serializer;
    350         public SerializerCompressWrapper(Serializer<E> serializer) {
    351             this.serializer = serializer;
    352         }
    353 
    354         @Override
    355         public void serialize(DataOutput out, E value) throws IOException {
    356             //serialize to byte[]
    357             DataOutput2 out2 = new DataOutput2();
    358             serializer.serialize(out2, value);
    359             byte[] b = out2.copyBytes();
    360             CompressLZF.SERIALIZER.serialize(out, b);
    361         }
    362 
    363         @Override
    364         public E deserialize(DataInput in, int available) throws IOException {
    365             byte[] b = CompressLZF.SERIALIZER.deserialize(in, available);
    366             DataInput2 in2 = new DataInput2(b);
    367             return serializer.deserialize(in2, b.length);
    368         }
    369     }
     347    public static <E> Serializer<E> CompressionWrapper(Serializer<E> serializer) {
     348        return new Serializer.CompressSerializerWrapper<E>(serializer);
     349    }
     350
    370351
    371352}
Note: See TracChangeset for help on using the changeset viewer.