package me.xephore.virustotal2bind.packets;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class PacketDetectionDecoder implements Decoder {
	
	private final JSONObject obj;
	private int detections = 0;
	
	public PacketDetectionDecoder(JSONObject obj) {
		this.obj = obj;
	}
	
	@Override
	public void decode() {
		JSONArray array = (JSONArray) obj.get("detected_urls");
		
		String name = array.toString().replace("{", "").replace("}", "").replace("[", "").replace("]", "");
		
		String[] args = name.split(",");
		
		for(String a : args) {
			if(a.contains("total")) {
				this.detections = (this.detections+Integer.parseInt(a.replace("\"total\":", "")));
			}
		}
	}
	
	@Override
	public Object getResult() {
		return "detections: " + detections;
	}

}

@@ -171,19 +171,18 @@
 oder %7B%0D%0A
-%09
 %0D%0A
+
 %09private
@@ -235,19 +235,18 @@
 s = 0;%0D%0A
-%09
 %0D%0A
+
 %09public 
@@ -306,27 +306,26 @@
 = obj;%0D%0A%09%7D%0D%0A
-%09
 %0D%0A
+
 %09@Override%0D%0A
@@ -404,28 +404,50 @@
 ed_urls%22);%0D%0A
-%09%09
+%0D%0A%09%09if(array != null) %7B
 %0D%0A
+%09
 %09%09String nam
@@ -539,19 +539,16 @@
 %22%22);%0D%0A%09%09
-%0D%0A%09
 %09String%5B
@@ -576,19 +576,16 @@
 ,%22);%0D%0A%09%09
-%0D%0A%09
 %09for(Str
@@ -604,16 +604,17 @@
 ) %7B%0D%0A%09%09%09
+%09
 if(a.con
@@ -628,24 +628,25 @@
 total%22)) %7B%0D%0A
+%09
 %09%09%09%09this.det
@@ -721,16 +721,23 @@
 %22%22)));%0D%0A
+%09%09%09%09%7D%0D%0A
 %09%09%09%7D%0D%0A%09%09
@@ -743,17 +743,16 @@
 %09%7D%0D%0A%09%7D%0D%0A
-%09
 %0D%0A%09@Over

fix NullPointerException