wip map parser
This commit is contained in:
		
							
								
								
									
										44
									
								
								app/src/main/java/school_project/MapParser.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								app/src/main/java/school_project/MapParser.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
			
		||||
package school_project;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.lang.reflect.Array;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
public class MapParser {
 | 
			
		||||
    public static Map ParseMapFile(File file) throws IllegalArgumentException, IllegalAccessException, IOException {
 | 
			
		||||
        System.out.println(file.getAbsolutePath());
 | 
			
		||||
        FileInputStream fileStream = new FileInputStream(file);
 | 
			
		||||
        if(!file.isFile()) throw new IllegalArgumentException("The argument should be a file");
 | 
			
		||||
        if(!file.canRead()) throw new IllegalAccessException("This file can't be read");
 | 
			
		||||
 | 
			
		||||
        byte[] bytes = fileStream.readAllBytes();
 | 
			
		||||
        int start_position = 0, end_position = 0;
 | 
			
		||||
        for (int i = 0; i < bytes.length; i++) {
 | 
			
		||||
            if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 83){ // SMS
 | 
			
		||||
                start_position = i+3;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (int i = start_position; i < bytes.length; i++) {
 | 
			
		||||
            if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME
 | 
			
		||||
                end_position = i;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        byte[] map_data = Arrays.copyOfRange(bytes, start_position, end_position); //TODO tonitch cursor
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        fileStream.close();
 | 
			
		||||
        return new Map(); //TODO: Send the parsed map
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//    public static void SaveMapFile(File file){
 | 
			
		||||
//    }
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) throws IOException, IllegalAccessException {
 | 
			
		||||
        ParseMapFile(new File("test.smap"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -1,2 +0,0 @@
 | 
			
		||||
package school_project;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user