Skip to content

Commit

Permalink
Add Multi Readers for more types
Browse files Browse the repository at this point in the history
I didn't add ReadInts but whatever 💀
  • Loading branch information
SuperHackio committed Mar 9, 2024
1 parent 67a1d8c commit 4cfbec2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/whitehole/io/ExternalFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ public byte[] readBytes(int length) throws IOException {
return ret;
}

@Override
public short[] readShorts(int length) throws IOException {
short[] ret = new short[length];
for (int i = 0; i < length; i++)
ret[i] = readShort();
return ret;
}

@Override
public float[] readFloats(int length) throws IOException {
float[] ret = new float[length];
for (int i = 0; i < length; i++)
ret[i] = readFloat();
return ret;
}

@Override
public void writeByte(byte val) throws IOException {
file.writeByte(val);
Expand Down
2 changes: 2 additions & 0 deletions src/whitehole/io/FileBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface FileBase {
public float readFloat() throws IOException;
public String readString(String encoding, int length) throws IOException;
public byte[] readBytes(int length) throws IOException;
public short[] readShorts(int length) throws IOException;
public float[] readFloats(int length) throws IOException;

public void writeByte(byte val) throws IOException;
public void writeShort(short val) throws IOException;
Expand Down
16 changes: 16 additions & 0 deletions src/whitehole/io/MemoryFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ public byte[] readBytes(int length) throws IOException {
return ret;
}

@Override
public short[] readShorts(int length) throws IOException {
short[] ret = new short[length];
for (int i = 0; i < length; i++)
ret[i] = readShort();
return ret;
}

@Override
public float[] readFloats(int length) throws IOException {
float[] ret = new float[length];
for (int i = 0; i < length; i++)
ret[i] = readFloat();
return ret;
}


@Override
public void writeByte(byte val) throws IOException {
Expand Down

0 comments on commit 4cfbec2

Please sign in to comment.