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

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

Introduction

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

Prototype

public static void serialize(final Serializable obj, final OutputStream outputStream) 

Source Link

Document

Serializes an Object to the specified stream.

The stream will be closed once the object is written.

Usage

From source file:atg.tools.dynunit.test.util.FileUtil.java

private static void persistConfigCache() throws IOException {
    FileUtils.touch(configFilesLastModifiedCache);
    final OutputStream out = new BufferedOutputStream(new FileOutputStream(configFilesLastModifiedCache));
    SerializationUtils.serialize(configFilesLastModified, out);
}

From source file:com.alta189.deskbin.util.KeyStore.java

private String toString(Serializable o) {
    ByteArrayOutputStream baos = null;
    ObjectOutputStream oos = null;
    try {/*from   ww w  .j a  v a 2s.c  om*/
        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        SerializationUtils.serialize(o, oos);
        return new String(Base64Coder.encode(baos.toByteArray()));
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(oos);
        IOUtils.closeQuietly(baos);
    }
    return null;
}

From source file:atg.tools.dynunit.test.util.FileUtil.java

/**
 * @see org.apache.commons.lang3.SerializationUtils#serialize(java.io.Serializable, java.io.OutputStream)
 *///from   w w  w  .  j av  a 2  s  . c  om
@Deprecated
public static void serialize(@NotNull final File file, final Object o) throws IOException {
    Validate.isInstanceOf(Serializable.class, o);
    final Serializable object = (Serializable) o;
    SerializationUtils.serialize(object, new FileOutputStream(file));
}

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

public static void store() {
    if (CHANGED) {
        try {/*from w  ww  . j  a va2  s .co  m*/
            //                Server.logTrace("storing analise.set");
            long time = System.currentTimeMillis();
            TreeSet<Analise> set = getAnaliseCloneSet();
            File file = new File("./data/analise.set");
            FileOutputStream outputStream = new FileOutputStream(file);
            try {
                SerializationUtils.serialize(set, outputStream);
                // Atualiza flag de atualizao.
                CHANGED = false;
            } finally {
                outputStream.close();
            }
            Server.logStore(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
        try {
            //                Server.logTrace("storing cluster.map");
            long time = System.currentTimeMillis();
            TreeMap<String, Short[]> map = getClusterMap();
            File file = new File("./data/cluster.map");
            FileOutputStream outputStream = new FileOutputStream(file);
            try {
                SerializationUtils.serialize(map, outputStream);
            } finally {
                outputStream.close();
            }
            Server.logStore(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

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

public static void store() {
    if (CHANGED) {
        try {// www .ja  va 2 s .c  o m
            //                Server.logTrace("storing client.map");
            long time = System.currentTimeMillis();
            HashMap<String, Client> map = getCloneMap();
            for (String key : map.keySet()) {
                Client value = map.get(key);
                if (value.administrator) {
                    // Compatibilidade com verses anteriores.
                    value.permission = Permission.ALL;
                }
            }
            File file = new File("./data/client.map");
            FileOutputStream outputStream = new FileOutputStream(file);
            try {
                SerializationUtils.serialize(map, outputStream);
                // Atualiza flag de atualizao.
                CHANGED = false;
            } finally {
                outputStream.close();
            }
            Server.logStore(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

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

public static void store() {
    if (isChanged()) {
        try {/*from www .ja  v a  2  s .com*/
            //                Server.logTrace("storing defer.map");
            long time = System.currentTimeMillis();
            File file = new File("./data/defer.map");
            HashMap<String, Defer> map = getMap();
            FileOutputStream outputStream = new FileOutputStream(file);
            try {
                SerializationUtils.serialize(map, outputStream);
                setStored();
            } finally {
                outputStream.close();
            }
            Server.logStore(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

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

public static void main(String[] args) throws Exception {
    File file = new File("C:\\Users\\Leandro\\Desktop\\amostra.txt");
    BufferedReader reader = new BufferedReader(new FileReader(file));
    int[] frequency = new int[256];
    int count = 0;
    String line;/*from  www.j a  v  a  2 s .c o  m*/
    while ((line = reader.readLine()) != null) {
        line = " " + line;
        if (count % 3 == 0) {
            line += '\0';
        }
        char[] input = line.toCharArray();
        for (int i = 0; i < input.length; i++) {
            frequency[input[i]]++;
        }
        count++;
    }
    reader.close();
    Huffman huffman = buildTree(frequency);
    FileOutputStream outputStream = new FileOutputStream("C:\\Users\\Leandro\\Desktop\\huffman.obj");
    SerializationUtils.serialize(huffman, outputStream);
    outputStream.close();
}

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

public static void store() {
    if (CHANGED) {
        try {//from ww  w  .ja v  a2  s .co  m
            //                Server.logTrace("storing peer.map");
            long time = System.currentTimeMillis();
            HashMap<String, Peer> map = getMap();
            File file = new File("./data/peer.map");
            FileOutputStream outputStream = new FileOutputStream(file);
            try {
                SerializationUtils.serialize(map, outputStream);
                // Atualiza flag de atualizao.
                CHANGED = false;
            } finally {
                outputStream.close();
            }
            Server.logStore(time, file);
        } catch (Exception ex) {
            Server.logError(ex);
        }
    }
}

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

public static void store() {
    if (isChanged()) {
        try {//w ww .  j  a v  a 2  s  .com
            //                Server.logTrace("storing reverse.map");
            long time = System.currentTimeMillis();
            File file = new File("./data/reverse.map");
            HashMap<String, Reverse> map = getMap();
            FileOutputStream outputStream = new FileOutputStream(file);
            try {
                SerializationUtils.serialize(map, outputStream);
                setStored();
            } finally {
                outputStream.close();
            }
            Server.logStore(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 .ja  v  a  2 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;
}