@Test public void testSplitBytes() { byte[] data = new byte[8]; for (int i = 0; i < data.length; i++) { data[i] = (byte) i; } int nSplit; byte[][] dataSplits; nSplit = 2; dataSplits = MemcachedChunkingCache.splitBytes(data, nSplit); Assert.assertEquals(nSplit, dataSplits.length); Assert.assertArrayEquals(dataSplits[0], new byte[] { 0, 1, 2, 3 }); Assert.assertArrayEquals(dataSplits[1], new byte[] { 4, 5, 6, 7 }); nSplit = 3; dataSplits = MemcachedChunkingCache.splitBytes(data, nSplit); Assert.assertEquals(nSplit, dataSplits.length); Assert.assertArrayEquals(dataSplits[0], new byte[] { 0, 1, 2 }); Assert.assertArrayEquals(dataSplits[1], new byte[] { 3, 4, 5 }); Assert.assertArrayEquals(dataSplits[2], new byte[] { 6, 7 }); }
protected static byte[][] splitBytes(final byte[] data, final int nSplit) { byte[][] dest = new byte[nSplit][]; final int splitSize = (data.length - 1) / nSplit + 1; for (int i = 0; i < nSplit - 1; i++) { dest[i] = Arrays.copyOfRange(data, i * splitSize, (i + 1) * splitSize); } dest[nSplit - 1] = Arrays.copyOfRange(data, (nSplit - 1) * splitSize, data.length); return dest; }
MemcachedChunkingCache extends MemcachedCache implements KeyHookLookup { protected static byte[][] splitBytes(final byte[] data, final int nSplit) { byte[][] dest = new byte[nSplit][]; final int splitSize = (data.length - 1) / nSplit + 1; for (int i = 0; i < nSplit - 1; i++) { dest[i] = Arrays.copyOfRange(data, i * splitSize, (i + 1) * splitSize); } dest[nSplit - 1] = Arrays.copyOfRange(data, (nSplit - 1) * splitSize, data.length); return dest; } }
MemcachedChunkingCache extends MemcachedCache implements KeyHookLookup { protected static byte[][] splitBytes(final byte[] data, final int nSplit) { byte[][] dest = new byte[nSplit][]; final int splitSize = (data.length - 1) / nSplit + 1; for (int i = 0; i < nSplit - 1; i++) { dest[i] = Arrays.copyOfRange(data, i * splitSize, (i + 1) * splitSize); } dest[nSplit - 1] = Arrays.copyOfRange(data, (nSplit - 1) * splitSize, data.length); return dest; } MemcachedChunkingCache(MemcachedCache cache); }
MemcachedChunkingCache extends MemcachedCache implements KeyHookLookup { protected static byte[][] splitBytes(final byte[] data, final int nSplit) { byte[][] dest = new byte[nSplit][]; final int splitSize = (data.length - 1) / nSplit + 1; for (int i = 0; i < nSplit - 1; i++) { dest[i] = Arrays.copyOfRange(data, i * splitSize, (i + 1) * splitSize); } dest[nSplit - 1] = Arrays.copyOfRange(data, (nSplit - 1) * splitSize, data.length); return dest; } MemcachedChunkingCache(MemcachedCache cache); @Override byte[] getBinary(String keyS); @Override void putBinary(String keyS, byte[] valueB, int expiration); void evict(String keyS); @Override KeyHook lookupKeyHook(String keyS); }
MemcachedChunkingCache extends MemcachedCache implements KeyHookLookup { protected static byte[][] splitBytes(final byte[] data, final int nSplit) { byte[][] dest = new byte[nSplit][]; final int splitSize = (data.length - 1) / nSplit + 1; for (int i = 0; i < nSplit - 1; i++) { dest[i] = Arrays.copyOfRange(data, i * splitSize, (i + 1) * splitSize); } dest[nSplit - 1] = Arrays.copyOfRange(data, (nSplit - 1) * splitSize, data.length); return dest; } MemcachedChunkingCache(MemcachedCache cache); @Override byte[] getBinary(String keyS); @Override void putBinary(String keyS, byte[] valueB, int expiration); void evict(String keyS); @Override KeyHook lookupKeyHook(String keyS);  }