@Override public int read() throws IOException { if (endOfStream == false) { int i = super.read(); if (i == -1) { endOfStream = true; calculateExtraData(); return readNext(); } else { last = i; } return i; } else { return readNext(); } }
@Override public int read(byte[] b, int off, int len) throws IOException { if (endOfStream == false) { int r = in.read(b, off, len); if (r == -1) { endOfStream = true; calculateExtraData(); return fillArray(b, off, len); } else { // Make sure we respect the offset. Otherwise it could let the RETRCmdHandler // hang forever. See JAMES-1222 last = b[off + r - 1]; return r; } } else { return fillArray(b, off, len); } }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Test public void testCRLFPresent() throws IOException { String data = "Subject: test\r\n\r\ndata\r\n"; checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), data); checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), data); }
private int fillArray(byte[] b, int off, int len) { int a = -1; int i = 0; if (complete) { return -1; } while (i < len) { a = readNext(); if (a == -1) { complete = true; break; } else { b[off + i++] = (byte) a; } } return i; }
@Test public void testCRPresent() throws IOException { String data = "Subject: test\r\n\r\ndata\r"; String expected = data + "\n"; checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); }
@Test public void testNonPresent() throws IOException { String data = "Subject: test\r\n\r\ndata"; String expected = data + "\r\n"; checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); }
@Test public void testCRPresent() throws IOException { String data = "Subject: test\r\n\r\ndata\r"; String expected = data + "\n"; checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); }
@Test public void testCRLFPresent() throws IOException { String data = "Subject: test\r\n\r\ndata\r\n"; checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), data); checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), data); }
@Test public void testNonPresent() throws IOException { String data = "Subject: test\r\n\r\ndata"; String expected = data + "\r\n"; checkRead(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); checkReadViaArray(new CRLFTerminatedInputStream(new ByteArrayInputStream(data.getBytes())), expected); }
if (deletedUidList.contains(uid) == false) { InputStream message = new CountingBodyInputStream(new ExtraDotInputStream(new CRLFTerminatedInputStream(session.getUserMailbox().getMessage(uid))), lines); return new POP3StreamResponse(POP3Response.OK_RESPONSE, "Message follows", message);
InputStream in = new CRLFTerminatedInputStream(new ExtraDotInputStream(content)); response = new POP3StreamResponse(POP3Response.OK_RESPONSE, "Message follows", in); return response;