Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.xpenguinx.factioncheck;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.List;
- public class SerializationUtil {
- public static List<Check> deserializeCheck(File file) {
- List<Check> arraylist= new ArrayList();
- ObjectInputStream ois = null;
- FileInputStream fin = null;
- try{
- fin = new FileInputStream(file.getPath());
- while (fin.available() > 0) {
- arraylist.add((Check) ois.readObject());
- }
- }catch (EOFException e) {
- } finally {
- try {
- if (fin != null)
- if (ois != null)
- ois.close();
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- return arraylist;
- }
- }
- public static void serializeCheck(List<Check> collection, File file) {
- FileOutputStream fout = null;
- ObjectOutputStream oos = null;
- if(collection == null) return;
- try {
- fout = new FileOutputStream(file.getPath());
- oos = new ObjectOutputStream(fout);
- for(Check check : collection) {
- oos.writeObject(check);
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- } finally {
- if (fout != null) {
- try {
- fout.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (oos != null) {
- try {
- oos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement