If successful, allocates a new buffer containing the uncompresse data and
returns the uncompressed length. Else, returns 0.

@return
438533
public int /* udword_ppt */decompress(
			final short[] /* const void* */source, int /* udword_ppt */size,
			final Decompressed decomp) {
		this.source = source;
		globalError = false; // assume no error

		readPtr = 0;

		if (!isCompressed(source, size)) {
			return 0;
		}

		// Uncompressed size is stored at end of source file.
		// Backwards decompression.
		readPtr += (size - 4);

		int /* udword_ppt */lastDword = readBEdword(source, readPtr);
		// Uncompressed length in bits 31-8 of last dword.
		int /* udword_ppt */outputLen = lastDword >> 8;

		// Allocate memory for output data.
		dest = new short /* ubyte_ppt */[outputLen];

		// Lowest dest. address for range-checks.
		// Put destptr to end of uncompressed data.
		writePtr = outputLen;

		// Read number of unused bits in 1st data dword
		// from lowest bits 7-0 of last dword.
		bits = 32 - (lastDword & 0xFF);

		// Main decompression loop.
		bytesTOdword();
		if (bits != 32)
			current >>= (32 - bits);
		do {
			if (readBits(1) == 0)
				bytes();
			if (writePtr > 0)
				sequence();
			if (globalError) {
				// statusString already set.
				outputLen = 0; // unsuccessful decompression
				break;
			}
		} while (writePtr > 0);

		// Finished.

		if (outputLen > 0) // successful
		{
			decomp.destBufRef = new short[dest.length];
			// Free any previously existing destination buffer.
			System.arraycopy(dest, 0, decomp.destBufRef, 0, dest.length);
		}

		return outputLen;
	}
734173
public byte[] getFullBBuffer(int minSize)
    {
        byte[] result = null;
        if (mFullBBuffer != null && mFullBBuffer.length >= minSize) {
            result = mFullBBuffer;
            mFullBBuffer = null;
        }
//System.err.println("DEBUG: Alloc BFull: "+result);
        return result;
    }
546234
@Override
    public long size() {
        if (this.isDirectory()) {
            return -1L;
        }

        final Asset asset = this.getArchive().get(this.path.toString()).getAsset();
        final InputStream stream = asset.openStream();
        int totalRead = 0;
        final byte[] buffer = new byte[1024 * 4];
        int read = 0;
        try {
            while ((read = stream.read(buffer, 0, buffer.length)) != -1) {
                totalRead += read;
            }
        } catch (final IOException ioe) {
            throw new RuntimeException(ioe);
        }

        return totalRead;
    }
650356
private ByteBuf tryCompress(ByteBuf buf) {
        final int uncompressedLength = buf.readableBytes();
        final byte[] compressed = new byte[Snappy.maxCompressedLength(uncompressedLength)];
        final int compressedLength;

        if (buf.hasArray()) {
            // Save a memory copy by reading directly from the backing array.
            compressedLength = Snappy.compress(
                    buf.array(), buf.arrayOffset() + buf.readerIndex(), uncompressedLength, compressed, 0);
        } else {
            final byte[] data = new byte[buf.readableBytes()];
            buf.getBytes(buf.readerIndex(), data);
            compressedLength = Snappy.compress(data, 0, data.length, compressed, 0);
        }

        final double ratio = (double) compressedLength / uncompressedLength;
        if (ratio > minCompressionRatio) {
            // Compression doesn't make enough of a difference.
            return null;
        }

        // Save a memory copy by deferring trimming until we know the result will be used.
        final byte[] trimmedCompressed = Arrays.copyOf(compressed, compressedLength);
        return Unpooled.wrappedBuffer(trimmedCompressed);
    }
250793
public long getAlignedSizeOfRaw() {
        long sizeOfRaw = get(SIZE_OF_RAW_DATA);
        if (sizeOfRaw == (sizeOfRaw & ~0xfff)) {
            return sizeOfRaw;
        }
        long result = (sizeOfRaw + 0xfff) & ~0xfff;
        assert result % 4096 == 0;
        return result;
    }
1184291
private boolean makeSpace() {
        clearCaches();
        int offset = savedScannerPosition == -1 ?
            position : savedScannerPosition;
        buf.position(offset);
        // Gain space by compacting buffer
        if (offset > 0) {
            buf.compact();
            translateSavedIndexes(offset);
            position -= offset;
            buf.flip();
            return true;
        }
        // Gain space by growing buffer
        int newSize = buf.capacity() * 2;
        CharBuffer newBuf = CharBuffer.allocate(newSize);
        newBuf.put(buf);
        newBuf.flip();
        translateSavedIndexes(offset);
        position -= offset;
        buf = newBuf;
        matcher.reset(buf);
        return true;
    }
1129976
public int getSize() {
        int ret = 0;
        MethodState state = firstPointer;
        while (state != null) {
            ret++;
            state = state.getNext();
        }
        return ret;
    }
275950
@Override
  public Compressor createCompressor() {
    if (!isNativeCodeLoaded()) {
      throw new RuntimeException("native lz4 library not available");
    }
    int bufferSize = conf.getInt(
        IO_COMPRESSION_CODEC_LZ4_BUFFERSIZE_KEY,
        IO_COMPRESSION_CODEC_LZ4_BUFFERSIZE_DEFAULT);
    boolean useLz4HC = conf.getBoolean(
        IO_COMPRESSION_CODEC_LZ4_USELZ4HC_KEY,
        IO_COMPRESSION_CODEC_LZ4_USELZ4HC_DEFAULT); 
    return new Lz4Compressor(bufferSize, useLz4HC);
  }
860502
public static long sizeOnHeapOf(ByteBuffer buffer)
    {
        if (buffer.isDirect())
            return BUFFER_EMPTY_SIZE;
        // if we're only referencing a sub-portion of the ByteBuffer, don't count the array overhead (assume it's slab
        // allocated, so amortized over all the allocations the overhead is negligible and better to undercount than over)
        if (buffer.capacity() > buffer.remaining())
            return buffer.remaining();
        return BUFFER_EMPTY_SIZE + sizeOfArray(buffer.capacity(), 1);
    }
422163
public synchronized int allocateNextChunk() {
        if ((used_bytes.longValue() + (long) mem_chunksize) > max_allowed_bytes) {
            logger.info("No memory left");
            return 0;
        }
        used_bytes.set(used_bytes.longValue() + (long) mem_chunksize);
        return mem_chunksize;
    }
755581
public int shrink()
    {
        byte[] old = buf;
        if (pos == 0)
        {
            return 0; // nothing to do
        }
        int n = old.length - pos;
        int m;
        int p;
        int s;
        int l;
        if (n < origsize)
        {
            buf = new byte[origsize];
            p = pos;
            s = origsize - n;
            l = old.length - p;
            m = old.length - origsize;
            pos = s;
        }
        else
        {
            buf = new byte[n];
            p = pos;
            s = 0;
            l = n;
            m = old.length - l;
            pos = 0;
        }
        System.arraycopy(old, p, buf, s, l);
        return m;
    }
144374
public byte getByte() {
		assert hasRemaining();
		ByteBuf buf = bufs[first];
		assert buf.canRead();
		byte result = buf.get();
		if (!buf.canRead()) {
			doPoll();
		}
		return result;
	}
1332358
public final long getMaximumSize()
    {
        long result = 0;
        result = result + _storedItemManager.getMaximumSize();
        result = result + _unstoredItemManager.getMaximumSize();
        return result;
    }
136821
@Trivial
    protected synchronized int size(int bufferType) {
        if (bufferType == EXPLICIT_BUFFER) {
            return this.explicitBuffer.size();
        } else if (bufferType == SCAN_BUFFER) {
            return this.scanBuffer.size();
        } else if (bufferType == GC_BUFFER) {
            return this.garbageCollectorBuffer.size();
        }
        return 0;
    }
72357
private int allocate(int size)
    {
        while (true)
        {
            int prev = allocatePosition.get();
            int next = prev + size;
            if (next >= buffer.capacity())
                return -1;
            if (allocatePosition.compareAndSet(prev, next))
                return prev;
        }
    }
1091912
public ByteBuffer serialize () {

        final int size = uncroppedSize();
        if (size == 0) return ByteBuffer.allocate(0);// empty data segment

        // calculate sense length
        int senseLength;
        if (senseData == null)
            senseLength = 0;
        else
            senseLength = senseData.size();

        // allocate buffer of appropriate size
        final ByteBuffer buffer = ByteBuffer.allocate(size);

        // write sense length field
        ReadWrite.writeTwoByteInt(buffer,// buffer
                senseLength,// value
                0);// index

        // write sense data
        if (senseData != null) senseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH);

        // write and SCSI response data
        if (responseData != null) responseData.serialize(buffer, SENSE_LENGTH_FIELD_LENGTH + senseLength);

        if (allocationLength > 0 && buffer.capacity() > allocationLength) {
            /*
             * If the allocation length variable is valid and the response data segment is larger than the data-in
             * buffer allocated by the initiator, limit the number of bytes returned.
             */
            buffer.position(0);
            buffer.limit(allocationLength);
            final ByteBuffer croppedBuffer = ByteBuffer.allocate(allocationLength);
            croppedBuffer.put(buffer);
            return croppedBuffer;
        }

        if (LOGGER.isDebugEnabled()) LOGGER.debug("SCSI Response Data Segment:\n" + Debug.byteBufferToString(buffer));

        return buffer;
    }
334316
public long readUnconsumedDecData() {
        long totalBytesRead = 0L;

        // Determine if data is left over from a former read request.
        if (unconsumedDecData != null) {
            // Left over data exists. Is there enough to satisfy the request?
            if (getBuffer() == null) {
                // Caller needs us to allocate the buffer to return.
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Caller needs buffer, unconsumed data: "
                                 + SSLUtils.getBufferTraceInfo(unconsumedDecData));
                }
                // Note, data of unconsumedDecData buffer array should be starting
                // at position 0 in the first buffer.
                totalBytesRead = SSLUtils.lengthOf(unconsumedDecData, 0);
                // First release any existing buffers in decryptedNetBuffers array.
                cleanupDecBuffers();
                callerRequiredAllocation = true;
                // Note, it is the responsibility of the calling channel to release this buffer.
                decryptedNetBuffers = unconsumedDecData;
                // Set left over buffers to null to note that they are no longer in use.
                unconsumedDecData = null;
                if ((decryptedNetLimitInfo == null)
                    || (decryptedNetLimitInfo.length != decryptedNetBuffers.length)) {
                    decryptedNetLimitInfo = new int[decryptedNetBuffers.length];
                }
                SSLUtils.getBufferLimits(decryptedNetBuffers, decryptedNetLimitInfo);
            } else {
                // Caller provided buffers for read. We need to copy the left over
                // data to those buffers.
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Caller provided buffers, unconsumed data: "
                                 + SSLUtils.getBufferTraceInfo(unconsumedDecData));
                }
                // First release any existing buffers in decryptedNetBuffers array.
                cleanupDecBuffers();
                // The unconsumedDecData buffers have the data to copy to the user buffers.
                // The copyDataToCallerBuffers method copies from decryptedNetBuffers, so assign it.
                decryptedNetBuffers = unconsumedDecData;
                // Copy the outputbuffer to the buffers provided by the caller.
                totalBytesRead = copyDataToCallerBuffers();
                // Null out the reference to the overflow buffers.
                decryptedNetBuffers = null;
            }
        }
        return totalBytesRead;
    }