1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
From: Ole Streicher <olebole@debian.org>
Date: Tue, 23 Jun 2020 22:21:57 +0200
Subject: Use android-json
This one has only "String" and input parameter for JSONTokener
src/main/uk/ac/starlink/vo/Vocabulary.java | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/main/uk/ac/starlink/vo/Vocabulary.java b/src/main/uk/ac/starlink/vo/Vocabulary.java
index 2d94b34..1a87e6a 100644
@@ -15,6 +15,8 @@ import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.apache.commons.io.IOUtils;
+import org.json.JSONException;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
@@ -123,7 +125,7 @@ public class Vocabulary {
/* Parse the JSON in accordance with the desise format
* defined in Vocabularies 2.0. */
- JSONTokener jt = new JSONTokener( in );
+ JSONTokener jt = new JSONTokener( IOUtils.toString( in ) );
Object top = jt.nextValue();
if ( top instanceof JSONObject ) {
JSONObject topObj = (JSONObject) top;
@@ -154,7 +156,9 @@ public class Vocabulary {
return new Vocabulary( uri, terms, flavour );
}
}
- }
+ } catch (JSONException e) {
+ throw new IOException(e);
+ }
finally {
in.close();
}
@@ -437,10 +441,12 @@ public class Vocabulary {
if ( value instanceof JSONArray ) {
JSONArray jarray = (JSONArray) value;
for ( int i = 0; i < jarray.length(); i++ ) {
- Object el = jarray.get( i );
- if ( el instanceof String ) {
- list.add( (String) el );
- }
+ try {
+ Object el = jarray.get( i );
+ if ( el instanceof String ) {
+ list.add( (String) el );
+ }
+ } catch (JSONException e) { }
}
}
return list.toArray( new String[ 0 ] );
|