BulkStringEofJuderManager { public static BulkStringEofJudger create(byte []data){ int start = 0; if(data[0] == RedisClientProtocol.DOLLAR_BYTE){ start = 1; } if(arraynequals(data, 1, RedisClientProtocol.EOF, RedisClientProtocol.EOF.length)){ if(start + RedisClientProtocol.EOF.length + BulkStringEofMarkJudger.MARK_LENGTH > data.length){ throw new IllegalStateException("bulksting eof mark error:" + new String(data)); } byte []mark = new byte[BulkStringEofMarkJudger.MARK_LENGTH]; System.arraycopy(data, start + RedisClientProtocol.EOF.length, mark, 0, BulkStringEofMarkJudger.MARK_LENGTH); return new BulkStringEofMarkJudger(mark); } logger.debug("[create]len:{}, {}, {}", data.length, new String(data), start); String lengthStr = new String(data, start, data.length - start).trim(); long length = Long.parseLong(lengthStr); return new BulkStringLengthEofJudger(length); }  static BulkStringEofJudger create(byte []data);  }
@Test public void test(){ BulkStringEofJudger judger = null; judger = BulkStringEofJuderManager.create(("$EOF:" + randomString(BulkStringEofMarkJudger.MARK_LENGTH) + "\r\n").getBytes()); Assert.assertTrue( judger instanceof BulkStringEofJudger); judger = BulkStringEofJuderManager.create(("$EOF:" + randomString(BulkStringEofMarkJudger.MARK_LENGTH + 100) + "\r\n").getBytes()); Assert.assertTrue( judger instanceof BulkStringEofJudger); judger = BulkStringEofJuderManager.create(("$100\r\n").getBytes()); Assert.assertTrue( judger instanceof BulkStringEofJudger); try{ judger = BulkStringEofJuderManager.create(("$EOF:" + randomString(BulkStringEofMarkJudger.MARK_LENGTH/2) + "\r\n").getBytes()); Assert.fail(); }catch(Exception e){ } }