feat: improve Bufffer API
This commit is contained in:
parent
4f22e76d2b
commit
27162ef8ac
@ -24,6 +24,10 @@ public class Buffer {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void append(byte b) {
|
||||||
|
write(length, new byte[] { b });
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] data() {
|
public byte[] data() {
|
||||||
var res = new byte[length];
|
var res = new byte[length];
|
||||||
System.arraycopy(this.data, 0, res, 0, length);
|
System.arraycopy(this.data, 0, res, 0, length);
|
||||||
@ -38,4 +42,12 @@ public class Buffer {
|
|||||||
this.length = data.length;
|
this.length = data.length;
|
||||||
System.arraycopy(data, 0, this.data, 0, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public interface File {
|
|||||||
return new String(res);
|
return new String(res);
|
||||||
}
|
}
|
||||||
default String readLine() {
|
default String readLine() {
|
||||||
var res = new Buffer(new byte[0]);
|
var res = new Buffer();
|
||||||
var buff = new byte[1];
|
var buff = new byte[1];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -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.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) || files.containsKey(_path)) throw new FilesystemException(path, FSCode.ALREADY_EXISTS);
|
||||||
if (folders.contains(_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;
|
break;
|
||||||
case FOLDER:
|
case FOLDER:
|
||||||
if (!folders.contains(_path.getParent())) throw new FilesystemException(path, FSCode.DOESNT_EXIST);
|
if (!folders.contains(_path.getParent())) throw new FilesystemException(path, FSCode.DOESNT_EXIST);
|
||||||
|
Loading…
Reference in New Issue
Block a user