feat: improve Bufffer API

This commit is contained in:
TopchetoEU 2023-11-26 11:51:32 +02:00
parent 4f22e76d2b
commit 27162ef8ac
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
3 changed files with 14 additions and 2 deletions

View File

@ -24,6 +24,10 @@ public class Buffer {
return n;
}
public void append(byte b) {
write(length, new byte[] { b });
}
public byte[] data() {
var res = new byte[length];
System.arraycopy(this.data, 0, res, 0, length);
@ -38,4 +42,12 @@ public class Buffer {
this.length = data.length;
System.arraycopy(data, 0, this.data, 0, data.length);
}
public Buffer(int capacity) {
this.data = new byte[capacity];
this.length = 0;
}
public Buffer() {
this.data = new byte[128];
this.length = 0;
}
}

View File

@ -21,7 +21,7 @@ public interface File {
return new String(res);
}
default String readLine() {
var res = new Buffer(new byte[0]);
var res = new Buffer();
var buff = new byte[1];
while (true) {

View File

@ -24,7 +24,7 @@ public class MemoryFilesystem implements Filesystem {
if (!folders.contains(_path.getParent())) throw new FilesystemException(path, FSCode.DOESNT_EXIST);
if (folders.contains(_path) || files.containsKey(_path)) throw new FilesystemException(path, FSCode.ALREADY_EXISTS);
if (folders.contains(_path)) throw new FilesystemException(path, FSCode.ALREADY_EXISTS);
files.put(_path, new Buffer(new byte[0]));
files.put(_path, new Buffer());
break;
case FOLDER:
if (!folders.contains(_path.getParent())) throw new FilesystemException(path, FSCode.DOESNT_EXIST);