diff --git a/src/me/topchetoeu/jscript/filesystem/Buffer.java b/src/me/topchetoeu/jscript/filesystem/Buffer.java index 3a77157..4df364a 100644 --- a/src/me/topchetoeu/jscript/filesystem/Buffer.java +++ b/src/me/topchetoeu/jscript/filesystem/Buffer.java @@ -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; + } } diff --git a/src/me/topchetoeu/jscript/filesystem/File.java b/src/me/topchetoeu/jscript/filesystem/File.java index 487b5dc..643c2f1 100644 --- a/src/me/topchetoeu/jscript/filesystem/File.java +++ b/src/me/topchetoeu/jscript/filesystem/File.java @@ -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) { diff --git a/src/me/topchetoeu/jscript/filesystem/MemoryFilesystem.java b/src/me/topchetoeu/jscript/filesystem/MemoryFilesystem.java index 7db85db..2c8ec3e 100644 --- a/src/me/topchetoeu/jscript/filesystem/MemoryFilesystem.java +++ b/src/me/topchetoeu/jscript/filesystem/MemoryFilesystem.java @@ -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);