user.java
来自「java 完全探索的随书源码」· Java 代码 · 共 85 行
JAVA
85 行
import java.io.*;public class User implements Serializable{ // Private instance variables private String userName = null; private String password = null; // Constructor public User( String name, String passwd ) { super(); userName = name; password = passwd; } //Public accessors public String getUserName() { return userName; } public void setUserName( String name ) { userName = name; } public String getPassword() { return password; } public void setPassword( String passwd ) { password = passwd; } // Implement the neccessary writeObject method for handling the // serialization of this object other than the default way private void writeObject( ObjectOutputStream out ) throws IOException { String userNameEncrypted = encryptStr( getUserName() ); String passwordEncrypted = encryptStr( getPassword() ); out.writeObject( userNameEncrypted ); out.writeObject( passwordEncrypted ); } // Implement the neccessary readObject method for handling the // serialization of this object other than the default way private void readObject( ObjectInputStream in ) throws IOException, ClassNotFoundException { String userNameEncrypted = (String)in.readObject(); String passwordEncrypted = (String)in.readObject(); setUserName( decryptStr( userNameEncrypted )); setPassword( decryptStr( passwordEncrypted )); } // Extremely simple encryption routine just do show the point // of something being done with the data public String encryptStr( String normalStr ) { StringBuffer buf = new StringBuffer( normalStr ); buf.reverse(); return buf.toString(); } // Simple decryption routine public String decryptStr( String encryptStr ) { StringBuffer buf = new StringBuffer( encryptStr ); buf.reverse(); return buf.toString(); } // Override the toString() method from Object to pretty print a User object public String toString() { StringBuffer strBuf = new StringBuffer( "User: " ); strBuf.append( getUserName() ); strBuf.append( " Password: " ); strBuf.append( getPassword() ); return strBuf.toString(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?