Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package me.xpenguinx.factioncheck;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class SerializationUtil {
  8.  
  9. public static List<Check> deserializeCheck(File file) {
  10. List<Check> arraylist= new ArrayList();
  11. ObjectInputStream ois = null;
  12. FileInputStream fin = null;
  13. try{
  14. fin = new FileInputStream(file.getPath());
  15. while (fin.available() > 0) {
  16. arraylist.add((Check) ois.readObject());
  17. }
  18.  
  19. }catch (EOFException e) {
  20. } finally {
  21. try {
  22.  
  23. if (fin != null)
  24. if (ois != null)
  25. ois.close();
  26. } catch (IOException ex) {
  27. ex.printStackTrace();
  28. }
  29. return arraylist;
  30. }
  31. }
  32.  
  33. public static void serializeCheck(List<Check> collection, File file) {
  34.  
  35. FileOutputStream fout = null;
  36. ObjectOutputStream oos = null;
  37. if(collection == null) return;
  38. try {
  39.  
  40. fout = new FileOutputStream(file.getPath());
  41. oos = new ObjectOutputStream(fout);
  42. for(Check check : collection) {
  43. oos.writeObject(check);
  44. }
  45. } catch (Exception ex) {
  46.  
  47. ex.printStackTrace();
  48.  
  49. } finally {
  50.  
  51. if (fout != null) {
  52. try {
  53. fout.close();
  54. } catch (IOException e) {
  55. e.printStackTrace();
  56. }
  57. }
  58.  
  59. if (oos != null) {
  60. try {
  61. oos.close();
  62. } catch (IOException e) {
  63. e.printStackTrace();
  64. }
  65. }
  66.  
  67. }
  68. }
  69.  
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement