NagiosPerfData { public static String readLabel(CharBuffer buffer) throws IOException { StringBuilder label = new StringBuilder(); char start = buffer.get(); if (start == '\'' || start == '"') { char c; while (buffer.hasRemaining()) { c = buffer.get(); if (c == start) { if (buffer.hasRemaining()) { char n = buffer.get(); if (n == start) { label.append(c); } else if (n == '=') { break; } else { throw new IOException("Reached end of label, was expecting: ="); } } } else { label.append(c); } } } else { label.append(start); char c; while ((c = buffer.get()) != '=' && buffer.hasRemaining()) { label.append(c); } } return label.toString(); } NagiosPerfData();  NagiosPerfData(String label, String value, String unit, String warning, String critical, String min, String max); String getLabel(); void setLabel(String label); String getValue(); void setValue(String value); String getUnit(); void setUnit(String unit); String getWarning(); void setWarning(String warning); String getCritical(); void setCritical(String critical); String getMin(); void setMin(String min); String getMax(); void setMax(String max); String toString(); Reading toReading(); static List<NagiosPerfData> parsePerfData(String perfData); static void skipWhitespace(CharBuffer buffer); static String readValue(CharBuffer buffer); static String readLabel(CharBuffer buffer);  }
@Test public void testReadUnquotedLabel() throws Exception { String label = NagiosPerfData.readLabel(CharBuffer.wrap("load1=0.490;15.000;30.000;0;".toCharArray())); assertThat(label, is(equalTo("load1"))); }
@Test public void testReadQuotedLabel() throws Exception { String label = NagiosPerfData.readLabel(CharBuffer.wrap("'chris'' load1'=0.490;15.000;30.000;0;".toCharArray())); assertThat(label, is(equalTo("chris' load1"))); }