FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

package org.json.zip; 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 binary compression scheme for JSON text. * * @author JSON.org * @version 2014-05-03 */ /** * An encoder 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 Zipper extends JSONzip { /** * An encoder outputs to a BitWriter. */ final BitWriter bitwriter; /** * Create a new encoder. It may be used for an entire session or * subsession. * * @param bitwriter * The BitWriter this encoder will output to. * Don't forget to flush. */ public Zipper(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 JSON number. * @return The number code. */ private static int bcd(char digit) { if (digit >= '0' && digit = 0 && longer < int14) { write(0, 2); if (longer < int4) { zero(); write((int) longer, 4); return; } one(); if (longer < int7) { zero(); write((int)(longer - int4), 7); return; } one(); write((int)(longer - int7), 14); return; } } write(1, 2); for (int i = 0; i < string.length(); i += 1) { write(bcd(string.charAt(i)), 4); } write(endOfNumber, 4); this.valuekeep.register(string); } else { write(3, 2); writeJSON(value); } } /** * Output a zero bit. * * @throws JSONException */ private void zero() throws JSONException { write(0, 1); } /** * Encode a JSONObject. * * @param jsonobject The JSONObject. * @throws JSONException */ public void encode(JSONObject jsonobject) throws JSONException { generate(); writeJSON(jsonobject); } /** * Encode a JSONArray. * * @param jsonarray The JSONArray. * @throws JSONException */ public void encode(JSONArray jsonarray) throws JSONException { generate(); writeJSON(jsonarray); } }

Back | FazBrowse Home | New Git URL