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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
From: Ole Streicher <olebole@debian.org>
Date: Mon, 28 May 2018 14:26:48 -0700
Subject: Use android json
The original org.json code is not packaged for Debian because of its
license, and the android variant is a bit outdated now.
The libjson-java code is different and contains net.sf.json (which
however has classes of the same name...)
---
src/main/uk/ac/starlink/topcat/TopcatCodec2.java | 5 +++--
.../uk/ac/starlink/topcat/activate/HipsSurvey.java | 26 +++++++++++++++++-----
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/main/uk/ac/starlink/topcat/TopcatCodec2.java b/src/main/uk/ac/starlink/topcat/TopcatCodec2.java
index 237eef3..f469600 100644
--- a/src/main/uk/ac/starlink/topcat/TopcatCodec2.java
+++ b/src/main/uk/ac/starlink/topcat/TopcatCodec2.java
@@ -859,7 +859,7 @@ public class TopcatCodec2 implements TopcatCodec {
.append( "[" );
for ( Map<String,String> map : list ) {
buf.append( "\n " )
- .append( JSONObject.valueToString( map ) )
+ .append( (new JSONObject( map )).toString() )
.append( "," );
}
buf.setLength( buf.length() - 1 );
@@ -886,7 +886,8 @@ public class TopcatCodec2 implements TopcatCodec {
if ( el instanceof JSONObject ) {
JSONObject jsonObj = (JSONObject) el;
Map<String,String> map = new LinkedHashMap<String,String>();
- for ( String key : jsonObj.keySet() ) {
+ java.util.Iterator<String> iterator = jsonObj.keys();
+ for ( String key : (Iterable<String>)() -> iterator ) {
Object val = jsonObj.get( key );
if ( val instanceof String ) {
map.put( key, (String) val );
diff --git a/src/main/uk/ac/starlink/topcat/activate/HipsSurvey.java b/src/main/uk/ac/starlink/topcat/activate/HipsSurvey.java
index 2d7efd1..c05f91f 100644
--- a/src/main/uk/ac/starlink/topcat/activate/HipsSurvey.java
+++ b/src/main/uk/ac/starlink/topcat/activate/HipsSurvey.java
@@ -17,6 +17,7 @@ import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
+import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import uk.ac.starlink.util.ContentCoding;
@@ -402,7 +403,13 @@ public class HipsSurvey {
logger_.info( "Loading HiPS list from " + url );
InputStream in = new BufferedInputStream( coding.openStream( url ) );
try {
- JSONTokener jt = new JSONTokener( in );
+ byte[] contents = new byte[1024];
+ int bytesRead = 0;
+ String strFileContents = "";
+ while((bytesRead = in.read(contents)) != -1) {
+ strFileContents += new String(contents, 0, bytesRead);
+ }
+ JSONTokener jt = new JSONTokener( strFileContents );
Object next = jt.nextValue();
if ( next instanceof JSONArray ) {
List<HipsSurvey> list = new ArrayList<HipsSurvey>();
@@ -422,6 +429,9 @@ public class HipsSurvey {
throw new IOException( "Unexpected JSON object from " + url );
}
}
+ catch (JSONException e) {
+ throw new IOException( "Unexpected JSON object from " + url );
+ }
finally {
in.close();
}
@@ -436,10 +446,16 @@ public class HipsSurvey {
*/
private static final Map<String,String> toMap( JSONObject jobj ) {
Map<String,String> map = new LinkedHashMap<String,String>();
- for ( String key : JSONObject.getNames( jobj ) ) {
- Object val = jobj.get( key );
- if ( val instanceof String ) {
- map.put( key, (String) val );
+ JSONArray names = jobj.names();
+ for ( int i = 0; i < names.length(); i++ ) {
+ try {
+ String key = (String)names.get(i);
+ Object val = jobj.get( key );
+ if ( val instanceof String ) {
+ map.put( key, (String) val );
+ }
+ }
+ catch (JSONException e) {
}
}
return map;
|