Welcome to
Java Ranch, Sophie.
I just finished implementing my own readRecord() method this past Saturday.
These would be my comments:
1. Calculating the record position is something you will do also in the update and delete methods. Therefore you might like to refactor that.
2. I like your approach of reading the whole record into a ByteArrayInputStream, notwithstanding, at the end you have to parse it anyway. You could have done the parsing directly from the file, probably saving a few nanoseconds. The only real advantage I see in this approach is the fact that you read the whole bunch of bytes in a sole operation, reducing the possibilities of a dirty read (if another thread modifies the record while you are reading it).
3. Finally, I guess your database variable is a RandomAccessFile. Have you wondered what would happen if two threads try to read a record concurrently. Let's say thread one just seek the record 1, thread two comes immediately after it, before thread 1 performs the readFully operation, thread 2 seeks a new position. Then thread1 read the position sought by thread 2 and the read is corrupted.
4. In the URLyBird specification that I download, a couple of paragraphs after the DBAccess interface definition says:
"Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.". Since the readRecord throws RecordNotFoundException you may seriously consider evaluating the delete flag.
5. I do not recommend to catch the IOException and do nothing. In this case you either throw a RecordNotFoundException or at least, log the exception for future review and evaluation.
6. Consider adding some logging to your database class. Something that might really help you in future stages of your programming to detect bugs and see what you code is doing. I added logging to determine when a read a search or an update happens, when a file is opened, when validations result successful. There I can see the executing thread, the class, the method and some message with the details of what the application is doing. That could indeed help you in future phases of your project.
7. You may consider throwing IllegalArgumentException when the record number is not between 0 and Long.MAX_VALUE.
8. You may consider accepting the default encoding as parameter when you create your database object, probably read from the suncertify.properties file.
9. If you are using JDK 1.5 you may consider using the enhanced for instead of using iterators. That adds code clarity.
10. Finally, when you have to skip some bytes in an Stream, as you do in the first iteration of your read loop, instead of wasting an iteration, use the skip(int bytes) method.
I hope this helps!
[ July 25, 2006: Message edited by: Edwin Dalorzo ]