/** * Appends the given value to the buffer. * * @param value The value to append. */ public KeyValuePairWriter write(final String key, final long value) { writeSeparator(); out.print(key); out.print("="); out.print(value); return this; }
@Test public void testWritekeyValuePairs() throws Exception { final Date date = createDate(1970, Calendar.NOVEMBER, 21, 13, 17, 57, 742); log.info("Created date: " + date.toString()); final StringWriter stringWriter = new StringWriter(); final KeyValuePairWriter writer = new KeyValuePairWriter(stringWriter); writer.write("a1", "Hallo"); writer.write("a2", "Hal\"lo"); writer.write("a3", (String) null); writer.write("a4", (Date) null); writer.write("a5", date); writer.write("a6", 42); writer.flush(); assertEquals("a1=\"Hallo\",a2=\"Hal\"\"lo\",a3=,a4=,a5=\"1970-11-21 13:17:57.742\",a6=42", stringWriter.toString()); }
/** * Appends the given value to the buffer in the format "yyyy-MM-dd HH:mm:ss.SSS". * * @param value The value to append. */ public KeyValuePairWriter write(final String key, final Object value) { writeSeparator(); out.print(key); out.print("="); if (value != null) { out.print(String.valueOf(value)); } return this; }
/** * Appends the given value in the format "yyyy-MM-dd HH:mm:ss.SSS". * * @param value The value to append. */ public KeyValuePairWriter write(final String key, final Date value) { writeSeparator(); out.print(key); out.print("="); if (value != null) { out.print('"'); out.print(dateFormat.format(value)); out.print('"'); } return this; }
/** * Appends the given value. The string will be encapsulated in quotation marks: " Any occurance of the quotation mark will be quoted by * duplication. Example: hallo -> "hallo", hal"lo -> "hal""lo" * * @param value The value to append. */ public KeyValuePairWriter write(final String key, final String s) { writeSeparator(); out.print(key); out.print("="); if (s != null) { out.print('"'); final int len = s.length(); char c; for (int i = 0; i < len; i++) { c = s.charAt(i); if ('"' == c) { out.print('"'); } out.print(c); } out.print('"'); } return this; }