Example usage for org.apache.commons.lang3 SerializationUtils deserialize

List of usage examples for org.apache.commons.lang3 SerializationUtils deserialize

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SerializationUtils deserialize.

Prototype

public static <T> T deserialize(final byte[] objectData) 

Source Link

Document

Deserializes a single Object from an array of bytes.

Usage

From source file:net.spfbl.core.Defer.java

public static void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/defer.map");
    if (file.exists()) {
        try {/*from w  ww . j a  v  a  2 s.c  o  m*/
            HashMap<String, Object> map;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                map = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String key : map.keySet()) {
                Object value = map.get(key);
                if (value instanceof Long) {
                    long start = (Long) value;
                    Defer defer = new Defer(start);
                    putExact(key, defer);
                } else if (value instanceof Defer) {
                    Defer defer = (Defer) value;
                    putExact(key, defer);
                }
            }
            setLoaded();
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

From source file:net.spfbl.core.Huffman.java

public static Huffman load() {
    try {/*  w  w  w.j  a v a  2 s  .c om*/
        InputStream inputStream = Huffman.class.getResourceAsStream("huffman.obj");
        try {
            return SerializationUtils.deserialize(inputStream);
        } finally {
            inputStream.close();
        }
    } catch (Exception ex) {
        Server.logError(ex);
        System.exit(1);
        return null;
    }
}

From source file:net.spfbl.core.Peer.java

public static synchronized void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/peer.map");
    if (file.exists()) {
        try {//from  w w w .ja va2  s.  c o  m
            HashMap<Object, Object> map;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                map = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (Object key : map.keySet()) {
                Object value = map.get(key);
                if (key instanceof InetAddress) {
                    InetAddress address = (InetAddress) key;
                    Integer port = (Integer) value;
                    create(address.getHostAddress(), port);
                } else if (key instanceof String) {
                    String address = (String) key;
                    if (value instanceof Integer) {
                        Integer port = (Integer) value;
                        create(address, port);
                    } else if (value instanceof Peer) {
                        Peer peer = (Peer) value;
                        if (peer.send == Send.DUNNO) {
                            // Obsoleto.
                            peer.send = Send.NEVER;
                        } else if (peer.send == Send.BLOCK) {
                            // Obsoleto.
                            peer.send = Send.ALWAYS;
                        }
                        if (peer.receive == Receive.CONFIRM) {
                            // Obsoleto.
                            peer.receive = Receive.REPUTATION;
                        }
                        if (peer.receive == Receive.RETAIN) {
                            // Obsoleto.
                            peer.receive = Receive.REPUTATION;
                        }
                        //                            if (peer.retainSet == null) {
                        //                                peer.retainSet = new TreeSet<String>();
                        //                            }
                        if (peer.limit == 0) {
                            peer.limit = 100;
                        }
                        if (peer.reputationMap2 == null) {
                            peer.reputationMap2 = new TreeMap<String, Binomial>();
                        }
                        if (peer.reputationMap != null) {
                            peer.reputationMap2.putAll(peer.reputationMap);
                            peer.reputationMap.clear();
                        }
                        MAP.put(address, peer);
                    }
                }
            }
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    } else {
        try {
            if (Core.hasPeerConnection()) {
                Peer matrix = Peer.create("matrix.spfbl.net", 9877);
                matrix.setReceiveStatus(Receive.ACCEPT);
                matrix.setSendStatus(Send.REPUTATION);
                matrix.sendHELO();
            }
        } catch (ProcessException ex) {
            Server.logError(ex);
        }
    }
}

From source file:net.spfbl.core.Reverse.java

public static void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/reverse.map");
    if (file.exists()) {
        try {//w  w  w .j a  v  a2s.c o m
            HashMap<String, Object> map;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                map = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String key : map.keySet()) {
                Object value = map.get(key);
                if (value instanceof Reverse) {
                    Reverse reverse = (Reverse) value;
                    putExact(key, reverse);
                }
            }
            setStored();
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

From source file:net.spfbl.core.Server.java

private static SecretKey getPrivateKey() {
    if (privateKey == null) {
        try {/*from  ww w  .j  ava2 s.  co  m*/
            File file = new File("./data/server.key");
            if (file.exists()) {
                FileInputStream fileInputStream = new FileInputStream(file);
                try {
                    privateKey = SerializationUtils.deserialize(fileInputStream);
                } finally {
                    fileInputStream.close();
                }
            } else {
                KeyGenerator keyGen = KeyGenerator.getInstance("AES");
                keyGen.init(new SecureRandom());
                SecretKey key = keyGen.generateKey();
                FileOutputStream outputStream = new FileOutputStream(file);
                try {
                    SerializationUtils.serialize(key, outputStream);
                } finally {
                    outputStream.close();
                }
                privateKey = key;
            }
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
    return privateKey;
}

From source file:net.spfbl.core.User.java

public static synchronized void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/user.map");
    if (file.exists()) {
        try {//from  www .j  a v a 2  s  . c o  m
            HashMap<String, Object> map;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                map = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String key : map.keySet()) {
                Object value = map.get(key);
                if (value instanceof User) {
                    User user = (User) value;
                    if (user.locale == null) {
                        user.locale = Core.getDefaultLocale(user.email);
                    }
                    for (long time2 : user.getTimeSet()) {
                        Query query = user.getQuery(time2);
                        if (query.CHANGED == null) {
                            query.CHANGED = new BinarySemaphore(!query.STORED);
                        }
                    }
                    MAP.put(key, user);
                }
            }
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

From source file:net.spfbl.data.Block.java

public static void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/block.set");
    if (file.exists()) {
        try {//from ww  w.  j  a va  2 s .c  o  m
            Set<String> set;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                set = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String token : set) {
                String client;
                String identifier;
                if (token.contains(":")) {
                    int index = token.indexOf(':');
                    client = token.substring(0, index);
                    if (Domain.isEmail(client)) {
                        identifier = token.substring(index + 1);
                    } else {
                        client = null;
                        identifier = token;
                    }
                } else {
                    client = null;
                    identifier = token;
                }
                if (identifier.startsWith("CIDR=")) {
                    CIDR.addExact(client, identifier);
                } else if (identifier.startsWith("WHOIS/")) {
                    WHOIS.addExact(client, identifier);
                } else if (identifier.startsWith("DNSBL=")) {
                    DNSBL.addExact(client, identifier);
                } else if (identifier.startsWith("REGEX=")) {
                    REGEX.addExact(client, identifier);
                } else {
                    SET.addExact(token);
                }
            }
            CHANGED = false;
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
    time = System.currentTimeMillis();
    file = new File("./data/block.map");
    if (file.exists()) {
        try {
            Map<String, Long> map;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                map = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String token : map.keySet()) {
                Long last = map.get(token);
                if (last != null) {
                    SET.putExact(token, last);
                }
            }
            CHANGED = false;
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

From source file:net.spfbl.data.Generic.java

public static void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/generic.map");
    if (file.exists()) {
        try {//from  www .j  a va 2 s.c  o  m
            Map<String, Boolean> map;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                map = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String token : map.keySet()) {
                boolean dyn = map.get(token);
                if (token.startsWith("REGEX=")) {
                    REGEX.addExact(token);
                } else {
                    MAP.putExact(token, dyn);
                }
            }
            CHANGED = false;
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    } else if ((file = new File("./data/generic.set")).exists()) {
        try {
            Set<String> set;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                set = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String token : set) {
                if (token.startsWith("REGEX=")) {
                    REGEX.addExact(token);
                } else {
                    MAP.addGenericExact(token);
                }
            }
            CHANGED = false;
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

From source file:net.spfbl.data.Ignore.java

public static void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/ignore.set");
    if (file.exists()) {
        try {/*from ww  w  .  j  a  v a  2  s  . co m*/
            Set<String> set;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                set = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            // Processo temporrio de transio.
            for (String token : set) {
                if ((token = normalizeTokenCIDR(token)) != null) {
                    String client;
                    String identifier;
                    if (token.contains(":")) {
                        int index = token.indexOf(':');
                        client = token.substring(0, index);
                        identifier = token.substring(index + 1);
                    } else {
                        client = null;
                        identifier = token;
                    }
                    if (Subnet.isValidCIDR(identifier)) {
                        identifier = "CIDR=" + Subnet.normalizeCIDR(identifier);
                    }
                    try {
                        if (client == null) {
                            addExact(identifier);
                        } else {
                            addExact(client + ':' + identifier);
                        }
                    } catch (ProcessException ex) {
                        Server.logDebug("IGNORE CIDR " + identifier + " " + ex.getErrorMessage());
                    }
                }
            }
            CHANGED = false;
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

From source file:net.spfbl.data.NoReply.java

public static void load() {
    long time = System.currentTimeMillis();
    File file = new File("./data/noreply.set");
    if (file.exists()) {
        try {/*  w w w.  j  a  v a 2  s .  co  m*/
            Set<String> set;
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                set = SerializationUtils.deserialize(fileInputStream);
            } finally {
                fileInputStream.close();
            }
            for (String token : set) {
                addExact(token);
            }
            CHANGED = false;
            Server.logLoad(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}