CharacterStreamCommunication { public static void writeBoundary(String boundary, Appendable destination) throws IOException { Objects.requireNonNull(boundary); if (!BOUNDARY_PATTERN.matcher(boundary).matches()) { throw new IllegalArgumentException(String.format( "Expected boundary that is valid according to RFC 2046, but got '%s'.", boundary )); } destination.append(BOUNDARY).append(": ").append(boundary).append('\n'); } private  CharacterStreamCommunication(); static void writeBoundary(String boundary, Appendable destination); static void writeObject(Serializable serializable, Appendable destination, String boundary);  }
@Test public void testWriteBoundary() throws IOException { StringBuilder stringBuilder = new StringBuilder(256); CharacterStreamCommunication.writeBoundary("abc", stringBuilder); Assert.assertEquals(stringBuilder.toString(), "X-Object-Boundary: abc\n"); try { CharacterStreamCommunication.writeBoundary("foo ", stringBuilder); Assert.fail(); } catch (IllegalArgumentException ignored) { } try { CharacterStreamCommunication.writeBoundary("garçon", stringBuilder); Assert.fail(); } catch (IllegalArgumentException ignored) { } }