Skip to content

Commit 7d19f61

Browse files
committed
Update
1 parent 8d8bc34 commit 7d19f61

13 files changed

+155
-12
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package yetmorecode.file;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.IOException;
7+
import java.nio.ByteBuffer;
8+
import java.nio.ByteOrder;
9+
10+
public class BinaryFileInputStream extends FileInputStream {
11+
12+
private ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN;
13+
14+
public BinaryFileInputStream(String name) throws FileNotFoundException {
15+
super(name);
16+
}
17+
18+
public BinaryFileInputStream(String name, ByteOrder order) throws FileNotFoundException {
19+
super(name);
20+
byteOrder = order;
21+
}
22+
23+
public BinaryFileInputStream(File file) throws FileNotFoundException {
24+
super(file);
25+
}
26+
27+
public BinaryFileInputStream(File file, ByteOrder order) throws FileNotFoundException {
28+
this(file);
29+
byteOrder = order;
30+
}
31+
32+
public int readByte(long offset) throws IOException {
33+
var old = position(offset);
34+
int ret = readByte();
35+
position(old);
36+
return ret;
37+
}
38+
39+
public int readByte() throws IOException {
40+
return read();
41+
}
42+
43+
public short readShort(long offset) throws IOException {
44+
var old = position(offset);
45+
var i = readShort();
46+
position(old);
47+
return i;
48+
}
49+
50+
public short readShort() throws IOException {
51+
byte[] bytes = readNBytes(2);
52+
ByteBuffer bb = ByteBuffer.wrap(bytes);
53+
bb.order(byteOrder);
54+
return bb.getShort();
55+
}
56+
57+
public int readInt(long offset) throws IOException {
58+
var old = position(offset);
59+
var i = readInt();
60+
position(old);
61+
return i;
62+
}
63+
64+
public int readInt() throws IOException {
65+
byte[] bytes = readNBytes(4);
66+
ByteBuffer bb = ByteBuffer.wrap(bytes);
67+
bb.order(byteOrder);
68+
return bb.getInt();
69+
}
70+
71+
public float readFloat(long offset) throws IOException {
72+
var old = position(offset);
73+
var i = readFloat();
74+
position(old);
75+
return i;
76+
}
77+
78+
public float readFloat() throws IOException {
79+
byte[] bytes = readNBytes(4);
80+
ByteBuffer bb = ByteBuffer.wrap(bytes);
81+
bb.order(byteOrder);
82+
return bb.getFloat();
83+
}
84+
85+
public String readString(long offset, int size) throws IOException {
86+
var old = position(offset);
87+
var i = readString(size);
88+
position(old);
89+
return i;
90+
}
91+
92+
public String readString(int size) throws IOException {
93+
return new String(readNBytes(size));
94+
}
95+
96+
public long position(long offset) throws IOException {
97+
var old = getChannel().position();
98+
getChannel().position(offset);
99+
return old;
100+
}
101+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package yetmorecode.file;
2+
3+
import java.io.FileNotFoundException;
4+
import java.io.FileOutputStream;
5+
6+
public class BinaryFileOutputStream extends FileOutputStream {
7+
8+
public BinaryFileOutputStream(String name) throws FileNotFoundException {
9+
super(name);
10+
}
11+
12+
}

src/yetmorecode/format/exception/InvalidHeaderException.java renamed to src/yetmorecode/file/exception/InvalidHeaderException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package yetmorecode.format.exception;
1+
package yetmorecode.file.exception;
22

33
/**
44
* An exception class to handle encountering

src/yetmorecode/format/lx/LeObjectPageTableEntry.java renamed to src/yetmorecode/file/format/lx/LeObjectPageTableEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package yetmorecode.format.lx;
1+
package yetmorecode.file.format.lx;
22

33
/**
44
* The Object page table provides information about a logical page in an object.

src/yetmorecode/format/lx/LxExecutable.java renamed to src/yetmorecode/file/format/lx/LxExecutable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package yetmorecode.format.lx;
1+
package yetmorecode.file.format.lx;
22

33
import java.util.ArrayList;
44

5-
import yetmorecode.format.mz.MzHeader;
5+
import yetmorecode.file.format.mz.MzHeader;
66

77
public class LxExecutable {
88
/**

src/yetmorecode/format/lx/LxFixupRecord.java renamed to src/yetmorecode/file/format/lx/LxFixupRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package yetmorecode.format.lx;
1+
package yetmorecode.file.format.lx;
22

33
import java.util.ArrayList;
44

src/yetmorecode/format/lx/LxHeader.java renamed to src/yetmorecode/file/format/lx/LxHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package yetmorecode.format.lx;
1+
package yetmorecode.file.format.lx;
22

33
/**
44
* LX/LE/LC executable module header

src/yetmorecode/format/lx/LxObjectPageTableEntry.java renamed to src/yetmorecode/file/format/lx/LxObjectPageTableEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package yetmorecode.format.lx;
1+
package yetmorecode.file.format.lx;
22

33
/**
44
* The Object page table provides information about a logical page in an object.

src/yetmorecode/format/lx/ObjectPageTableEntry.java renamed to src/yetmorecode/file/format/lx/ObjectPageTableEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package yetmorecode.format.lx;
1+
package yetmorecode.file.format.lx;
22

33
public interface ObjectPageTableEntry {
44
public int getOffset();

src/yetmorecode/format/lx/ObjectTableEntry.java renamed to src/yetmorecode/file/format/lx/ObjectTableEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package yetmorecode.format.lx;
1+
package yetmorecode.file.format.lx;
22

33
/**
44
* LX Executable Object Table Entry<br>

0 commit comments

Comments
 (0)