@Override public byte[] bytes() { if (valBytes == null) { byte[] bs = new byte[len]; U.arrayCopy(bytes, off, bs, 0, len); valBytes = bs; } return valBytes; }
/** * Gets copy of internal array. * * @return Copy of internal array. */ public byte[] array() { byte[] res = new byte[size]; U.arrayCopy(data, 0, res, 0, size); return res; }
/** * Sets bytes from specified buffer to a given value. * * @param buf Buffer. * @param off Offset. * @param len Length. */ public void putBytes(byte[] buf, int off, int len) { if (arr == null) arr = new byte[PACKET_SIZE]; U.arrayCopy(buf, 0, arr, off, len); }
/** * @param b Buffer to copy from (length included). * @param off Offset in source buffer. * @param len Length. * @param resBuf Result buffer. * @param resOff Result offset. */ private void messageToBuffer0(byte[] b, int off, int len, byte[] resBuf, int resOff) { assert off == 0; assert resBuf.length >= resOff + len; U.arrayCopy(b, off, resBuf, resOff, len); }
/** * Creates copy of request packet for easy response construction. * * @param req Source request packet. */ GridMemcachedMessage(GridMemcachedMessage req) { assert req != null; reqFlag = req.reqFlag; opCode = req.opCode; opaque = new byte[req.opaque.length]; U.arrayCopy(req.opaque, 0, opaque, 0, req.opaque.length); }
/** {@inheritDoc} */ @Override public byte[] apply(byte[] e) { final int size = data.length; if (e == null || e.length == 0) e = new byte[start + size]; // Don't allocate more, then required. else if (e.length < start + size) { // Expand stored data array, if it less, then required. byte[] tmp = new byte[start + size]; // Don't allocate more than required. U.arrayCopy(e, 0, tmp, 0, e.length); e = tmp; } // Copy data into entry. U.arrayCopy(data, 0, e, start, size); return e; }
/** {@inheritDoc} */ @Override public byte[] apply(byte[] e) { final int size = data.length; if (e == null || e.length == 0) e = new byte[start + size]; // Don't allocate more, then required. else if (e.length < start + size) { // Expand stored data array, if it less, then required. byte[] tmp = new byte[start + size]; // Don't allocate more than required. U.arrayCopy(e, 0, tmp, 0, e.length); e = tmp; } // Copy data into entry. U.arrayCopy(data, 0, e, start, size); return e; }
/** * Writes <code>len</code> bytes from the specified byte array * starting at offset <code>off</code> to this byte array output stream. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. */ @Override public void write(byte b[], int off, int len) { if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) throw new IndexOutOfBoundsException(); else if (len == 0) return; int newCnt = cnt + len; if (newCnt > buf.length) buf = Arrays.copyOf(buf, Math.max(buf.length << 1, newCnt)); U.arrayCopy(b, off, buf, cnt, len); cnt = newCnt; }
/** * @param bytes Byte to add. * @param off Offset at which to add. * @param len Number of bytes to add. */ public void add(byte[] bytes, int off, int len) { requestFreeSize(len); U.arrayCopy(bytes, off, data, size, len); size += len; }
/** * @param b Buffer to copy from. * @param off Offset in source buffer. * @param len Length. * @param resBuf Result buffer. * @param resOff Result offset. */ private void messageToBuffer(byte[] b, int off, int len, byte[] resBuf, int resOff) { assert b.length == len; assert off == 0; assert resBuf.length >= resOff + len + 4; U.intToBytes(len, resBuf, resOff); U.arrayCopy(b, off, resBuf, resOff + 4, len); }
assert prevEnd < valPos : prevEnd + " " + valPos; U.arrayCopy(bytes, valPos, bytes, prevEnd, val.len);
U.arrayCopy(block, blockOff, buf, off, len);
U.arrayCopy(block, blockOff, buf, off, len);
/** {@inheritDoc} */ @Override protected synchronized void storeDataBlock(ByteBuffer block) throws GridException, IOException { int writeLen = block.remaining(); preStoreDataBlocks(null, writeLen); int blockSize = fileInfo.blockSize(); // If data length is not enough to fill full block, fill the remainder and return. if (remainderDataLen + writeLen < blockSize) { if (remainder == null) remainder = new byte[blockSize]; else if (remainder.length != blockSize) { assert remainderDataLen == remainder.length; byte[] allocated = new byte[blockSize]; U.arrayCopy(remainder, 0, allocated, 0, remainder.length); remainder = allocated; } block.get(remainder, remainderDataLen, writeLen); remainderDataLen += writeLen; } else { remainder = data.storeDataBlocks(fileInfo, fileInfo.length() + space, remainder, remainderDataLen, block, false, streamRange, batch); remainderDataLen = remainder == null ? 0 : remainder.length; } }
/** {@inheritDoc} */ @Override protected synchronized void storeDataBlock(ByteBuffer block) throws GridException, IOException { int writeLen = block.remaining(); preStoreDataBlocks(null, writeLen); int blockSize = fileInfo.blockSize(); // If data length is not enough to fill full block, fill the remainder and return. if (remainderDataLen + writeLen < blockSize) { if (remainder == null) remainder = new byte[blockSize]; else if (remainder.length != blockSize) { assert remainderDataLen == remainder.length; byte[] allocated = new byte[blockSize]; U.arrayCopy(remainder, 0, allocated, 0, remainder.length); remainder = allocated; } block.get(remainder, remainderDataLen, writeLen); remainderDataLen += writeLen; } else { remainder = data.storeDataBlocks(fileInfo, fileInfo.length() + space, remainder, remainderDataLen, block, false, streamRange, batch); remainderDataLen = remainder == null ? 0 : remainder.length; } }
byte[] data = new byte[packet.length - 1]; U.arrayCopy(packet, 1, data, 0, data.length);
/** {@inheritDoc} */ @Override protected synchronized void storeDataBlocks(DataInput in, int len) throws GridException, IOException { preStoreDataBlocks(in, len); int blockSize = fileInfo.blockSize(); // If data length is not enough to fill full block, fill the remainder and return. if (remainderDataLen + len < blockSize) { if (remainder == null) remainder = new byte[blockSize]; else if (remainder.length != blockSize) { assert remainderDataLen == remainder.length; byte[] allocated = new byte[blockSize]; U.arrayCopy(remainder, 0, allocated, 0, remainder.length); remainder = allocated; } in.readFully(remainder, remainderDataLen, len); remainderDataLen += len; } else { remainder = data.storeDataBlocks(fileInfo, fileInfo.length() + space, remainder, remainderDataLen, in, len, false, streamRange, batch); remainderDataLen = remainder == null ? 0 : remainder.length; } }
/** {@inheritDoc} */ @Override protected synchronized void storeDataBlocks(DataInput in, int len) throws GridException, IOException { preStoreDataBlocks(in, len); int blockSize = fileInfo.blockSize(); // If data length is not enough to fill full block, fill the remainder and return. if (remainderDataLen + len < blockSize) { if (remainder == null) remainder = new byte[blockSize]; else if (remainder.length != blockSize) { assert remainderDataLen == remainder.length; byte[] allocated = new byte[blockSize]; U.arrayCopy(remainder, 0, allocated, 0, remainder.length); remainder = allocated; } in.readFully(remainder, remainderDataLen, len); remainderDataLen += len; } else { remainder = data.storeDataBlocks(fileInfo, fileInfo.length() + space, remainder, remainderDataLen, in, len, false, streamRange, batch); remainderDataLen = remainder == null ? 0 : remainder.length; } }
/** * Updates meta data. * * @throws SQLException In case of error. */ private void updateMetaData() throws SQLException { if (conn.isClosed()) throw new SQLException("Connection is closed."); try { byte[] packet = conn.client().compute().execute(TASK_NAME, conn.cacheName()); byte status = packet[0]; byte[] data = new byte[packet.length - 1]; U.arrayCopy(packet, 1, data, 0, data.length); if (status == 1) throw JU.unmarshalError(data); else { List<Object> res = JU.unmarshal(data); meta = (Map<String, Map<String, Map<String, String>>>)res.get(0); indexes = (Collection<List<Object>>)res.get(1); } } catch (GridClientException e) { throw new SQLException("Failed to get meta data from GridGain.", e); } }
/** {@inheritDoc} */ @Override public byte[] reduce(List<GridComputeJobResult> results) throws GridException { byte status; byte[] bytes; GridComputeJobResult res = F.first(results); if (res.getException() == null) { status = 0; bytes = MARSHALLER.marshal(res.getData()); } else { status = 1; bytes = MARSHALLER.marshal(new SQLException(res.getException().getMessage())); } byte[] packet = new byte[bytes.length + 1]; packet[0] = status; U.arrayCopy(bytes, 0, packet, 1, bytes.length); return packet; }