From a1e36ccbc7a686aa13dbc62288571101ffad2565 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 28 Feb 2023 07:13:50 +0100 Subject: [PATCH] wip map parser --- .../main/java/school_project/MapParser.java | 44 +++++++++++++++++++ .../main/java/school_project/Position.java | 2 - 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/school_project/MapParser.java delete mode 100644 app/src/main/java/school_project/Position.java diff --git a/app/src/main/java/school_project/MapParser.java b/app/src/main/java/school_project/MapParser.java new file mode 100644 index 0000000..0a366a9 --- /dev/null +++ b/app/src/main/java/school_project/MapParser.java @@ -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")); + } + +} diff --git a/app/src/main/java/school_project/Position.java b/app/src/main/java/school_project/Position.java deleted file mode 100644 index a981709..0000000 --- a/app/src/main/java/school_project/Position.java +++ /dev/null @@ -1,2 +0,0 @@ -package school_project; -