I'm attempting to develop a simple online editor that allows for real-time collaboration (written in Java). In this editor, I want clients to be able to edit the source code at arbitrary points (e.g. add the letter 'd' to the source code file at row 11, column 20). I'm not sure how to design these source code file objects in an efficient way, while still allowing for letter-by-letter client-server synchronization (similar to how Google Docs works).
I considered using a RandomAccessFile, but after reading this post, I don't think that would be an efficient approach. Inserting a letter near the beginning of the file would involve changing everything after it.
My current plan is to represent both the source files on the server and client using a StringBuilder object and its insert/delete/append methods. On the server-side, this StringBuilder would be converted to an actual file as necessary.
I'm curious as to whether there might be a better approach for solving this problem. Any ideas?