@Test public void testParseLiteral() throws Exception { ImapResponseParser parser = createParser("* {4}\r\ntest\r\n"); ImapResponse response = parser.readResponse(); assertEquals(1, response.size()); assertEquals("test", response.getString(0)); }
private Object parseLiteral() throws IOException { expect('{'); int size = Integer.parseInt(readStringUntil('}')); expect('\r'); expect('\n'); if (size == 0) { return ""; } if (response.getCallback() != null) { FixedLengthInputStream fixed = new FixedLengthInputStream(inputStream, size); Exception callbackException = null; Object result = null; try { result = response.getCallback().foundLiteral(response, fixed); } catch (IOException e) { throw e; } catch (Exception e) { callbackException = e; } boolean someDataWasRead = fixed.available() != size; if (someDataWasRead) { if (result == null && callbackException == null) { throw new AssertionError("Callback consumed some data but returned no result"); } fixed.skipRemaining(); } if (callbackException != null) { if (exception == null) { exception = callbackException; } return "EXCEPTION"; } if (result != null) { return result; } } byte[] data = new byte[size]; int read = 0; while (read != size) { int count = inputStream.read(data, read, size - read); if (count == -1) { throw new IOException("parseLiteral(): end of stream reached"); } read += count; } return new String(data, "US-ASCII"); }
ImapResponseParser { private Object parseLiteral() throws IOException { expect('{'); int size = Integer.parseInt(readStringUntil('}')); expect('\r'); expect('\n'); if (size == 0) { return ""; } if (response.getCallback() != null) { FixedLengthInputStream fixed = new FixedLengthInputStream(inputStream, size); Exception callbackException = null; Object result = null; try { result = response.getCallback().foundLiteral(response, fixed); } catch (IOException e) { throw e; } catch (Exception e) { callbackException = e; } boolean someDataWasRead = fixed.available() != size; if (someDataWasRead) { if (result == null && callbackException == null) { throw new AssertionError("Callback consumed some data but returned no result"); } fixed.skipRemaining(); } if (callbackException != null) { if (exception == null) { exception = callbackException; } return "EXCEPTION"; } if (result != null) { return result; } } byte[] data = new byte[size]; int read = 0; while (read != size) { int count = inputStream.read(data, read, size - read); if (count == -1) { throw new IOException("parseLiteral(): end of stream reached"); } read += count; } return new String(data, "US-ASCII"); } }
ImapResponseParser { private Object parseLiteral() throws IOException { expect('{'); int size = Integer.parseInt(readStringUntil('}')); expect('\r'); expect('\n'); if (size == 0) { return ""; } if (response.getCallback() != null) { FixedLengthInputStream fixed = new FixedLengthInputStream(inputStream, size); Exception callbackException = null; Object result = null; try { result = response.getCallback().foundLiteral(response, fixed); } catch (IOException e) { throw e; } catch (Exception e) { callbackException = e; } boolean someDataWasRead = fixed.available() != size; if (someDataWasRead) { if (result == null && callbackException == null) { throw new AssertionError("Callback consumed some data but returned no result"); } fixed.skipRemaining(); } if (callbackException != null) { if (exception == null) { exception = callbackException; } return "EXCEPTION"; } if (result != null) { return result; } } byte[] data = new byte[size]; int read = 0; while (read != size) { int count = inputStream.read(data, read, size - read); if (count == -1) { throw new IOException("parseLiteral(): end of stream reached"); } read += count; } return new String(data, "US-ASCII"); } ImapResponseParser(PeekableInputStream in); }
ImapResponseParser { private Object parseLiteral() throws IOException { expect('{'); int size = Integer.parseInt(readStringUntil('}')); expect('\r'); expect('\n'); if (size == 0) { return ""; } if (response.getCallback() != null) { FixedLengthInputStream fixed = new FixedLengthInputStream(inputStream, size); Exception callbackException = null; Object result = null; try { result = response.getCallback().foundLiteral(response, fixed); } catch (IOException e) { throw e; } catch (Exception e) { callbackException = e; } boolean someDataWasRead = fixed.available() != size; if (someDataWasRead) { if (result == null && callbackException == null) { throw new AssertionError("Callback consumed some data but returned no result"); } fixed.skipRemaining(); } if (callbackException != null) { if (exception == null) { exception = callbackException; } return "EXCEPTION"; } if (result != null) { return result; } } byte[] data = new byte[size]; int read = 0; while (read != size) { int count = inputStream.read(data, read, size - read); if (count == -1) { throw new IOException("parseLiteral(): end of stream reached"); } read += count; } return new String(data, "US-ASCII"); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback); }
ImapResponseParser { private Object parseLiteral() throws IOException { expect('{'); int size = Integer.parseInt(readStringUntil('}')); expect('\r'); expect('\n'); if (size == 0) { return ""; } if (response.getCallback() != null) { FixedLengthInputStream fixed = new FixedLengthInputStream(inputStream, size); Exception callbackException = null; Object result = null; try { result = response.getCallback().foundLiteral(response, fixed); } catch (IOException e) { throw e; } catch (Exception e) { callbackException = e; } boolean someDataWasRead = fixed.available() != size; if (someDataWasRead) { if (result == null && callbackException == null) { throw new AssertionError("Callback consumed some data but returned no result"); } fixed.skipRemaining(); } if (callbackException != null) { if (exception == null) { exception = callbackException; } return "EXCEPTION"; } if (result != null) { return result; } } byte[] data = new byte[size]; int read = 0; while (read != size) { int count = inputStream.read(data, read, size - read); if (count == -1) { throw new IOException("parseLiteral(): end of stream reached"); } read += count; } return new String(data, "US-ASCII"); } ImapResponseParser(PeekableInputStream in); ImapResponse readResponse(); ImapResponse readResponse(ImapResponseCallback callback);  }