ConvertStream { @Override public String toString() { StringBuilder builder = new StringBuilder(); boolean hasFormat = false; if (format != null) { hasFormat = true; builder.append(format.name()); } if (base64) { if (hasFormat) { builder.append(','); } builder.append("base64"); hasFormat = true; } if (base64mime) { if (hasFormat) { builder.append(','); } builder.append("base64mime"); hasFormat = true; } if (file != null) { if (hasFormat) { builder.append(','); } builder.append("file:"); Path pwd = new File(System.getenv("PWD")).toPath(); try { pwd = pwd.toFile().getCanonicalFile().toPath(); } catch (IOException e) { } String abs = file.getAbsolutePath(); String rel = pwd.relativize(file.getAbsoluteFile() .toPath()) .toString(); if (abs.length() < rel.length() || rel.startsWith(PARENT_PARENT)) { builder.append(abs); } else { builder.append(rel); } hasFormat = true; } if (!hasFormat) { builder.append("none"); } return builder.toString(); } ConvertStream(Format format);  ConvertStream(Format format,
                         File file,
                         boolean base64,
                         boolean base64mime); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); final Format format; final File file; final boolean base64; final boolean base64mime; }
@Test public void testRoundTrip() throws IOException { ConvertStream stream = new ConvertStream(Format.config, tmp.newFile("foo"), true, false); assertThat(stream.toString(), is("config,base64,file:" + tmp.getRoot().getAbsolutePath() + "/foo")); ConvertStreamParser parser = new ConvertStreamParser(new ConvertStream(Format.pretty_json)); ConvertStream other = parser.parse(stream.toString()); assertThat(other, is(stream)); stream = new ConvertStream(Format.binary, null, false, false); assertThat(stream.toString(), is("binary")); other = parser.parse(stream.toString()); assertThat(other, is(stream)); }