drtshock loves formatting, so I may as well

This commit is contained in:
gomeow
2013-04-12 10:54:25 -07:00
parent 678f61127e
commit 03a7b52a8e
22 changed files with 677 additions and 793 deletions
@@ -46,7 +46,7 @@ public class Listeners implements Listener {
VaultViewInfo info = Commands.inVault.get(p.getName());
try {
vm.saveVault(inv, info.getHolder(), info.getNumber());
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace();
}
Commands.inVault.remove(p.getName());
@@ -127,7 +127,7 @@ public class Listeners implements Listener {
public void onInteractEntity(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
EntityType type = event.getRightClicked().getType();
if((type == EntityType.VILLAGER||type==EntityType.MINECART) && Commands.inVault.containsKey(player.getName())) {
if((type == EntityType.VILLAGER || type == EntityType.MINECART) && Commands.inVault.containsKey(player.getName())) {
event.setCancelled(true);
}
}
@@ -46,7 +46,7 @@ public class Main extends JavaPlugin {
update = true;
name = u.getNewVersion();
}
} catch (Exception e) {
} catch(Exception e) {
log.log(Level.WARNING, "PlayerVaults: Failed to check for updates.");
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
e.printStackTrace();
@@ -72,7 +72,7 @@ public class Main extends JavaPlugin {
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace();
}
}
@@ -119,7 +119,7 @@ public class Main extends JavaPlugin {
setInConfig("drop-on-death.inventories", dropInvs, conf);
try {
conf.save(configFile);
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace();
}
}
@@ -141,7 +141,7 @@ public class Main extends JavaPlugin {
Lang.setFile(defConfig);
return defConfig;
}
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace(); // So they notice
log.severe("[PlayerVaults] Couldn't create language file.");
log.severe("[PlayerVaults] This is a fatal error. Now disabling");
@@ -57,7 +57,7 @@ public class Commands implements CommandExecutor {
if(sender.hasPermission("playervaults.workbench")) {
if(sender instanceof Player) {
Inventory workbench = Bukkit.createInventory(null, InventoryType.WORKBENCH);
((Player)sender).openInventory(workbench);
((Player) sender).openInventory(workbench);
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_WORKBENCH);
} else {
sender.sendMessage(Lang.TITLE.toString() + Lang.PLAYER_ONLY);
@@ -4,12 +4,11 @@ import org.bukkit.command.CommandSender;
import com.drtshock.playervaults.util.Lang;
public class Feedback {
public enum Type {
OPEN,
DELETE,
WORKBENCH, //For later versions
WORKBENCH, // For later versions
FURNACE;
}
@@ -16,10 +16,9 @@ public class VaultOperations {
private static Main plugin;
private static VaultManager vm = new VaultManager(plugin);
public static boolean checkPerms(CommandSender cs, int number) {
if(cs.hasPermission("playervaults.amount." + String.valueOf(number))) return true;
for(int x = number; x <= 99;x++) {
for(int x = number; x <= 99; x++) {
if(cs.hasPermission("playervaults.amount." + String.valueOf(x))) return true;
}
return false;
@@ -39,8 +38,7 @@ public class VaultOperations {
number = Integer.parseInt(arg);
if(number == 0)
return false;
}
catch(NumberFormatException nfe) {
} catch(NumberFormatException nfe) {
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
return false;
}
@@ -78,8 +76,7 @@ public class VaultOperations {
number = Integer.parseInt(arg);
if(number == 0)
return false;
}
catch(NumberFormatException nfe) {
} catch(NumberFormatException nfe) {
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
}
vm.loadVault(sender, user, number);
@@ -109,8 +106,7 @@ public class VaultOperations {
if(number == 0)
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
return;
}
catch(NumberFormatException nfe) {
} catch(NumberFormatException nfe) {
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
}
try {
@@ -118,11 +114,11 @@ public class VaultOperations {
vm.deleteVault(sender, sender.getName(), number);
return;
}
} catch (IOException e) {
} catch(IOException e) {
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
}
} else {
sender.sendMessage(Lang.TITLE.toString()+ Lang.MUST_BE_NUMBER);
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
}
}
@@ -143,13 +139,12 @@ public class VaultOperations {
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
return;
}
}
catch(NumberFormatException nfe) {
} catch(NumberFormatException nfe) {
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
}
try {
vm.deleteVault(sender, user, number);
} catch (IOException e) {
} catch(IOException e) {
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
}
} else {
@@ -10,6 +10,7 @@ import com.drtshock.playervaults.Main;
public class DropOnDeath {
public static Main plugin;
public DropOnDeath(Main instance) {
DropOnDeath.plugin = instance;
}
@@ -26,7 +27,7 @@ public class DropOnDeath {
for(int count = 1; count <= Main.inventoriesToDrop; count++) {
Inventory inv = vm.getVault(player, count);
ItemStack[] stack = inv.getContents();
for(ItemStack is : stack) {
for(ItemStack is:stack) {
loc.getWorld().dropItemNaturally(loc, is);
}
}
@@ -25,6 +25,7 @@ public class EconomyOperations {
configFile = new File(plugin.getDataFolder(), "config.yml");
bukkitConfig.load(configFile);
}
/**
* Have a player pay to open a vault.
* Returns true if successful. Otherwise false.
@@ -32,7 +33,7 @@ public class EconomyOperations {
* @return transaction success
*/
public static boolean payToOpen(Player player) {
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
return true;
double cost = bukkitConfig.getDouble("economy.cost-to-open", 10);
@@ -44,6 +45,7 @@ public class EconomyOperations {
return false;
}
/**
* Have a player pay to create a vault.
* Returns true if successful. Otherwise false.
@@ -51,7 +53,7 @@ public class EconomyOperations {
* @return transaction success
*/
public static boolean payToCreate(Player player) {
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
return true;
double cost = bukkitConfig.getDouble("economy.cost-to-create", 100);
@@ -79,7 +81,7 @@ public class EconomyOperations {
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
if(file.exists()) {
if(playerFile.getString("vault"+number) == null) {
if(playerFile.getString("vault" + number) == null) {
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
return false;
}
@@ -134,7 +134,7 @@ public class Metrics {
private volatile int taskId = -1;
public Metrics(final Plugin plugin) throws IOException {
if (plugin == null) {
if(plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
}
@@ -149,7 +149,7 @@ public class Metrics {
configuration.addDefault("guid", UUID.randomUUID().toString());
// Do we need to create the file?
if (configuration.get("guid", null) == null) {
if(configuration.get("guid", null) == null) {
configuration.options().header("http://mcstats.org").copyDefaults(true);
configuration.save(configurationFile);
}
@@ -166,7 +166,7 @@ public class Metrics {
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/
public Graph createGraph(final String name) {
if (name == null) {
if(name == null) {
throw new IllegalArgumentException("Graph name cannot be null");
}
@@ -186,7 +186,7 @@ public class Metrics {
* @param graph The name of the graph
*/
public void addGraph(final Graph graph) {
if (graph == null) {
if(graph == null) {
throw new IllegalArgumentException("Graph cannot be null");
}
@@ -199,7 +199,7 @@ public class Metrics {
* @param plotter The plotter to use to plot custom data
*/
public void addCustomData(final Plotter plotter) {
if (plotter == null) {
if(plotter == null) {
throw new IllegalArgumentException("Plotter cannot be null");
}
@@ -221,12 +221,12 @@ public class Metrics {
public boolean start() {
synchronized (optOutLock) {
// Did we opt out?
if (isOptOut()) {
if(isOptOut()) {
return false;
}
// Is metrics already running?
if (taskId >= 0) {
if(taskId >= 0) {
return true;
}
@@ -239,18 +239,20 @@ public class Metrics {
try {
// This has to be synchronized or it can collide with the disable method.
synchronized (optOutLock) {
// Disable Task, if it is running and the server owner decided to opt-out
if (isOptOut() && taskId > 0) {
// Disable Task, if it is running and the server owner decided to
// opt-out
if(isOptOut() && taskId > 0) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
// Tell all plotters to stop gathering information.
for (Graph graph : graphs){
for(Graph graph:graphs) {
graph.onOptOut();
}
}
}
// We use the inverse of firstPost because if it is the first time we are posting,
// We use the inverse of firstPost because if it is the first time we are
// posting,
// it is not a interval ping, so it evaluates to FALSE
// Each time thereafter it will evaluate to TRUE, i.e PING!
postPlugin(!firstPost);
@@ -258,7 +260,7 @@ public class Metrics {
// After the first post we set firstPost to false
// Each post thereafter will be a ping
firstPost = false;
} catch (IOException e) {
} catch(IOException e) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
}
}
@@ -274,14 +276,14 @@ public class Metrics {
* @return true if metrics should be opted out of it
*/
public boolean isOptOut() {
synchronized(optOutLock) {
synchronized (optOutLock) {
try {
// Reload the metrics file
configuration.load(getConfigFile());
} catch (IOException ex) {
} catch(IOException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
} catch (InvalidConfigurationException ex) {
} catch(InvalidConfigurationException ex) {
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
return true;
}
@@ -298,13 +300,13 @@ public class Metrics {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (isOptOut()) {
if(isOptOut()) {
configuration.set("opt-out", false);
configuration.save(configurationFile);
}
// Enable Task, if it is not running
if (taskId < 0) {
if(taskId < 0) {
start();
}
}
@@ -319,13 +321,13 @@ public class Metrics {
// This has to be synchronized or it can collide with the check in the task.
synchronized (optOutLock) {
// Check if the server owner has already set opt-out, if not, set it.
if (!isOptOut()) {
if(!isOptOut()) {
configuration.set("opt-out", true);
configuration.save(configurationFile);
}
// Disable Task, if it is running
if (taskId > 0) {
if(taskId > 0) {
this.plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
@@ -338,7 +340,8 @@ public class Metrics {
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins
// to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
@@ -353,7 +356,8 @@ public class Metrics {
* Generic method that posts a plugin to the metrics website
*/
private void postPlugin(final boolean isPing) throws IOException {
// The plugin's description file containg all of the plugin data such as name, version, author, etc
// The plugin's description file containg all of the plugin data such as name, version,
// author, etc
final PluginDescriptionFile description = plugin.getDescription();
// Construct the post data
@@ -365,7 +369,7 @@ public class Metrics {
encodeDataPair(data, "revision", String.valueOf(REVISION));
// If we're pinging, append it
if (isPing) {
if(isPing) {
encodeDataPair(data, "ping", "true");
}
@@ -377,7 +381,7 @@ public class Metrics {
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Plotter plotter : graph.getPlotters()) {
for(Plotter plotter:graph.getPlotters()) {
// The key name to send to the metrics server
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
// Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
@@ -401,7 +405,7 @@ public class Metrics {
// Mineshafter creates a socks proxy, so we can safely bypass it
// It does not reroute POST requests so we need to go around it
if (isMineshafterPresent()) {
if(isMineshafterPresent()) {
connection = url.openConnection(Proxy.NO_PROXY);
} else {
connection = url.openConnection();
@@ -422,18 +426,18 @@ public class Metrics {
writer.close();
reader.close();
if (response == null || response.startsWith("ERR")) {
throw new IOException(response); //Throw the exception
if(response == null || response.startsWith("ERR")) {
throw new IOException(response); // Throw the exception
} else {
// Is this the first update this hour?
if (response.contains("OK This is your first update this hour")) {
if(response.contains("OK This is your first update this hour")) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Plotter plotter : graph.getPlotters()) {
for(Plotter plotter:graph.getPlotters()) {
plotter.reset();
}
}
@@ -451,7 +455,7 @@ public class Metrics {
try {
Class.forName("mineshafter.MineServer");
return true;
} catch (Exception e) {
} catch(Exception e) {
return false;
}
}
@@ -546,7 +550,7 @@ public class Metrics {
@Override
public boolean equals(final Object object) {
if (!(object instanceof Graph)) {
if(!(object instanceof Graph)) {
return false;
}
@@ -620,7 +624,7 @@ public class Metrics {
@Override
public boolean equals(final Object object) {
if (!(object instanceof Plotter)) {
if(!(object instanceof Plotter)) {
return false;
}
@@ -631,4 +635,3 @@ public class Metrics {
}
}
@@ -33,12 +33,13 @@ public class Serialization {
}
return map;
}
private static Object fromJson(Object json) throws JSONException {
if (json == JSONObject.NULL) {
if(json == JSONObject.NULL) {
return null;
} else if (json instanceof JSONObject) {
} else if(json instanceof JSONObject) {
return toMap((JSONObject) json);
} else if (json instanceof JSONArray) {
} else if(json instanceof JSONArray) {
return toList((JSONArray) json);
} else {
return json;
@@ -47,7 +48,7 @@ public class Serialization {
public static List<Object> toList(JSONArray array) throws JSONException {
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < array.length(); i++) {
for(int i = 0; i < array.length(); i++) {
list.add(fromJson(array.get(i)));
}
return list;
@@ -81,7 +82,7 @@ public class Serialization {
try {
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
contents.add(item);
} catch (JSONException e) {
} catch(JSONException e) {
e.printStackTrace();
}
}
@@ -95,17 +96,18 @@ public class Serialization {
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
Map<String, Object> serialized = recreateMap(cs.serialize());
for (Entry<String, Object> entry : serialized.entrySet()) {
if (entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable)entry.getValue()));
for(Entry<String, Object> entry:serialized.entrySet()) {
if(entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable) entry.getValue()));
}
}
serialized.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass()));
return serialized;
}
public static Map<String, Object> recreateMap(Map<String, Object> original) {
Map<String, Object> map = new HashMap<String, Object>();
for (Entry<String, Object> entry : original.entrySet()) {
for(Entry<String, Object> entry:original.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
return map;
@@ -113,10 +115,11 @@ public class Serialization {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static ConfigurationSerializable deserialize(Map<String, Object> map) {
for (Entry<String, Object> entry : map.entrySet()) {
// Check if any of its sub-maps are ConfigurationSerializable. They need to be done first.
if (entry.getValue() instanceof Map && ((Map)entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
entry.setValue(deserialize((Map)entry.getValue()));
for(Entry<String, Object> entry:map.entrySet()) {
// Check if any of its sub-maps are ConfigurationSerializable. They need to be done
// first.
if(entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
entry.setValue(deserialize((Map) entry.getValue()));
}
}
return ConfigurationSerialization.deserializeObject(map);
@@ -28,7 +28,7 @@ public class Updater extends Main {
}
try {
langConf.save(super.getLangFile());
} catch (IOException e) {
} catch(IOException e) {
log.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml.");
log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
e.printStackTrace();
@@ -40,34 +40,47 @@ public class Updater extends Main {
public String getNewVersion() {
return this.newVersion;
}
public boolean getUpdate() throws Exception {
String version = this.version;
URL url = new URL("http://dev.bukkit.org/server-mods/playervaults/files.rss");
InputStreamReader isr = null;
try {
isr = new InputStreamReader(url.openStream());
}
catch(UnknownHostException e) {
return false; //Cannot connect
} catch(UnknownHostException e) {
return false; // Cannot connect
}
BufferedReader in = new BufferedReader(isr);
String line;
int lineNum = 0;
while((line = in.readLine()) != null) {
while ((line = in.readLine()) != null) {
if(line.length() != line.replace("<title>", "").length()) {
line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1); //Substring 1 for me, takes off the beginning v on my file name "v1.3.2"
line = line.replaceAll("<title>", "").replaceAll("</title>", "").replaceAll(" ", "").substring(1); // Substring
// 1
// for
// me,
// takes
// off
// the
// beginning
// v
// on
// my
// file
// name
// "v1.3.2"
if(lineNum == 1) {
this.newVersion = line;
Integer newVer = Integer.parseInt(line.replace(".", ""));
Integer oldVer = Integer.parseInt(version.replace(".", ""));
if(oldVer < newVer) {
return true; //They are using an old version
return true; // They are using an old version
}
else if(oldVer > newVer) {
return false; //They are using a FUTURE version!
return false; // They are using a FUTURE version!
}
else {
return false; //They are up to date!
return false; // They are up to date!
}
}
lineNum = lineNum + 1;
@@ -18,6 +18,7 @@ import com.drtshock.playervaults.Main;
public class VaultManager {
public Main plugin;
public VaultManager(Main instance) {
this.plugin = instance;
}
@@ -128,7 +129,7 @@ public class VaultManager {
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
} catch(IOException e) {
e.printStackTrace();
}
}
@@ -144,7 +145,7 @@ public class VaultManager {
*/
public void saveFile(String name, YamlConfiguration yaml) throws IOException {
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
if (file.exists()) {
if(file.exists()) {
file.renameTo(new File(directory + File.separator + "backups" + File.separator + name.toLowerCase() + ".yml"));
}
yaml.save(file);
+46 -47
View File
@@ -1,27 +1,27 @@
package org.json;
/*
Copyright (c) 2002 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.
* Copyright (c) 2002 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.
*/
/**
@@ -66,12 +66,12 @@ public class CDL {
case '\'':
q = c;
sb = new StringBuffer();
for (;;) {
for(;;) {
c = x.next();
if (c == q) {
if(c == q) {
break;
}
if (c == 0 || c == '\n' || c == '\r') {
if(c == 0 || c == '\n' || c == '\r') {
throw x.syntaxError("Missing close quote '" + q + "'.");
}
sb.append(c);
@@ -94,24 +94,24 @@ public class CDL {
*/
public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
JSONArray ja = new JSONArray();
for (;;) {
for(;;) {
String value = getValue(x);
char c = x.next();
if (value == null ||
if(value == null ||
(ja.length() == 0 && value.length() == 0 && c != ',')) {
return null;
}
ja.put(value);
for (;;) {
if (c == ',') {
for(;;) {
if(c == ',') {
break;
}
if (c != ' ') {
if (c == '\n' || c == '\r' || c == 0) {
if(c != ' ') {
if(c == '\n' || c == '\r' || c == 0) {
return ja;
}
throw x.syntaxError("Bad character '" + c + "' (" +
(int)c + ").");
(int) c + ").");
}
c = x.next();
}
@@ -143,21 +143,21 @@ public class CDL {
*/
public static String rowToString(JSONArray ja) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ja.length(); i += 1) {
if (i > 0) {
for(int i = 0; i < ja.length(); i += 1) {
if(i > 0) {
sb.append(',');
}
Object object = ja.opt(i);
if (object != null) {
if(object != null) {
String string = object.toString();
if (string.length() > 0 && (string.indexOf(',') >= 0 ||
if(string.length() > 0 && (string.indexOf(',') >= 0 ||
string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 ||
string.indexOf(0) >= 0 || string.charAt(0) == '"')) {
sb.append('"');
int length = string.length();
for (int j = 0; j < length; j += 1) {
for(int j = 0; j < length; j += 1) {
char c = string.charAt(j);
if (c >= ' ' && c != '"') {
if(c >= ' ' && c != '"') {
sb.append(c);
}
}
@@ -216,24 +216,23 @@ public class CDL {
*/
public static JSONArray toJSONArray(JSONArray names, JSONTokener x)
throws JSONException {
if (names == null || names.length() == 0) {
if(names == null || names.length() == 0) {
return null;
}
JSONArray ja = new JSONArray();
for (;;) {
for(;;) {
JSONObject jo = rowToJSONObject(names, x);
if (jo == null) {
if(jo == null) {
break;
}
ja.put(jo);
}
if (ja.length() == 0) {
if(ja.length() == 0) {
return null;
}
return ja;
}
/**
* Produce a comma delimited text from a JSONArray of JSONObjects. The
* first row will be a list of names obtained by inspecting the first
@@ -244,9 +243,9 @@ public class CDL {
*/
public static String toString(JSONArray ja) throws JSONException {
JSONObject jo = ja.optJSONObject(0);
if (jo != null) {
if(jo != null) {
JSONArray names = jo.names();
if (names != null) {
if(names != null) {
return rowToString(names) + toString(names, ja);
}
}
@@ -264,13 +263,13 @@ public class CDL {
*/
public static String toString(JSONArray names, JSONArray ja)
throws JSONException {
if (names == null || names.length() == 0) {
if(names == null || names.length() == 0) {
return null;
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ja.length(); i += 1) {
for(int i = 0; i < ja.length(); i += 1) {
JSONObject jo = ja.optJSONObject(i);
if (jo != null) {
if(jo != null) {
sb.append(rowToString(jo.toJSONArray(names)));
}
}
+36 -38
View File
@@ -1,27 +1,27 @@
package org.json;
/*
Copyright (c) 2002 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.
* Copyright (c) 2002 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.
*/
/**
@@ -49,12 +49,12 @@ public class Cookie {
String s = string.trim();
StringBuffer sb = new StringBuffer();
int length = s.length();
for (int i = 0; i < length; i += 1) {
for(int i = 0; i < length; i += 1) {
c = s.charAt(i);
if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') {
if(c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') {
sb.append('%');
sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16));
sb.append(Character.forDigit((char)(c & 0x0f), 16));
sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16));
sb.append(Character.forDigit((char) (c & 0x0f), 16));
} else {
sb.append(c);
}
@@ -62,7 +62,6 @@ public class Cookie {
return sb.toString();
}
/**
* Convert a cookie specification string into a JSONObject. The string
* will contain a name value pair separated by '='. The name and the value
@@ -89,8 +88,8 @@ public class Cookie {
x.next();
while (x.more()) {
name = unescape(x.nextTo("=;"));
if (x.next() != '=') {
if (name.equals("secure")) {
if(x.next() != '=') {
if(name.equals("secure")) {
value = Boolean.TRUE;
} else {
throw x.syntaxError("Missing '=' in cookie parameter.");
@@ -104,7 +103,6 @@ public class Cookie {
return jo;
}
/**
* Convert a JSONObject into a cookie specification string. The JSONObject
* must contain "name" and "value" members.
@@ -121,19 +119,19 @@ public class Cookie {
sb.append(escape(jo.getString("name")));
sb.append("=");
sb.append(escape(jo.getString("value")));
if (jo.has("expires")) {
if(jo.has("expires")) {
sb.append(";expires=");
sb.append(jo.getString("expires"));
}
if (jo.has("domain")) {
if(jo.has("domain")) {
sb.append(";domain=");
sb.append(escape(jo.getString("domain")));
}
if (jo.has("path")) {
if(jo.has("path")) {
sb.append(";path=");
sb.append(escape(jo.getString("path")));
}
if (jo.optBoolean("secure")) {
if(jo.optBoolean("secure")) {
sb.append(";secure");
}
return sb.toString();
@@ -150,15 +148,15 @@ public class Cookie {
public static String unescape(String string) {
int length = string.length();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; ++i) {
for(int i = 0; i < length; ++i) {
char c = string.charAt(i);
if (c == '+') {
if(c == '+') {
c = ' ';
} else if (c == '%' && i + 2 < length) {
} else if(c == '%' && i + 2 < length) {
int d = JSONTokener.dehexchar(string.charAt(i + 1));
int e = JSONTokener.dehexchar(string.charAt(i + 2));
if (d >= 0 && e >= 0) {
c = (char)(d * 16 + e);
if(d >= 0 && e >= 0) {
c = (char) (d * 16 + e);
i += 2;
}
}
+23 -24
View File
@@ -1,27 +1,27 @@
package org.json;
/*
Copyright (c) 2002 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.
* Copyright (c) 2002 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.
*/
import java.util.Iterator;
@@ -58,7 +58,6 @@ public class CookieList {
return jo;
}
/**
* Convert a JSONObject into a cookie list. A cookie list is a sequence
* of name/value pairs. The names are separated from the values by '='.
@@ -75,8 +74,8 @@ public class CookieList {
StringBuffer sb = new StringBuffer();
while (keys.hasNext()) {
string = keys.next().toString();
if (!jo.isNull(string)) {
if (b) {
if(!jo.isNull(string)) {
if(b) {
sb.append(';');
}
sb.append(Cookie.escape(string));
+25 -25
View File
@@ -1,27 +1,27 @@
package org.json;
/*
Copyright (c) 2002 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.
* Copyright (c) 2002 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.
*/
import java.util.Iterator;
@@ -93,7 +93,7 @@ public class HTTP {
String token;
token = x.nextToken();
if (token.toUpperCase().startsWith("HTTP")) {
if(token.toUpperCase().startsWith("HTTP")) {
// Response
@@ -156,13 +156,13 @@ public class HTTP {
Iterator<?> keys = jo.keys();
String string;
StringBuffer sb = new StringBuffer();
if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
if(jo.has("Status-Code") && jo.has("Reason-Phrase")) {
sb.append(jo.getString("HTTP-Version"));
sb.append(' ');
sb.append(jo.getString("Status-Code"));
sb.append(' ');
sb.append(jo.getString("Reason-Phrase"));
} else if (jo.has("Method") && jo.has("Request-URI")) {
} else if(jo.has("Method") && jo.has("Request-URI")) {
sb.append(jo.getString("Method"));
sb.append(' ');
sb.append('"');
@@ -176,7 +176,7 @@ public class HTTP {
sb.append(CRLF);
while (keys.hasNext()) {
string = keys.next().toString();
if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string)
if(!"HTTP-Version".equals(string) && !"Status-Code".equals(string)
&& !"Reason-Phrase".equals(string)
&& !"Method".equals(string)
&& !"Request-URI".equals(string) && !jo.isNull(string)) {
+27 -28
View File
@@ -1,27 +1,27 @@
package org.json;
/*
Copyright (c) 2002 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.
* Copyright (c) 2002 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.
*/
/**
@@ -40,7 +40,6 @@ public class HTTPTokener extends JSONTokener {
super(string);
}
/**
* Get the next token or string. This is used in parsing HTTP headers.
* @throws JSONException
@@ -53,21 +52,21 @@ public class HTTPTokener extends JSONTokener {
do {
c = next();
} while (Character.isWhitespace(c));
if (c == '"' || c == '\'') {
if(c == '"' || c == '\'') {
q = c;
for (;;) {
for(;;) {
c = next();
if (c < ' ') {
if(c < ' ') {
throw syntaxError("Unterminated string.");
}
if (c == q) {
if(c == q) {
return sb.toString();
}
sb.append(c);
}
}
for (;;) {
if (c == 0 || Character.isWhitespace(c)) {
for(;;) {
if(c == 0 || Character.isWhitespace(c)) {
return sb.toString();
}
sb.append(c);
+69 -116
View File
@@ -1,27 +1,27 @@
package org.json;
/*
Copyright (c) 2002 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.
* Copyright (c) 2002 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.
*/
import java.io.IOException;
@@ -81,13 +81,11 @@ import java.util.Map;
*/
public class JSONArray {
/**
* The arrayList where the JSONArray's properties are kept.
*/
private final ArrayList<Object> myArrayList;
/**
* Construct an empty JSONArray.
*/
@@ -102,13 +100,13 @@ public class JSONArray {
*/
public JSONArray(JSONTokener x) throws JSONException {
this();
if (x.nextClean() != '[') {
if(x.nextClean() != '[') {
throw x.syntaxError("A JSONArray text must start with '['");
}
if (x.nextClean() != ']') {
if(x.nextClean() != ']') {
x.back();
for (;;) {
if (x.nextClean() == ',') {
for(;;) {
if(x.nextClean() == ',') {
x.back();
this.myArrayList.add(JSONObject.NULL);
} else {
@@ -118,7 +116,7 @@ public class JSONArray {
switch (x.nextClean()) {
case ';':
case ',':
if (x.nextClean() == ']') {
if(x.nextClean() == ']') {
return;
}
x.back();
@@ -132,7 +130,6 @@ public class JSONArray {
}
}
/**
* Construct a JSONArray from a source JSON text.
* @param source A string that begins with
@@ -144,14 +141,13 @@ public class JSONArray {
this(new JSONTokener(source));
}
/**
* Construct a JSONArray from a Collection.
* @param collection A Collection.
*/
public JSONArray(Collection<?> collection) {
this.myArrayList = new ArrayList<Object>();
if (collection != null) {
if(collection != null) {
Iterator<?> iter = collection.iterator();
while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next()));
@@ -159,16 +155,15 @@ public class JSONArray {
}
}
/**
* Construct a JSONArray from an array
* @throws JSONException If not an array.
*/
public JSONArray(Object array) throws JSONException {
this();
if (array.getClass().isArray()) {
if(array.getClass().isArray()) {
int length = Array.getLength(array);
for (int i = 0; i < length; i += 1) {
for(int i = 0; i < length; i += 1) {
this.put(JSONObject.wrap(Array.get(array, i)));
}
} else {
@@ -177,7 +172,6 @@ public class JSONArray {
}
}
/**
* Get the object value associated with an index.
* @param index
@@ -187,13 +181,12 @@ public class JSONArray {
*/
public Object get(int index) throws JSONException {
Object object = this.opt(index);
if (object == null) {
if(object == null) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
return object;
}
/**
* Get the boolean value associated with an index.
* The string values "true" and "false" are converted to boolean.
@@ -205,19 +198,18 @@ public class JSONArray {
*/
public boolean getBoolean(int index) throws JSONException {
Object object = this.get(index);
if (object.equals(Boolean.FALSE) ||
if(object.equals(Boolean.FALSE) ||
(object instanceof String &&
((String)object).equalsIgnoreCase("false"))) {
((String) object).equalsIgnoreCase("false"))) {
return false;
} else if (object.equals(Boolean.TRUE) ||
} else if(object.equals(Boolean.TRUE) ||
(object instanceof String &&
((String)object).equalsIgnoreCase("true"))) {
((String) object).equalsIgnoreCase("true"))) {
return true;
}
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
}
/**
* Get the double value associated with an index.
*
@@ -230,15 +222,14 @@ public class JSONArray {
Object object = this.get(index);
try {
return object instanceof Number
? ((Number)object).doubleValue()
: Double.parseDouble((String)object);
} catch (Exception e) {
? ((Number) object).doubleValue()
: Double.parseDouble((String) object);
} catch(Exception e) {
throw new JSONException("JSONArray[" + index +
"] is not a number.");
}
}
/**
* Get the int value associated with an index.
*
@@ -250,15 +241,14 @@ public class JSONArray {
Object object = this.get(index);
try {
return object instanceof Number
? ((Number)object).intValue()
: Integer.parseInt((String)object);
} catch (Exception e) {
? ((Number) object).intValue()
: Integer.parseInt((String) object);
} catch(Exception e) {
throw new JSONException("JSONArray[" + index +
"] is not a number.");
}
}
/**
* Get the JSONArray associated with an index.
* @param index The index must be between 0 and length() - 1.
@@ -268,14 +258,13 @@ public class JSONArray {
*/
public JSONArray getJSONArray(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONArray) {
return (JSONArray)object;
if(object instanceof JSONArray) {
return (JSONArray) object;
}
throw new JSONException("JSONArray[" + index +
"] is not a JSONArray.");
}
/**
* Get the JSONObject associated with an index.
* @param index subscript
@@ -285,14 +274,13 @@ public class JSONArray {
*/
public JSONObject getJSONObject(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONObject) {
return (JSONObject)object;
if(object instanceof JSONObject) {
return (JSONObject) object;
}
throw new JSONException("JSONArray[" + index +
"] is not a JSONObject.");
}
/**
* Get the long value associated with an index.
*
@@ -305,15 +293,14 @@ public class JSONArray {
Object object = this.get(index);
try {
return object instanceof Number
? ((Number)object).longValue()
: Long.parseLong((String)object);
} catch (Exception e) {
? ((Number) object).longValue()
: Long.parseLong((String) object);
} catch(Exception e) {
throw new JSONException("JSONArray[" + index +
"] is not a number.");
}
}
/**
* Get the string associated with an index.
* @param index The index must be between 0 and length() - 1.
@@ -322,13 +309,12 @@ public class JSONArray {
*/
public String getString(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof String) {
return (String)object;
if(object instanceof String) {
return (String) object;
}
throw new JSONException("JSONArray[" + index + "] not a string.");
}
/**
* Determine if the value is null.
* @param index The index must be between 0 and length() - 1.
@@ -338,7 +324,6 @@ public class JSONArray {
return JSONObject.NULL.equals(this.opt(index));
}
/**
* Make a string from the contents of this JSONArray. The
* <code>separator</code> string is inserted between each element.
@@ -351,8 +336,8 @@ public class JSONArray {
int len = this.length();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < len; i += 1) {
if (i > 0) {
for(int i = 0; i < len; i += 1) {
if(i > 0) {
sb.append(separator);
}
sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
@@ -360,7 +345,6 @@ public class JSONArray {
return sb.toString();
}
/**
* Get the number of elements in the JSONArray, included nulls.
*
@@ -370,7 +354,6 @@ public class JSONArray {
return this.myArrayList.size();
}
/**
* Get the optional object value associated with an index.
* @param index The index must be between 0 and length() - 1.
@@ -383,7 +366,6 @@ public class JSONArray {
: this.myArrayList.get(index);
}
/**
* Get the optional boolean value associated with an index.
* It returns false if there is no value at that index,
@@ -396,7 +378,6 @@ public class JSONArray {
return this.optBoolean(index, false);
}
/**
* Get the optional boolean value associated with an index.
* It returns the defaultValue if there is no value at that index or if
@@ -409,12 +390,11 @@ public class JSONArray {
public boolean optBoolean(int index, boolean defaultValue) {
try {
return this.getBoolean(index);
} catch (Exception e) {
} catch(Exception e) {
return defaultValue;
}
}
/**
* Get the optional double value associated with an index.
* NaN is returned if there is no value for the index,
@@ -427,7 +407,6 @@ public class JSONArray {
return this.optDouble(index, Double.NaN);
}
/**
* Get the optional double value associated with an index.
* The defaultValue is returned if there is no value for the index,
@@ -440,12 +419,11 @@ public class JSONArray {
public double optDouble(int index, double defaultValue) {
try {
return this.getDouble(index);
} catch (Exception e) {
} catch(Exception e) {
return defaultValue;
}
}
/**
* Get the optional int value associated with an index.
* Zero is returned if there is no value for the index,
@@ -458,7 +436,6 @@ public class JSONArray {
return this.optInt(index, 0);
}
/**
* Get the optional int value associated with an index.
* The defaultValue is returned if there is no value for the index,
@@ -470,12 +447,11 @@ public class JSONArray {
public int optInt(int index, int defaultValue) {
try {
return this.getInt(index);
} catch (Exception e) {
} catch(Exception e) {
return defaultValue;
}
}
/**
* Get the optional JSONArray associated with an index.
* @param index subscript
@@ -484,10 +460,9 @@ public class JSONArray {
*/
public JSONArray optJSONArray(int index) {
Object o = this.opt(index);
return o instanceof JSONArray ? (JSONArray)o : null;
return o instanceof JSONArray ? (JSONArray) o : null;
}
/**
* Get the optional JSONObject associated with an index.
* Null is returned if the key is not found, or null if the index has
@@ -498,10 +473,9 @@ public class JSONArray {
*/
public JSONObject optJSONObject(int index) {
Object o = this.opt(index);
return o instanceof JSONObject ? (JSONObject)o : null;
return o instanceof JSONObject ? (JSONObject) o : null;
}
/**
* Get the optional long value associated with an index.
* Zero is returned if there is no value for the index,
@@ -514,7 +488,6 @@ public class JSONArray {
return this.optLong(index, 0);
}
/**
* Get the optional long value associated with an index.
* The defaultValue is returned if there is no value for the index,
@@ -526,12 +499,11 @@ public class JSONArray {
public long optLong(int index, long defaultValue) {
try {
return this.getLong(index);
} catch (Exception e) {
} catch(Exception e) {
return defaultValue;
}
}
/**
* Get the optional string value associated with an index. It returns an
* empty string if there is no value at that index. If the value
@@ -544,7 +516,6 @@ public class JSONArray {
return this.optString(index, "");
}
/**
* Get the optional string associated with an index.
* The defaultValue is returned if the key is not found.
@@ -560,7 +531,6 @@ public class JSONArray {
: object.toString();
}
/**
* Append a boolean value. This increases the array's length by one.
*
@@ -572,7 +542,6 @@ public class JSONArray {
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONArray which is produced from a Collection.
@@ -584,7 +553,6 @@ public class JSONArray {
return this;
}
/**
* Append a double value. This increases the array's length by one.
*
@@ -599,7 +567,6 @@ public class JSONArray {
return this;
}
/**
* Append an int value. This increases the array's length by one.
*
@@ -611,7 +578,6 @@ public class JSONArray {
return this;
}
/**
* Append an long value. This increases the array's length by one.
*
@@ -623,7 +589,6 @@ public class JSONArray {
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONObject which is produced from a Map.
@@ -635,7 +600,6 @@ public class JSONArray {
return this;
}
/**
* Append an object value. This increases the array's length by one.
* @param value An object value. The value should be a
@@ -648,7 +612,6 @@ public class JSONArray {
return this;
}
/**
* Put or replace a boolean value in the JSONArray. If the index is greater
* than the length of the JSONArray, then null elements will be added as
@@ -663,7 +626,6 @@ public class JSONArray {
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONArray which is produced from a Collection.
@@ -678,7 +640,6 @@ public class JSONArray {
return this;
}
/**
* Put or replace a double value. If the index is greater than the length of
* the JSONArray, then null elements will be added as necessary to pad
@@ -694,7 +655,6 @@ public class JSONArray {
return this;
}
/**
* Put or replace an int value. If the index is greater than the length of
* the JSONArray, then null elements will be added as necessary to pad
@@ -709,7 +669,6 @@ public class JSONArray {
return this;
}
/**
* Put or replace a long value. If the index is greater than the length of
* the JSONArray, then null elements will be added as necessary to pad
@@ -724,7 +683,6 @@ public class JSONArray {
return this;
}
/**
* Put a value in the JSONArray, where the value will be a
* JSONObject that is produced from a Map.
@@ -739,7 +697,6 @@ public class JSONArray {
return this;
}
/**
* Put or replace an object value in the JSONArray. If the index is greater
* than the length of the JSONArray, then null elements will be added as
@@ -754,10 +711,10 @@ public class JSONArray {
*/
public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
if (index < 0) {
if(index < 0) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
if (index < this.length()) {
if(index < this.length()) {
this.myArrayList.set(index, value);
} else {
while (index != this.length()) {
@@ -768,7 +725,6 @@ public class JSONArray {
return this;
}
/**
* Remove an index and close the hole.
* @param index The index of the element to be removed.
@@ -781,7 +737,6 @@ public class JSONArray {
return o;
}
/**
* Produce a JSONObject by combining a JSONArray of names with the values
* of this JSONArray.
@@ -792,17 +747,16 @@ public class JSONArray {
* @throws JSONException If any of the names are null.
*/
public JSONObject toJSONObject(JSONArray names) throws JSONException {
if (names == null || names.length() == 0 || this.length() == 0) {
if(names == null || names.length() == 0 || this.length() == 0) {
return null;
}
JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1) {
for(int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i));
}
return jo;
}
/**
* Make a JSON text of this JSONArray. For compactness, no
* unnecessary whitespace is added. If it is not possible to produce a
@@ -817,12 +771,11 @@ public class JSONArray {
public String toString() {
try {
return this.toString(0);
} catch (Exception e) {
} catch(Exception e) {
return null;
}
}
/**
* Make a prettyprinted JSON text of this JSONArray.
* Warning: This method assumes that the data structure is acyclical.
@@ -874,17 +827,17 @@ public class JSONArray {
int length = this.length();
writer.write('[');
if (length == 1) {
if(length == 1) {
JSONObject.writeValue(writer, this.myArrayList.get(0),
indentFactor, indent);
} else if (length != 0) {
} else if(length != 0) {
final int newindent = indent + indentFactor;
for (int i = 0; i < length; i += 1) {
if (commanate) {
for(int i = 0; i < length; i += 1) {
if(commanate) {
writer.write(',');
}
if (indentFactor > 0) {
if(indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, newindent);
@@ -892,14 +845,14 @@ public class JSONArray {
indentFactor, newindent);
commanate = true;
}
if (indentFactor > 0) {
if(indentFactor > 0) {
writer.write('\n');
}
JSONObject.indent(writer, indent);
}
writer.write(']');
return writer;
} catch (IOException e) {
} catch(IOException e) {
throw new JSONException(e);
}
}
File diff suppressed because it is too large Load Diff
+1
View File
@@ -1,4 +1,5 @@
package org.json;
/**
* The <code>JSONString</code> interface allows a <code>toJSONString()</code>
* method so that a class can change the behavior of
+21 -21
View File
@@ -1,27 +1,27 @@
package org.json;
/*
Copyright (c) 2006 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.
* Copyright (c) 2006 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.
*/
import java.io.StringWriter;
+48 -65
View File
@@ -8,27 +8,27 @@ import java.io.Reader;
import java.io.StringReader;
/*
Copyright (c) 2002 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.
* Copyright (c) 2002 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.
*/
/**
@@ -48,7 +48,6 @@ public class JSONTokener {
private Reader reader;
private boolean usePrevious;
/**
* Construct a JSONTokener from a Reader.
*
@@ -66,7 +65,6 @@ public class JSONTokener {
this.line = 1;
}
/**
* Construct a JSONTokener from an InputStream.
*/
@@ -74,7 +72,6 @@ public class JSONTokener {
this(new InputStreamReader(inputStream));
}
/**
* Construct a JSONTokener from a string.
*
@@ -84,14 +81,13 @@ public class JSONTokener {
this(new StringReader(s));
}
/**
* Back up one character. This provides a sort of lookahead capability,
* so that you can test for a digit or letter before attempting to parse
* the next number or identifier.
*/
public void back() throws JSONException {
if (this.usePrevious || this.index <= 0) {
if(this.usePrevious || this.index <= 0) {
throw new JSONException("Stepping back two steps is not supported");
}
this.index -= 1;
@@ -100,7 +96,6 @@ public class JSONTokener {
this.eof = false;
}
/**
* Get the hex value of a character (base16).
* @param c A character between '0' and '9' or between 'A' and 'F' or
@@ -108,13 +103,13 @@ public class JSONTokener {
* @return An int between 0 and 15, or -1 if c was not a hex digit.
*/
public static int dehexchar(char c) {
if (c >= '0' && c <= '9') {
if(c >= '0' && c <= '9') {
return c - '0';
}
if (c >= 'A' && c <= 'F') {
if(c >= 'A' && c <= 'F') {
return c - ('A' - 10);
}
if (c >= 'a' && c <= 'f') {
if(c >= 'a' && c <= 'f') {
return c - ('a' - 10);
}
return -1;
@@ -124,7 +119,6 @@ public class JSONTokener {
return this.eof && !this.usePrevious;
}
/**
* Determine if the source string still contains characters that next()
* can consume.
@@ -132,14 +126,13 @@ public class JSONTokener {
*/
public boolean more() throws JSONException {
this.next();
if (this.end()) {
if(this.end()) {
return false;
}
this.back();
return true;
}
/**
* Get the next character in the source string.
*
@@ -147,26 +140,26 @@ public class JSONTokener {
*/
public char next() throws JSONException {
int c;
if (this.usePrevious) {
if(this.usePrevious) {
this.usePrevious = false;
c = this.previous;
} else {
try {
c = this.reader.read();
} catch (IOException exception) {
} catch(IOException exception) {
throw new JSONException(exception);
}
if (c <= 0) { // End of stream
if(c <= 0) { // End of stream
this.eof = true;
c = 0;
}
}
this.index += 1;
if (this.previous == '\r') {
if(this.previous == '\r') {
this.line += 1;
this.character = c == '\n' ? 0 : 1;
} else if (c == '\n') {
} else if(c == '\n') {
this.line += 1;
this.character = 0;
} else {
@@ -176,7 +169,6 @@ public class JSONTokener {
return this.previous;
}
/**
* Consume the next character, and check that it matches a specified
* character.
@@ -186,14 +178,13 @@ public class JSONTokener {
*/
public char next(char c) throws JSONException {
char n = this.next();
if (n != c) {
if(n != c) {
throw this.syntaxError("Expected '" + c + "' and instead saw '" +
n + "'");
}
return n;
}
/**
* Get the next n characters.
*
@@ -204,7 +195,7 @@ public class JSONTokener {
* n characters remaining in the source string.
*/
public String next(int n) throws JSONException {
if (n == 0) {
if(n == 0) {
return "";
}
@@ -213,7 +204,7 @@ public class JSONTokener {
while (pos < n) {
chars[pos] = this.next();
if (this.end()) {
if(this.end()) {
throw this.syntaxError("Substring bounds error");
}
pos += 1;
@@ -221,22 +212,20 @@ public class JSONTokener {
return new String(chars);
}
/**
* Get the next char in the string, skipping whitespace.
* @throws JSONException
* @return A character, or 0 if there are no more characters.
*/
public char nextClean() throws JSONException {
for (;;) {
for(;;) {
char c = this.next();
if (c == 0 || c > ' ') {
if(c == 0 || c > ' ') {
return c;
}
}
}
/**
* Return the characters up to the next close quote character.
* Backslash processing is done. The formal JSON format does not
@@ -251,7 +240,7 @@ public class JSONTokener {
public String nextString(char quote) throws JSONException {
char c;
StringBuffer sb = new StringBuffer();
for (;;) {
for(;;) {
c = this.next();
switch (c) {
case 0:
@@ -277,7 +266,7 @@ public class JSONTokener {
sb.append('\r');
break;
case 'u':
sb.append((char)Integer.parseInt(this.next(4), 16));
sb.append((char) Integer.parseInt(this.next(4), 16));
break;
case '"':
case '\'':
@@ -290,7 +279,7 @@ public class JSONTokener {
}
break;
default:
if (c == quote) {
if(c == quote) {
return sb.toString();
}
sb.append(c);
@@ -298,7 +287,6 @@ public class JSONTokener {
}
}
/**
* Get the text up but not including the specified character or the
* end of line, whichever comes first.
@@ -307,10 +295,10 @@ public class JSONTokener {
*/
public String nextTo(char delimiter) throws JSONException {
StringBuffer sb = new StringBuffer();
for (;;) {
for(;;) {
char c = this.next();
if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
if (c != 0) {
if(c == delimiter || c == 0 || c == '\n' || c == '\r') {
if(c != 0) {
this.back();
}
return sb.toString().trim();
@@ -319,7 +307,6 @@ public class JSONTokener {
}
}
/**
* Get the text up but not including one of the specified delimiter
* characters or the end of line, whichever comes first.
@@ -329,11 +316,11 @@ public class JSONTokener {
public String nextTo(String delimiters) throws JSONException {
char c;
StringBuffer sb = new StringBuffer();
for (;;) {
for(;;) {
c = this.next();
if (delimiters.indexOf(c) >= 0 || c == 0 ||
if(delimiters.indexOf(c) >= 0 || c == 0 ||
c == '\n' || c == '\r') {
if (c != 0) {
if(c != 0) {
this.back();
}
return sb.toString().trim();
@@ -342,7 +329,6 @@ public class JSONTokener {
}
}
/**
* Get the next value. The value can be a Boolean, Double, Integer,
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
@@ -383,13 +369,12 @@ public class JSONTokener {
this.back();
string = sb.toString().trim();
if ("".equals(string)) {
if("".equals(string)) {
throw this.syntaxError("Missing value");
}
return JSONObject.stringToValue(string);
}
/**
* Skip characters until the next character is the requested character.
* If the requested character is not found, no characters are skipped.
@@ -406,7 +391,7 @@ public class JSONTokener {
this.reader.mark(1000000);
do {
c = this.next();
if (c == 0) {
if(c == 0) {
this.reader.reset();
this.index = startIndex;
this.character = startCharacter;
@@ -414,7 +399,7 @@ public class JSONTokener {
return c;
}
} while (c != to);
} catch (IOException exc) {
} catch(IOException exc) {
throw new JSONException(exc);
}
@@ -422,7 +407,6 @@ public class JSONTokener {
return c;
}
/**
* Make a JSONException to signal a syntax error.
*
@@ -433,7 +417,6 @@ public class JSONTokener {
return new JSONException(message + this.toString());
}
/**
* Make a printable string of this JSONTokener.
*
+38 -42
View File
@@ -4,27 +4,27 @@ import java.io.IOException;
import java.io.Writer;
/*
Copyright (c) 2006 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.
* Copyright (c) 2006 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.
*/
/**
@@ -108,19 +108,19 @@ public class JSONWriter {
* @throws JSONException If the value is out of sequence.
*/
private JSONWriter append(String string) throws JSONException {
if (string == null) {
if(string == null) {
throw new JSONException("Null pointer");
}
if (this.mode == 'o' || this.mode == 'a') {
if(this.mode == 'o' || this.mode == 'a') {
try {
if (this.comma && this.mode == 'a') {
if(this.comma && this.mode == 'a') {
this.writer.write(',');
}
this.writer.write(string);
} catch (IOException e) {
} catch(IOException e) {
throw new JSONException(e);
}
if (this.mode == 'o') {
if(this.mode == 'o') {
this.mode = 'k';
}
this.comma = true;
@@ -139,7 +139,7 @@ public class JSONWriter {
* outermost array or object).
*/
public JSONWriter array() throws JSONException {
if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
if(this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
this.push(null);
this.append("[");
this.comma = false;
@@ -156,7 +156,7 @@ public class JSONWriter {
* @throws JSONException If unbalanced.
*/
private JSONWriter end(char mode, char c) throws JSONException {
if (this.mode != mode) {
if(this.mode != mode) {
throw new JSONException(mode == 'a'
? "Misplaced endArray."
: "Misplaced endObject.");
@@ -164,7 +164,7 @@ public class JSONWriter {
this.pop(mode);
try {
this.writer.write(c);
} catch (IOException e) {
} catch(IOException e) {
throw new JSONException(e);
}
this.comma = true;
@@ -200,13 +200,13 @@ public class JSONWriter {
* do not belong in arrays or if the key is null.
*/
public JSONWriter key(String string) throws JSONException {
if (string == null) {
if(string == null) {
throw new JSONException("Null key.");
}
if (this.mode == 'k') {
if(this.mode == 'k') {
try {
this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
if (this.comma) {
if(this.comma) {
this.writer.write(',');
}
this.writer.write(JSONObject.quote(string));
@@ -214,14 +214,13 @@ public class JSONWriter {
this.comma = false;
this.mode = 'o';
return this;
} catch (IOException e) {
} catch(IOException e) {
throw new JSONException(e);
}
}
throw new JSONException("Misplaced key.");
}
/**
* Begin appending a new object. All keys and values until the balancing
* <code>endObject</code> will be appended to this object. The
@@ -232,10 +231,10 @@ public class JSONWriter {
* outermost array or object).
*/
public JSONWriter object() throws JSONException {
if (this.mode == 'i') {
if(this.mode == 'i') {
this.mode = 'o';
}
if (this.mode == 'o' || this.mode == 'a') {
if(this.mode == 'o' || this.mode == 'a') {
this.append("{");
this.push(new JSONObject());
this.comma = false;
@@ -245,18 +244,17 @@ public class JSONWriter {
}
/**
* Pop an array or object scope.
* @param c The scope to close.
* @throws JSONException If nesting is wrong.
*/
private void pop(char c) throws JSONException {
if (this.top <= 0) {
if(this.top <= 0) {
throw new JSONException("Nesting error.");
}
char m = this.stack[this.top - 1] == null ? 'a' : 'k';
if (m != c) {
if(m != c) {
throw new JSONException("Nesting error.");
}
this.top -= 1;
@@ -273,7 +271,7 @@ public class JSONWriter {
* @throws JSONException If nesting is too deep.
*/
private void push(JSONObject jo) throws JSONException {
if (this.top >= maxdepth) {
if(this.top >= maxdepth) {
throw new JSONException("Nesting too deep.");
}
this.stack[this.top] = jo;
@@ -281,7 +279,6 @@ public class JSONWriter {
this.top += 1;
}
/**
* Append either the value <code>true</code> or the value
* <code>false</code>.
@@ -313,7 +310,6 @@ public class JSONWriter {
return this.append(Long.toString(l));
}
/**
* Append an object value.
* @param object The object to append. It can be null, or a Boolean, Number,