@Test public void readTwoChunkByteMultipleReads () throws Exception { try (final InputStream empty = new NonBlockingByteArrayInputStream ("2\r\n12\r\n1\na\r\n0\r\n".getBytes ()); final ChunkedInputStream cIS = new ChunkedInputStream (empty)) { int ret = cIS.read (); assertEquals ("Read one Chunk-1: correct data returned", '1', ret); ret = cIS.read (); assertEquals ("Read one Chunk-1: correct data returned", '2', ret); ret = cIS.read (); assertEquals ("Read one Chunk-1: correct data returned", 'a', ret); } }
@Override public final int read () throws IOException { if (m_nLeft < 0) return -1; if (m_nLeft == 0) { if (m_bAfterFirstChunk) { HTTPHelper.readTillNexLine (m_aIS); } else { m_bAfterFirstChunk = true; } m_nLeft = HTTPHelper.readChunkLen (m_aIS); if (LOGGER.isDebugEnabled ()) LOGGER.debug ("Read chunk size: " + m_nLeft); if (m_nLeft <= 0) { m_nLeft = -1; return -1; } } m_nLeft--; return super.read (); }
ChunkedInputStream extends FilterInputStream { @Override public final int read () throws IOException { if (m_nLeft < 0) return -1; if (m_nLeft == 0) { if (m_bAfterFirstChunk) { HTTPHelper.readTillNexLine (m_aIS); } else { m_bAfterFirstChunk = true; } m_nLeft = HTTPHelper.readChunkLen (m_aIS); if (LOGGER.isDebugEnabled ()) LOGGER.debug ("Read chunk size: " + m_nLeft); if (m_nLeft <= 0) { m_nLeft = -1; return -1; } } m_nLeft--; return super.read (); } }
ChunkedInputStream extends FilterInputStream { @Override public final int read () throws IOException { if (m_nLeft < 0) return -1; if (m_nLeft == 0) { if (m_bAfterFirstChunk) { HTTPHelper.readTillNexLine (m_aIS); } else { m_bAfterFirstChunk = true; } m_nLeft = HTTPHelper.readChunkLen (m_aIS); if (LOGGER.isDebugEnabled ()) LOGGER.debug ("Read chunk size: " + m_nLeft); if (m_nLeft <= 0) { m_nLeft = -1; return -1; } } m_nLeft--; return super.read (); } ChunkedInputStream(@Nonnull final InputStream aIS); }
ChunkedInputStream extends FilterInputStream { @Override public final int read () throws IOException { if (m_nLeft < 0) return -1; if (m_nLeft == 0) { if (m_bAfterFirstChunk) { HTTPHelper.readTillNexLine (m_aIS); } else { m_bAfterFirstChunk = true; } m_nLeft = HTTPHelper.readChunkLen (m_aIS); if (LOGGER.isDebugEnabled ()) LOGGER.debug ("Read chunk size: " + m_nLeft); if (m_nLeft <= 0) { m_nLeft = -1; return -1; } } m_nLeft--; return super.read (); } ChunkedInputStream(@Nonnull final InputStream aIS); @Override final int read(); @Override final int read(@Nonnull final byte [] aBuf, final int nOffset, final int nLength); }
ChunkedInputStream extends FilterInputStream { @Override public final int read () throws IOException { if (m_nLeft < 0) return -1; if (m_nLeft == 0) { if (m_bAfterFirstChunk) { HTTPHelper.readTillNexLine (m_aIS); } else { m_bAfterFirstChunk = true; } m_nLeft = HTTPHelper.readChunkLen (m_aIS); if (LOGGER.isDebugEnabled ()) LOGGER.debug ("Read chunk size: " + m_nLeft); if (m_nLeft <= 0) { m_nLeft = -1; return -1; } } m_nLeft--; return super.read (); } ChunkedInputStream(@Nonnull final InputStream aIS); @Override final int read(); @Override final int read(@Nonnull final byte [] aBuf, final int nOffset, final int nLength);  }