1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. public class SandboxConfigFilter {
  5. public static void main(String[] args) {
  6. String configFilePath = args[0]; // Get config file path from command line
  7. String sandboxConfig = filterForSandbox(configFilePath);
  8. System.out.println(sandboxConfig); // Output the filtered configuration
  9. }
  10. public static String filterForSandbox(String configFilePath) {
  11. StringBuilder sandboxConfig = new StringBuilder();
  12. try (BufferedReader reader = new BufferedReader(new FileReader(configFilePath))) {
  13. String line;
  14. boolean inSandboxSection = false;
  15. while ((line = reader.readLine()) != null) {
  16. line = line.trim(); // Remove leading/trailing whitespace
  17. if (line.startsWith("[sandbox]")) {
  18. inSandboxSection = true;
  19. sandboxConfig.append(line).append("\n"); // Add sandbox section header
  20. } else if (inSandboxSection) {
  21. // Only include lines within the [sandbox] section
  22. if (!line.isEmpty() && !line.startsWith("#")) { //skip empty lines and comments.
  23. sandboxConfig.append(line).append("\n");
  24. }
  25. }
  26. }
  27. } catch (IOException e) {
  28. System.err.println("Error reading config file: " + e.getMessage());
  29. return ""; //Return empty string on error
  30. }
  31. return sandboxConfig.toString();
  32. }
  33. }

Add your comment