Use local copy of latest bndlib code for pre-release testing purposes
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1347815 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java b/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
new file mode 100644
index 0000000..2f0eea5
--- /dev/null
+++ b/bundleplugin/src/main/java/aQute/lib/json/FileHandler.java
@@ -0,0 +1,38 @@
+package aQute.lib.json;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+
+import aQute.lib.base64.*;
+
+public class FileHandler extends Handler {
+
+ @Override void encode(Encoder app, Object object, Map<Object, Type> visited)
+ throws IOException, Exception {
+ File f = (File) object;
+ if ( !f.isFile())
+ throw new RuntimeException("Encoding a file requires the file to exist and to be a normal file " + f );
+
+ FileInputStream in = new FileInputStream(f);
+ try {
+ app.append('"');
+ Base64.encode(in, app);
+ app.append('"');
+ } finally {
+ in.close();
+ }
+ }
+
+ Object decode(String s) throws Exception {
+ File tmp = File.createTempFile("json", ".bin");
+ FileOutputStream fout = new FileOutputStream(tmp);
+ try {
+ Base64.decode(new StringReader(s), fout);
+ } finally {
+ fout.close();
+ }
+ return tmp;
+ }
+
+}