Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Admin implements Serializable{
  4. private static final long serialVersionUID = 613659699548582156L;
  5. private String user;
  6. private String password;
  7.  
  8. @Override
  9. public String toString() {
  10. return "{class:'Admin'" +
  11. ", user:'" + user + ''' +
  12. ", password:'" + password + ''' +
  13. '}';
  14. }
  15.  
  16. public Admin(String user, String password) {
  17. this.user = user;
  18. this.password = password;
  19. }
  20.  
  21. public Admin() {
  22.  
  23. }
  24.  
  25. public String getUser() {
  26.  
  27. return user;
  28. }
  29.  
  30. public void setUser(String user) {
  31. this.user = user;
  32. }
  33.  
  34. public String getPassword() {
  35. return password;
  36. }
  37.  
  38. public void setPassword(String password) {
  39. this.password = password;
  40. }
  41.  
  42.  
  43. public boolean equals(Object o){
  44. if (o == null) {
  45. return false;
  46. }
  47. if (this == o) {
  48. return true;
  49. }
  50. Admin admin = (Admin) o;
  51. return (user != null ? user.equals(admin.getUser()) : admin.getUser() == null) &&
  52. (password != null ? password.equals(admin.getPassword()) : admin.getPassword() == null);
  53. }
  54.  
  55. public static void main(String[] args) {
  56. //write object
  57. // try {
  58. // ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(Admin.class.getClassLoader().getResource("admin.out").getPath()));
  59. // Admin a = new Admin("longlongago", "longlongago");
  60. // out.writeObject(a);
  61. // out.flush();
  62. // out.close();
  63. // } catch (IOException e) {
  64. // e.printStackTrace();
  65. // }
  66.  
  67. //read object
  68. try {
  69. ObjectInputStream in = new ObjectInputStream(Admin.class.getClassLoader().getResourceAsStream("admin.out"));
  70. Admin a = (Admin) in.readObject();
  71. System.out.println(a.toString());
  72. } catch (ClassNotFoundException e) {
  73. e.printStackTrace();
  74. } catch (IOException e) {
  75. e.printStackTrace();
  76. }
  77.  
  78. }
  79. }
  80.  
  81. java.io.EOFException
  82. at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2353)
  83. at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2822)
  84. at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804)
  85. at java.io.ObjectInputStream.<init>(ObjectInputStream.java:301)
  86. at pw.loveyouforever.Model.Admin.main(Admin.java:68)
  87. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  88. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  89. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  90. at java.lang.reflect.Method.invoke(Method.java:498)
  91. at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement