Changeset 29484 in osm for applications/editors/josm/plugins/imagerycache/src/org/mapdb/CompressLZF.java
- Timestamp:
- 2013-04-07T17:07:27+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagerycache/src/org/mapdb/CompressLZF.java
r29363 r29484 53 53 import java.io.DataOutput; 54 54 import java.io.IOException; 55 import java.io.Serializable;56 55 import java.util.Arrays; 57 56 … … 297 296 @Override 298 297 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 } 300 304 301 305 CompressLZF lzf = LZF.get(); … … 341 345 * Wraps existing serializer and compresses its input/output 342 346 */ 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 370 351 371 352 }
Note:
See TracChangeset
for help on using the changeset viewer.