import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.io.IOException; /* PROSPACE SCHEMATIC FILE ; Version 2006.3.2 Project,Space Planning-Projekt,, 0,,7,1.5,1.5,1,1,0,,1,1,0,0,0,0,3,1,1,0,1,0,0,0,0,2,3,1,0,1,0,0,0,0,3,3,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,0,0,0,0,0,0,0,,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,2,2,2,,0,0,0,0,0,0,0,0,,,0, Planogram,Test,, 100,200,60,16777215,2,1,100,10,60,1,16777215,0,10,2,0,32896,1,0,0,1,0,,,-1,-1,-1,-1,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,0,1,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,1,,,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,,,,0,0,0,0,0,0,0,0,,,,0.5,30,30,0,0,0,0,0,0,1.5,1.5,1,1,0,0,0,0,0,0,0,0,,,,,,F766F39C-5610-4cedAB0A-FDFD4D6DC166,,,,,0 Segment,,, 0,100,0,0,0,0,0,0,0,0,0,,,,,,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,, */ public class ProspaceParser { private final ProspaceHandler handler; public ProspaceParser(ProspaceHandler handler) { this.handler = handler; } public void parse(BufferedReader in) throws IOException, E { String magic = in.readLine(); if (!magic.equals("PROSPACE SCHEMATIC FILE")) throw new IOException("bad magic: " + magic); handler.start(); String line; while (((line = in.readLine()) != null) && line.startsWith(";")) { String header = line.substring(1).trim(); handler.header(header); } while (line != null) { String[] metadata = line.split(",", -1); // this form of split does not discard trailing empty strings, a common gotcha line = in.readLine(); String[] data = line.split(",", -1); handler.paragraph(metadata, data); line = in.readLine(); } in.close(); // not sure if you need to do this if you've read to the end of the stream handler.end(); } public void parse(InputStream in, String charset) throws IOException, E { parse(new BufferedReader(new InputStreamReader(in, charset))); } }