use of org.apache.ignite.internal.util.io.GridByteArrayOutputStream in project ignite by apache.
the class JdkMarshaller method marshal0.
/**
* {@inheritDoc}
*/
@Override
protected byte[] marshal0(@Nullable Object obj) throws IgniteCheckedException {
GridByteArrayOutputStream out = null;
try {
out = new GridByteArrayOutputStream(DFLT_BUFFER_SIZE);
marshal(obj, out);
return out.toByteArray();
} finally {
U.close(out, null);
}
}
use of org.apache.ignite.internal.util.io.GridByteArrayOutputStream in project ignite by apache.
the class GridClientJdkMarshaller method marshal.
/**
* {@inheritDoc}
*/
@Override
public ByteBuffer marshal(Object obj, int off) throws IOException {
GridByteArrayOutputStream bOut = new GridByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bOut);
out.writeObject(obj);
out.flush();
ByteBuffer buf = ByteBuffer.allocate(off + bOut.size());
buf.position(off);
buf.put(bOut.internalArray(), 0, bOut.size());
buf.flip();
return buf;
}
use of org.apache.ignite.internal.util.io.GridByteArrayOutputStream in project ignite by apache.
the class GridCacheReplicatedQueueRemoveSelfTest method testQueueRemovalProcessor.
/**
* This a unit test of Ignite queue's RemoveProcessor process() method.
*
* @throws Exception If failed.
*/
@Test
@SuppressWarnings("unchecked")
public void testQueueRemovalProcessor() throws Exception {
GridCacheContext cctx = grid(0).context().cache().cache("ignite-sys-cache").context();
IgniteUuid id = IgniteUuid.randomUuid();
CacheInvokeEntry entry = new CacheInvokeEntry<>(null, null, null, false, new GridDhtCacheEntry(cctx, null, new KeyCacheObjectImpl(1, BigInteger.valueOf(1).toByteArray(), 1)));
entry.setValue(new GridCacheQueueHeader(id, 2147483647, false, 0L, 10000L, Collections.singleton(1L)));
GridCacheQueueAdapter.RemoveProcessor rp = new GridCacheQueueAdapter.RemoveProcessor(id, 1L);
rp.process(entry);
GridCacheQueueAdapter.RemoveProcessor externalRP = new GridCacheQueueAdapter.RemoveProcessor();
GridByteArrayOutputStream output = new GridByteArrayOutputStream();
rp.writeExternal(new ObjectOutputStream(output));
externalRP.readExternal(new ObjectInputStream(new GridByteArrayInputStream(output.toByteArray())));
assertEquals(id, GridTestUtils.getFieldValue(externalRP, "id"));
// idx should be null, cause entry was already removed, see GridCacheQueueAdapter.RemoveProcessor.code
// for more details.
assertNull(GridTestUtils.getFieldValue(externalRP, "idx"));
}
use of org.apache.ignite.internal.util.io.GridByteArrayOutputStream in project ignite by apache.
the class ZookeeperDiscoveryImpl method zip.
/**
* @param bytes Bytes to compress.
* @return Zip-compressed bytes.
*/
private static byte[] zip(byte[] bytes) {
Deflater deflater = new Deflater();
deflater.setInput(bytes);
deflater.finish();
GridByteArrayOutputStream out = new GridByteArrayOutputStream(bytes.length);
final byte[] buf = new byte[bytes.length];
while (!deflater.finished()) {
int cnt = deflater.deflate(buf);
out.write(buf, 0, cnt);
}
return out.toByteArray();
}
use of org.apache.ignite.internal.util.io.GridByteArrayOutputStream in project ignite by apache.
the class ZookeeperDiscoveryImpl method unzip.
/**
* @param zipBytes Zip-compressed bytes.
* @return Uncompressed bytes.
* @throws DataFormatException If compressed data format is invalid.
*/
public static byte[] unzip(byte[] zipBytes) throws DataFormatException {
Inflater inflater = new Inflater();
inflater.setInput(zipBytes);
GridByteArrayOutputStream out = new GridByteArrayOutputStream(zipBytes.length * 2);
final byte[] buf = new byte[zipBytes.length];
while (!inflater.finished()) {
int cnt = inflater.inflate(buf);
out.write(buf, 0, cnt);
}
return out.toByteArray();
}
Aggregations