@Override
    public void permission(Permission p, ProtectionDomain pd) {
        if (filter(p)) {
            //filter out file operation checks for this class
            return;
        }

        if (!perms.containsKey(pd)) {
            perms.put(pd, new ArrayList<Permission>());
        }
        perms.get(pd).add(p);

        //write out the perms
        try (PrintWriter writer = new PrintWriter(new BufferedOutputStream(
                new FileOutputStream(outfile, true)))) {
//            raf.seek(0);
//            for (Entry<ProtectionDomain, List<Permission>> entry : perms.entrySet()) {
//                raf.writeUTF(format(entry.getKey(), entry.getValue().toArray(new Permission[0])));
//            }
            for (Entry<ProtectionDomain, List<Permission>> entry : perms.entrySet()) {
                writer.write(format(entry.getKey(), entry.getValue().toArray(new Permission[0])));
            }

        } catch (IOException ex) {
            System.err.println("Unable to save permission");
            ex.printStackTrace();
        }
    }