// Path: reference/src/main/java/me/doubledutch/stroom/client/StreamConnection.java
// public interface StreamConnection{
// 	public final static int LINEAR=0;
// 	public final static int SYNC=1;
// 	public final static int FLUSH=2;
// 	public final static int NONE=3;
// 
// 	public List<String> get(long index,long endIndex) throws IOException;
// 	public String get(long index) throws IOException;
// 	public String getLast() throws IOException;
// 	public long getCount() throws IOException;
// 	
// 	public long append(JSONObject data) throws IOException,JSONException;
// 	public long append(String data) throws IOException,JSONException;
// 	public List<Long> append(List<String> data) throws IOException,JSONException;
// 	
// 	public long append(JSONObject data,int hint) throws IOException,JSONException;
// 	public long append(String data,int hint) throws IOException,JSONException;
// 	public List<Long> append(List<String> data,int hint) throws IOException,JSONException;
// 
// 	public void truncate(long index) throws IOException;
// }
// 
// Path: reference/src/main/java/me/doubledutch/stroom/client/KVStoreConnection.java
// public interface KVStoreConnection{
// 	public String get(String key) throws IOException;
// 	public List<String> list() throws IOException;
// 	public List<String> search(String pattern) throws IOException;
// }


import org.apache.log4j.Logger;
import me.doubledutch.stroom.perf.*;
import me.doubledutch.stroom.streams.*;
import me.doubledutch.stroom.*;
import me.doubledutch.stroom.client.StreamConnection;
import me.doubledutch.stroom.client.KVStoreConnection;
import java.util.*;
import java.util.concurrent.*;
import org.json.*;
import java.net.*;
import javax.script.*;
import java.io.*;
									output.add(obj.toString());
								}
							}else{
								output.add(out);
							}
						}
						index++;
					}
					metric.startTimer("output.append");
					if(output.size()>0){
						// Separate keys from values
						List<String> removeList=new ArrayList<String>();
						List<String> keyList=new ArrayList<String>(output.size());
						List<String> valueList=new ArrayList<String>(output.size());
						for(String str:output){
							JSONObject obj=new JSONObject(str);
							if(obj.has("key") && obj.has("value")){
								Object keyObj=obj.get("key");
								String key=null;
								if(keyObj instanceof String){
									key=(String)keyObj;
								}else{
									key=keyObj.toString();
								}
								if(obj.isNull("value")){
									// Remove key
									removeList.add(key);
								}else{
									keyList.add(key);
									JSONObject value=obj.getJSONObject("value");
// Path: reference/src/main/java/me/doubledutch/stroom/client/StreamConnection.java
// public interface StreamConnection{
// 	public final static int LINEAR=0;
// 	public final static int SYNC=1;
// 	public final static int FLUSH=2;
// 	public final static int NONE=3;
// 
// 	public List<String> get(long index,long endIndex) throws IOException;
// 	public String get(long index) throws IOException;
// 	public String getLast() throws IOException;
// 	public long getCount() throws IOException;
// 	
// 	public long append(JSONObject data) throws IOException,JSONException;
// 	public long append(String data) throws IOException,JSONException;
// 	public List<Long> append(List<String> data) throws IOException,JSONException;
// 	
// 	public long append(JSONObject data,int hint) throws IOException,JSONException;
// 	public long append(String data,int hint) throws IOException,JSONException;
// 	public List<Long> append(List<String> data,int hint) throws IOException,JSONException;
// 
// 	public void truncate(long index) throws IOException;
// }
// 
// Path: reference/src/main/java/me/doubledutch/stroom/client/KVStoreConnection.java
// public interface KVStoreConnection{
// 	public String get(String key) throws IOException;
// 	public List<String> list() throws IOException;
// 	public List<String> search(String pattern) throws IOException;
// }


// Path: reference/src/main/java/me/doubledutch/stroom/filters/KeyValueService.java
import org.apache.log4j.Logger;
import me.doubledutch.stroom.perf.*;
import me.doubledutch.stroom.streams.*;
import me.doubledutch.stroom.*;
import me.doubledutch.stroom.client.StreamConnection;
import me.doubledutch.stroom.client.KVStoreConnection;
import java.util.*;
import java.util.concurrent.*;
import org.json.*;
import java.net.*;
import javax.script.*;
import java.io.*;

									output.add(obj.toString());
								}
							}else{
								output.add(out);
							}
						}
						index++;
					}
					metric.startTimer("output.append");
					if(output.size()>0){
						// Separate keys from values
						List<String> removeList=new ArrayList<String>();
						List<String> keyList=new ArrayList<String>(output.size());
						List<String> valueList=new ArrayList<String>(output.size());
						for(String str:output){
							JSONObject obj=new JSONObject(str);
							if(obj.has("key") && obj.has("value")){
								Object keyObj=obj.get("key");
								String key=null;
								if(keyObj instanceof String){
									key=(String)keyObj;
								}else{
									key=keyObj.toString();
								}
								if(obj.isNull("value")){
									// Remove key
									removeList.add(key);
								}else{
									keyList.add(key);
									JSONObject value=obj.getJSONObject("value");
									valueList.add(value.toString());