LabelParser (File file) throws InvalidLabelFileException { this.file = file ; try { this.in = (new LineNumberInputStream (new BufferedInputStream (new FileInputStream (file)))) ; this.buffer = new byte[32] ; this.ch = in.read() ; } catch (IOException e) { throw new InvalidLabelFileException (file.getAbsolutePath() + ": IO exception.") ; } }
LabelParser (String string) throws InvalidLabelException { try { this.in = (new LineNumberInputStream (new BufferedInputStream (new StringBufferInputStream (string)))) ; this.buffer = new byte[32] ; this.ch = in.read() ; } catch (IOException e) { throw new InvalidLabelException( "IO exception.") ; } }
/** * This will parse the provided file and returns the parsed key and value content * * @param propertiesStream the Reader of property information * @return a list of {@link PropertiesEntry}s * @throws IOException if something cant be read */ public List<PropertiesEntry> parse(InputStream propertiesStream) throws IOException { List<PropertiesEntry> entryList = new ArrayList<PropertiesEntry>(); LineNumberInputStream in = new LineNumberInputStream(propertiesStream); try { StringBuilder currentComment = new StringBuilder(); String line = readLine(in); while (line != null) { // does it start with a comment marker if (isCommentOrWhiteSpaceLine(line)) { currentComment.append(line).append('\n'); line = readLine(in); } else { // we have changed state. Its a property value. line = readEntryPrimed(in, currentComment, entryList, line, in.getLineNumber()); } } } finally { in.close(); } return entryList; }
@Override protected InputStream newInputStream() throws IOException { push(); InputStream in = super.newInputStream(); pop(); return new java.io.LineNumberInputStream(in); }