1
dd
2025-12-26 cca0b258ffefd2ad478b9e5115200f5a223eb09f
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
package com.nq.ws.hasbinary;
 
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
 
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class HasBinary {
    
    private static final Logger logger = Logger.getLogger(HasBinary.class.getName());
    
    private HasBinary() {}
 
    public static boolean hasBinary(Object data) {
        return _hasBinary(data);
    }
 
    private static boolean _hasBinary(Object obj) {
        if (obj == null) return false;
 
        if (obj instanceof byte[]) {
            return true;
        }
 
        if (obj instanceof JSONArray) {
            JSONArray _obj = (JSONArray)obj;
            int length = _obj.length();
            for (int i = 0; i < length; i++) {
                Object v;
                try {
                    v = _obj.isNull(i) ? null : _obj.get(i);
                } catch (JSONException e) {
                    logger.log(Level.WARNING, "An error occured while retrieving data from JSONArray", e);
                    return false;
                }
                if (_hasBinary(v)) {
                    return true;
                }
            }
        } else if (obj instanceof JSONObject) {
            JSONObject _obj = (JSONObject)obj;
            Iterator keys = _obj.keys();
            while (keys.hasNext()) {
                String key = (String)keys.next();
                Object v;
                try {
                    v = _obj.get(key);
                } catch (JSONException e) {
                    logger.log(Level.WARNING, "An error occured while retrieving data from JSONObject", e);
                    return false;       
                }
                if (_hasBinary(v)) {
                    return true;
                }
            }
        }
 
        return false;
    }
}