diff --git a/zip/Compressor.java b/zip/Compressor.java index 07fb691..5937d66 100644 --- a/zip/Compressor.java +++ b/zip/Compressor.java @@ -38,7 +38,7 @@ import org.json.Kim; * JSONzip is a compression scheme for JSON text. * * @author JSON.org - * @version 2014-04-21 + * @version 2014-04-28 */ /** @@ -75,7 +75,7 @@ public class Compressor extends JSONzip { * 'e' is 13. * * @param digit - * An ASCII character from a JSIN number. + * An ASCII character from a JSON number. * @return */ private static int bcd(char digit) { @@ -514,11 +514,11 @@ public class Compressor extends JSONzip { one(); if (longer < int7) { zero(); - write((int) longer, 7); + write((int)(longer - int4), 7); return; } one(); - write((int) longer, 14); + write((int)(longer - int7), 14); return; } } diff --git a/zip/Decompressor.java b/zip/Decompressor.java index df130ae..091ec54 100644 --- a/zip/Decompressor.java +++ b/zip/Decompressor.java @@ -35,7 +35,7 @@ import org.json.Kim; * JSONzip is a compression scheme for JSON text. * * @author JSON.org - * @version 2014-04-21 + * @version 2014-04-28 */ public class Decompressor extends JSONzip { @@ -288,7 +288,17 @@ public class Decompressor extends JSONzip { private Object readValue() throws JSONException { switch (read(2)) { case 0: - return new Integer(read(!bit() ? 4 : !bit() ? 7 : 14)); + int nr_bits = !bit() ? 4 : !bit() ? 7 : 14; + int integer = read(nr_bits); + switch (nr_bits) { + case 7: + integer += int4; + break; + case 14: + integer += int7; + break; + } + return new Integer(integer); case 1: byte[] bytes = new byte[256]; int length = 0; diff --git a/zip/JSONzip.java b/zip/JSONzip.java index 10cb181..a8b837f 100644 --- a/zip/JSONzip.java +++ b/zip/JSONzip.java @@ -44,7 +44,7 @@ package org.json.zip; * ADEQUATELY FOR PRODUCTION USE. * * @author JSON.org - * @version 2014-04-21 + * @version 2014-04-28 */ public abstract class JSONzip implements None, PostMortem { /** @@ -63,19 +63,19 @@ public abstract class JSONzip implements None, PostMortem { }; /** - * The number of integers that can be encoded in 4 bits. + * The first positive integer than cannot be encoded in 4 bits. */ public static final long int4 = 16; /** - * The number of integers that can be encoded in 7 bits. + * The first positive integer than cannot be encoded in 7 bits. */ - public static final long int7 = 128; + public static final long int7 = 144; /** - * The number of integers that can be encoded in 14 bits. + * The first positive integer than cannot be encoded in 14 bits. */ - public static final long int14 = 16384; + public static final long int14 = 16528; /** * The end of string code.