Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pad.ijvm;
- import pad.ijvm.interfaces.IJVMInterface;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- public class MachineFactory {
- public static IJVMInterface createIJVMInstance(File binary) throws IOException {
- // Create new machine instance here and return it.
- try{
- //File file = new File("/path/to/file.txt");
- byte[] bytes = new byte[(int) binary.length()];
- FileInputStream fileInputStream = new FileInputStream(binary);
- fileInputStream.read(bytes);
- fileInputStream.close();
- ReadDoc processBinary = new ReadDoc(bytes);
- } catch (FileNotFoundException e){
- System.err.printf("%s\n", e.getMessage());
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
- ----------------------------------------------------ReadDoc-----------------------------
- package pad.ijvm;
- import java.lang.System;
- public class ReadDoc {
- static final int BYTE_CONSTANT=4;
- int sizeOfText;
- byte[] binary;
- byte[] constantAndText;
- int constantSize;
- byte[] text;
- ReadDoc(byte[] bytes){
- binary = new byte[(int) bytes.length];
- System.arraycopy(bytes, 0, binary, 0, bytes.length);
- }
- void getInfo(){
- constantAndText = new byte[((binary.length)-BYTE_CONSTANT)];
- System.arraycopy(binary, BYTE_CONSTANT, constantAndText, 0, constantAndText.length);
- readBlock();
- }
- void readBlock(){
- constantSize= ((constantAndText[0] & 0xFF) << 24) |
- ((constantAndText[1] & 0xFF) << 16) |
- ((constantAndText[2] & 0xFF) << 8) |
- (constantAndText[3] & 0xFF);
- constantSize*=4; //every constant has 4 bytes
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement