private static byte[] ensureSize(byte[] buff, int len) { return buff == null || buff.length < len ? DataUtils.newBytes(len) : buff; }
/** * Read a byte array. * * @return the value */ public byte[] readBytes() throws IOException { int len = readInt(); if (len == -1) { return null; } byte[] b = DataUtils.newBytes(len); in.readFully(b); return b; }
private static byte[] getPaddedArrayCopy(byte[] data, int blockSize) { int size = MathUtils.roundUpInt(data.length, blockSize); byte[] newData = DataUtils.newBytes(size); System.arraycopy(data, 0, newData, 0, data.length); return newData; }
@Override public Object read(ByteBuffer buff, int tag) { switch (tag) { case TAG_BIG_INTEGER_0: return BigInteger.ZERO; case TAG_BIG_INTEGER_1: return BigInteger.ONE; case TAG_BIG_INTEGER_SMALL: return BigInteger.valueOf(DataUtils.readVarLong(buff)); } int len = DataUtils.readVarInt(buff); byte[] bytes = DataUtils.newBytes(len); buff.get(bytes); return new BigInteger(bytes); }
@Override public Object read(ByteBuffer buff, int tag) { int len = DataUtils.readVarInt(buff); byte[] data = DataUtils.newBytes(len); buff.get(data); return deserialize(data); }
/** * Compressed the data using the specified algorithm. If no algorithm is * supplied, LZF is used * * @param in the byte array with the original data * @param algorithm the algorithm (LZF, DEFLATE) * @return the compressed data */ public byte[] compress(byte[] in, String algorithm) { int len = in.length; if (in.length < 5) { algorithm = "NO"; } Compressor compress = getCompressor(algorithm); byte[] buff = getBuffer((len < 100 ? len + 100 : len) * 2); int newLen = compress(in, in.length, compress, buff); byte[] out = DataUtils.newBytes(newLen); System.arraycopy(buff, 0, out, 0, newLen); return out; }
ByteBuffer expandPage(ByteBuffer buff, int type, int start, int pageLength) { boolean compressed = (type & PageUtils.PAGE_COMPRESSED) != 0; if (compressed) { Compressor compressor; if ((type & PageUtils.PAGE_COMPRESSED_HIGH) == PageUtils.PAGE_COMPRESSED_HIGH) { compressor = map.getBTreeStorage().getCompressorHigh(); } else { compressor = map.getBTreeStorage().getCompressorFast(); } int lenAdd = DataUtils.readVarInt(buff); int compLen = pageLength + start - buff.position(); byte[] comp = DataUtils.newBytes(compLen); buff.get(comp); int l = compLen + lenAdd; ByteBuffer newBuff = ByteBuffer.allocate(l); compressor.expand(comp, 0, compLen, newBuff.array(), newBuff.arrayOffset(), l); return newBuff; } return buff; }
byte[] data; int len = tag - TAG_BYTE_ARRAY_0_15; data = DataUtils.newBytes(len); buff.get(data); return data;
@Override public Value readValue(ByteBuffer buff, int tag) { switch (tag) { case TAG_BIG_DECIMAL_0: return ZERO; case TAG_BIG_DECIMAL_1: return ONE; case TAG_BIG_DECIMAL_SMALL: return ValueDecimal.get(BigDecimal.valueOf(DataUtils.readVarLong(buff))); case TAG_BIG_DECIMAL_SMALL_SCALED: int scale = DataUtils.readVarInt(buff); return ValueDecimal.get(BigDecimal.valueOf(DataUtils.readVarLong(buff), scale)); } int scale = DataUtils.readVarInt(buff); int len = DataUtils.readVarInt(buff); byte[] bytes = DataUtils.newBytes(len); buff.get(bytes); BigInteger b = new BigInteger(bytes); return ValueDecimal.get(new BigDecimal(b, scale)); } };
/** * Expands the compressed data. * * @param in the byte array with the compressed data * @return the uncompressed data */ public byte[] expand(byte[] in) { int algorithm = in[0]; Compressor compress = getCompressor(algorithm); try { int len = readVariableInt(in, 1); int start = 1 + getVariableIntLength(len); byte[] buff = DataUtils.newBytes(len); compress.expand(in, start, in.length - start, buff, 0, len); return buff; } catch (Exception e) { throw DbException.get(ErrorCode.COMPRESSION_ERROR, e); } }
case Value.JAVA_OBJECT: { int len = readVarInt(buff); byte[] b = DataUtils.newBytes(len); buff.get(b, 0, len); if (type == Value.BYTES) { int smallLen = readVarInt(buff); if (smallLen >= 0) { byte[] small = DataUtils.newBytes(smallLen); buff.get(small, 0, smallLen); return ValueLob.createSmallLob(type, small);
if (compress != null) { int uncompressed = page.getInt(); byte[] buff = DataUtils.newBytes(remainingInBuffer); page.read(buff, 0, remainingInBuffer); page.reset();