public void endWithCrLfAndFlush() throws IOException { completeCrLf(); if (lastByte != LF) { writeByte(CR); writeByte(LF); } super.flush(); }
public long calculateSize() { try { CountingOutputStream out = new CountingOutputStream(); EOLConvertingOutputStream eolOut = new EOLConvertingOutputStream(out); writeTo(eolOut); eolOut.flush(); return out.getCount(); } catch (IOException e) { Timber.e(e, "Failed to calculate a message size"); } catch (MessagingException e) { Timber.e(e, "Failed to calculate a message size"); } return 0; } }
EOLConvertingOutputStream eolOut = new EOLConvertingOutputStream(connection.getOutputStream()); message.writeTo(eolOut); eolOut.write('\r'); eolOut.write('\n'); eolOut.flush();
@Before public void setUp() throws Exception { out = new ByteArrayOutputStream(); subject = new EOLConvertingOutputStream(out); }
EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream( new LineWrapOutputStream(new SmtpDataStuffing(outputStream), 1000)); msgOut.endWithCrLfAndFlush();
@Test public void endWithCrLfAndFlush_withoutNewline_shouldAddNewline() throws Exception { subject.write("The end".getBytes()); subject.endWithCrLfAndFlush(); assertEquals("The end\r\n", out.toString()); }
private void completeCrLf() throws IOException { if (lastByte == CR) { writeByte(LF); // We have to ignore the next character if it is <LF>. Otherwise it // will be expanded to an additional <CR><LF> sequence although it // belongs to the one just completed. ignoreLf = true; } }
@Override public void flush() throws IOException { completeCrLf(); super.flush(); }
EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream( new BufferedOutputStream(out, 1024)); message.writeTo(msgOut); msgOut.flush();
outputStream = new EOLConvertingOutputStream(outputStream); } catch (IOException e) { throw new MessagingException("could not allocate temp file for storage!", e);
@Test public void endWithCrLfAndFlush_endingWithCr_shouldCompleteNewline() throws Exception { subject.write("The end\r".getBytes()); subject.endWithCrLfAndFlush(); assertEquals("The end\r\n", out.toString()); }
@Test public void endWithCrLfAndFlush_endingWithNewline_shouldNotAddAdditionalNewline() throws Exception { subject.write("The end\r\n".getBytes()); subject.endWithCrLfAndFlush(); assertEquals("The end\r\n", out.toString()); }
@Test public void endWithCrLfAndFlush_endingWithLf_shouldCompleteNewline() throws Exception { subject.write("The end\n".getBytes()); subject.endWithCrLfAndFlush(); assertEquals("The end\r\n", out.toString()); } }