@Ignore @Test public void isSameContent() { String left = "<h1>The droids were just here 12 seconds ago.</h1>\n\n\n<h1>lastAccess = Thu Feb 20 10:45:01 PST 2014</h1>\n\n\n<h3>---------------------------------------</h3>\n<h3>lastEventSent = 12</h3>\n<h3>lastRemoteAddr = 166.137.185.60</h3>\n<h3>lastRemoteHost = 166.137.185.60</h3>\n<h3>lastRemoteUser = null</h3>"; String right = "<h1>The droids were just here 13 seconds ago.</h1>\n\n\n<h1>lastAccess = Thu Feb 20 10:45:00 PST 2014</h1>\n\n\n<h3>---------------------------------------</h3>\n<h3>lastEventSent = 12</h3>\n<h3>lastRemoteAddr = 166.137.185.60</h3>\n<h3>lastRemoteHost = 166.137.185.60</h3>\n<h3>lastRemoteUser = null</h3>"; Session session = mock(Session.class); HttpRequestResponseInfo reqLeft = mock(HttpRequestResponseInfo.class); HttpRequestResponseInfo reqRight = mock(HttpRequestResponseInfo.class); SortedMap<Integer, Integer> contentOffsetTreeMap = new TreeMap<Integer, Integer>(); contentOffsetTreeMap.put(1, 2); byte[] dataLeft = left.getBytes(); byte[] dataRight = right.getBytes(); Mockito.when(reqLeft.getContentOffsetLength()).thenReturn(contentOffsetTreeMap); Mockito.when(reqLeft.getPacketDirection()).thenReturn(PacketDirection.DOWNLINK); Mockito.when(reqRight.getContentOffsetLength()).thenReturn(contentOffsetTreeMap); Mockito.when(reqRight.getPacketDirection()).thenReturn(PacketDirection.UPLINK); Mockito.when(session.getStorageDl()).thenReturn(dataLeft); Mockito.when(session.getStorageUl()).thenReturn(dataRight); Mockito.when(session.getStorageUl()).thenReturn(dataLeft); }
public boolean isSameContent(HttpRequestResponseInfo left, HttpRequestResponseInfo right, Session session, Session sessionRight) { if (left.getContentLength() > 0 && left.getContentLength() != right.getContentLength()) { return false; } boolean yes = true; long leftcount = getActualByteCount(left, session); long rightcount = getActualByteCount(right, sessionRight); if (leftcount == rightcount) { if (leftcount == 0) { return true; } byte[] bufferLeft = left.getPayloadData().toByteArray(); byte[] bufferRight = right.getPayloadData().toByteArray(); Iterator<Map.Entry<Integer, Integer>> itleft = left.getContentOffsetLength().entrySet().iterator(); Iterator<Map.Entry<Integer, Integer>> itright = right.getContentOffsetLength().entrySet().iterator(); int indexLeft = 0; int stopLeft = 0; int indexRight = 0; int stopRight = 0; if (itleft.hasNext() && itright.hasNext()) { Map.Entry<Integer, Integer> entryLeft = itleft.next(); Map.Entry<Integer, Integer> entryRight = itright.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); do { if (bufferLeft[indexLeft] != bufferRight[indexRight]) { return false; } ++indexLeft; ++indexRight; if (indexLeft >= bufferLeft.length || indexRight >= bufferRight.length) { break; } if (indexLeft >= stopLeft) { if (itleft.hasNext()) { entryLeft = itleft.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); } else { break; } } if (indexRight >= stopRight) { if (itright.hasNext()) { entryRight = itright.next(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); } else { break; } } } while (true); } yes = true; } else { yes = false; } return yes; }
HttpRequestResponseHelperImpl implements IHttpRequestResponseHelper { public boolean isSameContent(HttpRequestResponseInfo left, HttpRequestResponseInfo right, Session session, Session sessionRight) { if (left.getContentLength() > 0 && left.getContentLength() != right.getContentLength()) { return false; } boolean yes = true; long leftcount = getActualByteCount(left, session); long rightcount = getActualByteCount(right, sessionRight); if (leftcount == rightcount) { if (leftcount == 0) { return true; } byte[] bufferLeft = left.getPayloadData().toByteArray(); byte[] bufferRight = right.getPayloadData().toByteArray(); Iterator<Map.Entry<Integer, Integer>> itleft = left.getContentOffsetLength().entrySet().iterator(); Iterator<Map.Entry<Integer, Integer>> itright = right.getContentOffsetLength().entrySet().iterator(); int indexLeft = 0; int stopLeft = 0; int indexRight = 0; int stopRight = 0; if (itleft.hasNext() && itright.hasNext()) { Map.Entry<Integer, Integer> entryLeft = itleft.next(); Map.Entry<Integer, Integer> entryRight = itright.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); do { if (bufferLeft[indexLeft] != bufferRight[indexRight]) { return false; } ++indexLeft; ++indexRight; if (indexLeft >= bufferLeft.length || indexRight >= bufferRight.length) { break; } if (indexLeft >= stopLeft) { if (itleft.hasNext()) { entryLeft = itleft.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); } else { break; } } if (indexRight >= stopRight) { if (itright.hasNext()) { entryRight = itright.next(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); } else { break; } } } while (true); } yes = true; } else { yes = false; } return yes; } }
HttpRequestResponseHelperImpl implements IHttpRequestResponseHelper { public boolean isSameContent(HttpRequestResponseInfo left, HttpRequestResponseInfo right, Session session, Session sessionRight) { if (left.getContentLength() > 0 && left.getContentLength() != right.getContentLength()) { return false; } boolean yes = true; long leftcount = getActualByteCount(left, session); long rightcount = getActualByteCount(right, sessionRight); if (leftcount == rightcount) { if (leftcount == 0) { return true; } byte[] bufferLeft = left.getPayloadData().toByteArray(); byte[] bufferRight = right.getPayloadData().toByteArray(); Iterator<Map.Entry<Integer, Integer>> itleft = left.getContentOffsetLength().entrySet().iterator(); Iterator<Map.Entry<Integer, Integer>> itright = right.getContentOffsetLength().entrySet().iterator(); int indexLeft = 0; int stopLeft = 0; int indexRight = 0; int stopRight = 0; if (itleft.hasNext() && itright.hasNext()) { Map.Entry<Integer, Integer> entryLeft = itleft.next(); Map.Entry<Integer, Integer> entryRight = itright.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); do { if (bufferLeft[indexLeft] != bufferRight[indexRight]) { return false; } ++indexLeft; ++indexRight; if (indexLeft >= bufferLeft.length || indexRight >= bufferRight.length) { break; } if (indexLeft >= stopLeft) { if (itleft.hasNext()) { entryLeft = itleft.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); } else { break; } } if (indexRight >= stopRight) { if (itright.hasNext()) { entryRight = itright.next(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); } else { break; } } } while (true); } yes = true; } else { yes = false; } return yes; }  }
HttpRequestResponseHelperImpl implements IHttpRequestResponseHelper { public boolean isSameContent(HttpRequestResponseInfo left, HttpRequestResponseInfo right, Session session, Session sessionRight) { if (left.getContentLength() > 0 && left.getContentLength() != right.getContentLength()) { return false; } boolean yes = true; long leftcount = getActualByteCount(left, session); long rightcount = getActualByteCount(right, sessionRight); if (leftcount == rightcount) { if (leftcount == 0) { return true; } byte[] bufferLeft = left.getPayloadData().toByteArray(); byte[] bufferRight = right.getPayloadData().toByteArray(); Iterator<Map.Entry<Integer, Integer>> itleft = left.getContentOffsetLength().entrySet().iterator(); Iterator<Map.Entry<Integer, Integer>> itright = right.getContentOffsetLength().entrySet().iterator(); int indexLeft = 0; int stopLeft = 0; int indexRight = 0; int stopRight = 0; if (itleft.hasNext() && itright.hasNext()) { Map.Entry<Integer, Integer> entryLeft = itleft.next(); Map.Entry<Integer, Integer> entryRight = itright.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); do { if (bufferLeft[indexLeft] != bufferRight[indexRight]) { return false; } ++indexLeft; ++indexRight; if (indexLeft >= bufferLeft.length || indexRight >= bufferRight.length) { break; } if (indexLeft >= stopLeft) { if (itleft.hasNext()) { entryLeft = itleft.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); } else { break; } } if (indexRight >= stopRight) { if (itright.hasNext()) { entryRight = itright.next(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); } else { break; } } } while (true); } yes = true; } else { yes = false; } return yes; }  @Autowired void setByteArrayLineReader(IByteArrayLineReader reader); boolean isCss(String contentType); boolean isHtml(String contentType); boolean isJSON(String contentType); boolean isJavaScript(String contentType); String getContentString(HttpRequestResponseInfo req, Session session); byte[] getContent(HttpRequestResponseInfo request, Session session); boolean isSameContent(HttpRequestResponseInfo left, HttpRequestResponseInfo right, Session session, Session sessionRight); long getActualByteCount(HttpRequestResponseInfo item, Session session); }
HttpRequestResponseHelperImpl implements IHttpRequestResponseHelper { public boolean isSameContent(HttpRequestResponseInfo left, HttpRequestResponseInfo right, Session session, Session sessionRight) { if (left.getContentLength() > 0 && left.getContentLength() != right.getContentLength()) { return false; } boolean yes = true; long leftcount = getActualByteCount(left, session); long rightcount = getActualByteCount(right, sessionRight); if (leftcount == rightcount) { if (leftcount == 0) { return true; } byte[] bufferLeft = left.getPayloadData().toByteArray(); byte[] bufferRight = right.getPayloadData().toByteArray(); Iterator<Map.Entry<Integer, Integer>> itleft = left.getContentOffsetLength().entrySet().iterator(); Iterator<Map.Entry<Integer, Integer>> itright = right.getContentOffsetLength().entrySet().iterator(); int indexLeft = 0; int stopLeft = 0; int indexRight = 0; int stopRight = 0; if (itleft.hasNext() && itright.hasNext()) { Map.Entry<Integer, Integer> entryLeft = itleft.next(); Map.Entry<Integer, Integer> entryRight = itright.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); do { if (bufferLeft[indexLeft] != bufferRight[indexRight]) { return false; } ++indexLeft; ++indexRight; if (indexLeft >= bufferLeft.length || indexRight >= bufferRight.length) { break; } if (indexLeft >= stopLeft) { if (itleft.hasNext()) { entryLeft = itleft.next(); indexLeft = entryLeft.getKey(); stopLeft = indexLeft + entryLeft.getValue(); } else { break; } } if (indexRight >= stopRight) { if (itright.hasNext()) { entryRight = itright.next(); indexRight = entryRight.getKey(); stopRight = entryRight.getValue(); } else { break; } } } while (true); } yes = true; } else { yes = false; } return yes; }  @Autowired void setByteArrayLineReader(IByteArrayLineReader reader); boolean isCss(String contentType); boolean isHtml(String contentType); boolean isJSON(String contentType); boolean isJavaScript(String contentType); String getContentString(HttpRequestResponseInfo req, Session session); byte[] getContent(HttpRequestResponseInfo request, Session session); boolean isSameContent(HttpRequestResponseInfo left, HttpRequestResponseInfo right, Session session, Session sessionRight); long getActualByteCount(HttpRequestResponseInfo item, Session session);  }