From 02cf5ed39d06b4c11b39d83f21f21069e4d8a160 Mon Sep 17 00:00:00 2001 From: Daniel Christoph <daniel.christoph@informatik.hu-berlin.de> Date: Sat, 14 Dec 2019 17:33:50 +0100 Subject: [PATCH] Update Simulation/GazeboObsticleSettings/Main.java --- Simulation/GazeboObsticleSettings/Main.java | 108 ++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Simulation/GazeboObsticleSettings/Main.java diff --git a/Simulation/GazeboObsticleSettings/Main.java b/Simulation/GazeboObsticleSettings/Main.java new file mode 100644 index 0000000..dcf1d49 --- /dev/null +++ b/Simulation/GazeboObsticleSettings/Main.java @@ -0,0 +1,108 @@ +import java.io.*; +import java.nio.Buffer; +import java.util.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.logging.Logger; + +public class Main { + public static void main(String[] args) throws IOException { + String path = args[0]; + if((args[1].compareTo("clear") == 0)){ + try + { + BufferedReader file = new BufferedReader(new FileReader(path)); + String line; + String input = ""; + while ((line = file.readLine()) != null) + { + //System.out.println(line); + if (line.contains("ob.append")) + { + line = ""; + //System.out.println("Line deleted."); + } + input += line + '\n'; + } + FileWriter fw = new FileWriter(path); + while((line = file.readLine()) != null) + { + line = line.trim(); // remove leading and trailing whitespace + if (!line.equals("")) // don't write out blank lines + { + fw.write(line, 0, line.length()); + } + } + FileOutputStream File = new FileOutputStream(path); + File.write(input.getBytes()); + file.close(); + File.close(); + } + catch (Exception e) + { + System.out.println("Problem reading file."); + } + } else if((args[1].compareTo("dist") == 0)){ + try + { + BufferedReader file = new BufferedReader(new FileReader(path)); + String line; + String input = ""; + while ((line = file.readLine()) != null) + { + //System.out.println(line); + if (line.contains("<")) + { + line = " if dist < " + args[2] + ":"; + //System.out.println("Line deleted."); + } + input += line + '\n'; + } + FileOutputStream File = new FileOutputStream(path); + File.write(input.getBytes()); + file.close(); + File.close(); + } + catch (Exception e) + { + System.out.println("Problem reading file."); + } + } else { + System.out.println("File: " + args[0]); + String[] coords = new String[args.length - 1]; + String oldString = "ob = " + "\\[" + "]"; + String newString = "ob = []"; + newString = newString + "\n"; + String oldContent = ""; + for (int i = 0; i < coords.length; i++) { + coords[i] = args[i + 1]; + newString = newString + "ob.append((0.00 , " + coords[i] + "));"; + newString = newString + "\n"; + } + BufferedReader in = new BufferedReader(new FileReader(path)); + StringBuffer inputBuffer = new StringBuffer(); + FileWriter writer = null; + + String line = in.readLine(); + + while (line != null) { + oldContent = oldContent + line + System.lineSeparator(); + line = in.readLine(); + } + + String newContent = oldContent.replaceAll(oldString, newString); + writer = new FileWriter(path); + writer.write(newContent); + + try { + in.close(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} -- GitLab