GitHub Viewer
package org.json.zip;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.Kim;
/*
Copyright (c) 2013 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* JSONzip is a compression scheme for JSON text.
*
* @author JSON.org
* @version 2013-04-18
*/
/**
* A compressor implements the compression behavior of JSONzip. It provides a
* zip method that takes a JSONObject or JSONArray and delivers a stream of
* bits to a BitWriter.
*
* FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY
* FOR PRODUCTION USE.
*/
public class Compressor extends JSONzip {
/**
* A compressor outputs to a BitWriter.
*/
final BitWriter bitwriter;
/**
* Create a new compressor. It may be used for an entire session or
* subsession.
*
* @param bitwriter
* The BitWriter this Compressor will output to. Don't forget to
* flush.
*/
public Compressor(BitWriter bitwriter) {
super();
this.bitwriter = bitwriter;
}
/**
* Return a 4 bit code for a character in a JSON number. The digits '0' to
* '9' get the codes 0 to 9. '.' is 10, '-' is 11, '+' is 12, and 'E' or
* 'e' is 13.
*
* @param digit
* An ASCII character from a JSIN number.
* @return
*/
private static int bcd(char digit) {
if (digit >= '0' && digit