import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import util.file.InvalidFileFormatException; import string.StrUtil; class BoardEntry { static final String fieldSep = " :: "; private int authorId; private int authorRank; private boolean authorIsPlayer; private String header; private String body; BoardEntry(int id, int rank, boolean player, String authorName, String date, String title, String bd) { authorId = id; authorRank = rank; authorIsPlayer = player; header = StrUtil.rightPad(authorName, Client.MAX_NAME_LENGTH) + fieldSep + date + fieldSep + title; body = bd; } BoardEntry(BufferedReader reader) throws InvalidFileFormatException { try { if (!reader.ready()) throw new InvalidFileFormatException(); authorId = Integer.parseInt(reader.readLine()); authorRank = Integer.parseInt(reader.readLine()); authorIsPlayer = Boolean.getBoolean(reader.readLine()); header = reader.readLine(); body = StrUtil.readDescription(reader); } catch(IOException e) { throw new InvalidFileFormatException(); } } void save(BufferedWriter writer) throws IOException { writer.write(String.valueOf(authorId)); writer.newLine(); writer.write(String.valueOf(authorRank)); writer.newLine(); writer.write(String.valueOf(authorIsPlayer)); writer.newLine(); writer.write(header); writer.newLine(); StrUtil.writeDescription(writer, body); } int getAuthorId() { return authorId; } int getAuthorRank() { return authorRank; } boolean authorIsPlayer() { return authorIsPlayer; } String getHeader() { return header; } String getBody() { return body; } }