FileDocCategorySizeDatePackage
TextToDBM.javaAPI DocExample1093Fri Oct 12 20:02:16 BST 2001jabadot

TextToDBM

public class TextToDBM extends Object
Convert the database from text form to DBM form.

Fields Summary
protected static final String
TEXT_NAME
protected static final String
DBM_NAME
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] fn)


	       
		BufferedReader is = new BufferedReader(new FileReader(TEXT_NAME));
		DBM db = new DBM(DBM_NAME);

		String line;
		while ((line = is.readLine()) != null) {
			//name:password:fullname:City:Prov:Country:privs

			if (line.startsWith("#")) {		// comment
				continue;
			}

			StringTokenizer st =
				new StringTokenizer(line, ":");
			String nick = st.nextToken();
			String pass = st.nextToken();
			String full = st.nextToken();
			String email = st.nextToken();
			String city = st.nextToken();
			String prov = st.nextToken();
			String ctry = st.nextToken();
			User u = new User(nick, pass, full, email,
				city, prov, ctry);
			String privs = st.nextToken();
			if (privs.indexOf("A") != -1) {
				u.setAdminPrivileged(true);
			}
			db.store(nick, u);
		}
		db.close();