-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d8bc34
commit 7d19f61
Showing
13 changed files
with
155 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package yetmorecode.file; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
public class BinaryFileInputStream extends FileInputStream { | ||
|
||
private ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN; | ||
|
||
public BinaryFileInputStream(String name) throws FileNotFoundException { | ||
super(name); | ||
} | ||
|
||
public BinaryFileInputStream(String name, ByteOrder order) throws FileNotFoundException { | ||
super(name); | ||
byteOrder = order; | ||
} | ||
|
||
public BinaryFileInputStream(File file) throws FileNotFoundException { | ||
super(file); | ||
} | ||
|
||
public BinaryFileInputStream(File file, ByteOrder order) throws FileNotFoundException { | ||
this(file); | ||
byteOrder = order; | ||
} | ||
|
||
public int readByte(long offset) throws IOException { | ||
var old = position(offset); | ||
int ret = readByte(); | ||
position(old); | ||
return ret; | ||
} | ||
|
||
public int readByte() throws IOException { | ||
return read(); | ||
} | ||
|
||
public short readShort(long offset) throws IOException { | ||
var old = position(offset); | ||
var i = readShort(); | ||
position(old); | ||
return i; | ||
} | ||
|
||
public short readShort() throws IOException { | ||
byte[] bytes = readNBytes(2); | ||
ByteBuffer bb = ByteBuffer.wrap(bytes); | ||
bb.order(byteOrder); | ||
return bb.getShort(); | ||
} | ||
|
||
public int readInt(long offset) throws IOException { | ||
var old = position(offset); | ||
var i = readInt(); | ||
position(old); | ||
return i; | ||
} | ||
|
||
public int readInt() throws IOException { | ||
byte[] bytes = readNBytes(4); | ||
ByteBuffer bb = ByteBuffer.wrap(bytes); | ||
bb.order(byteOrder); | ||
return bb.getInt(); | ||
} | ||
|
||
public float readFloat(long offset) throws IOException { | ||
var old = position(offset); | ||
var i = readFloat(); | ||
position(old); | ||
return i; | ||
} | ||
|
||
public float readFloat() throws IOException { | ||
byte[] bytes = readNBytes(4); | ||
ByteBuffer bb = ByteBuffer.wrap(bytes); | ||
bb.order(byteOrder); | ||
return bb.getFloat(); | ||
} | ||
|
||
public String readString(long offset, int size) throws IOException { | ||
var old = position(offset); | ||
var i = readString(size); | ||
position(old); | ||
return i; | ||
} | ||
|
||
public String readString(int size) throws IOException { | ||
return new String(readNBytes(size)); | ||
} | ||
|
||
public long position(long offset) throws IOException { | ||
var old = getChannel().position(); | ||
getChannel().position(offset); | ||
return old; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package yetmorecode.file; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
|
||
public class BinaryFileOutputStream extends FileOutputStream { | ||
|
||
public BinaryFileOutputStream(String name) throws FileNotFoundException { | ||
super(name); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...mat/exception/InvalidHeaderException.java → ...ile/exception/InvalidHeaderException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ode/format/lx/LeObjectPageTableEntry.java → ...ile/format/lx/LeObjectPageTableEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/yetmorecode/format/lx/LxExecutable.java → ...morecode/file/format/lx/LxExecutable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/yetmorecode/format/lx/LxFixupRecord.java → ...orecode/file/format/lx/LxFixupRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package yetmorecode.format.lx; | ||
package yetmorecode.file.format.lx; | ||
|
||
import java.util.ArrayList; | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/yetmorecode/format/lx/LxHeader.java → src/yetmorecode/file/format/lx/LxHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package yetmorecode.format.lx; | ||
package yetmorecode.file.format.lx; | ||
|
||
/** | ||
* LX/LE/LC executable module header | ||
|
2 changes: 1 addition & 1 deletion
2
...ode/format/lx/LxObjectPageTableEntry.java → ...ile/format/lx/LxObjectPageTableEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ecode/format/lx/ObjectPageTableEntry.java → .../file/format/lx/ObjectPageTableEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tmorecode/format/lx/ObjectTableEntry.java → ...code/file/format/lx/ObjectTableEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package yetmorecode.format.lx; | ||
package yetmorecode.file.format.lx; | ||
|
||
/** | ||
* LX Executable Object Table Entry<br> | ||
|
2 changes: 1 addition & 1 deletion
2
src/yetmorecode/format/mz/MzExecutable.java → ...morecode/file/format/mz/MzExecutable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package yetmorecode.format.mz; | ||
package yetmorecode.file.format.mz; | ||
|
||
import java.util.ArrayList; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...morecode/format/mz/MzRelocationEntry.java → ...ode/file/format/mz/MzRelocationEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package yetmorecode.format.mz; | ||
package yetmorecode.file.format.mz; | ||
|
||
|
||
/** | ||
|