Update document handling (WIP)

This commit is contained in:
MrLetsplay 2024-06-05 20:17:56 +02:00
parent 5634a1e555
commit 0a603a41df
Signed by: mr
SSH Key Fingerprint: SHA256:0zWNiRisbQ4dq/CCQAaMLoF3UfkF5wKPXO7DcjfFBEU

View File

@ -23,7 +23,7 @@ public class SharedDocument implements MessageListener {
private int lamport; private int lamport;
private Set<DocumentListener> listeners; private Set<DocumentListener> listeners;
public SharedDocument(RemoteConnection connection, String path, String initialContents) { public SharedDocument(RemoteConnection connection, String path, byte[] initialContents) {
this.connection = connection; this.connection = connection;
this.charBag = new ArrayCharBag(); this.charBag = new ArrayCharBag();
this.path = path; this.path = path;
@ -32,10 +32,14 @@ public class SharedDocument implements MessageListener {
charBag.add(Char.START_OF_DOCUMENT); charBag.add(Char.START_OF_DOCUMENT);
charBag.add(Char.END_OF_DOCUMENT); charBag.add(Char.END_OF_DOCUMENT);
if(initialContents != null && !initialContents.isEmpty()) { if(initialContents != null && initialContents.length > 0) {
insert(0, initialContents, Identifier.DEFAULT_SITE); insert(0, initialContents, Identifier.DEFAULT_SITE);
} }
} }
public SharedDocument(RemoteConnection connection, String path, String initialContents) {
this(connection, path, initialContents.getBytes(StandardCharsets.UTF_8));
}
public SharedDocument(RemoteConnection connection, String path) { public SharedDocument(RemoteConnection connection, String path) {
this(connection, path, null); this(connection, path, null);