/*
This method receiving the buffer size with package visibility allows
testing different buffer sizes.
348705
void parseDocument(final Reader reader, final int suggestedBufferSize, final ITextHandler handler)
            throws TextParseException {


        final long parsingStartTimeNanos = System.nanoTime();

        char[] buffer = null;

        try {

            final TextParseStatus status = new TextParseStatus();

            handler.handleDocumentStart(parsingStartTimeNanos, 1, 1);

            int bufferSize = suggestedBufferSize;
            buffer = this.pool.allocateBuffer(bufferSize);

            int bufferContentSize = reader.read(buffer);

            boolean cont = (bufferContentSize != -1);

            status.offset = -1;
            status.line = 1;
            status.col = 1;
            status.inStructure = false;
            status.inCommentLine = false;
            status.literalMarker = (char)0;

            while (cont) {

                parseBuffer(buffer, 0, bufferContentSize, handler, status);

                int readOffset = 0;
                int readLen = bufferSize;

                if (status.offset == 0) {

                    if (bufferContentSize == bufferSize) {
                        // Buffer is not big enough, double it!

                        char[] newBuffer = null;
                        try {

                            bufferSize *= 2;

                            newBuffer = this.pool.allocateBuffer(bufferSize);
                            System.arraycopy(buffer, 0, newBuffer, 0, bufferContentSize);

                            this.pool.releaseBuffer(buffer);

                            buffer = newBuffer;

                        } catch (final Exception ignored) {
                            this.pool.releaseBuffer(newBuffer);
                        }

                    }

                    // it's possible for two reads to occur in a row and 1) read less than the bufferSize and 2)
                    // still not find the next tag/end of structure
                    readOffset = bufferContentSize;
                    readLen = bufferSize - readOffset;

                } else if (status.offset < bufferContentSize) {

                    System.arraycopy(buffer, status.offset, buffer, 0, bufferContentSize - status.offset);

                    readOffset = bufferContentSize - status.offset;
                    readLen = bufferSize - readOffset;

                    status.offset = 0;
                    bufferContentSize = readOffset;

                }

                final int read = reader.read(buffer, readOffset, readLen);
                if (read != -1) {
                    bufferContentSize = readOffset + read;
                } else {
                    cont = false;
                }

            }

            // Iteration done, now it's time to clean up in case we still have some text to be notified

            int lastLine = status.line;
            int lastCol = status.col;

            final int lastStart = status.offset;
            final int lastLen = bufferContentSize - lastStart;

            if (lastLen > 0) {

                // Note that comment lines will not be parsed in a special way, only as mere texts, because they
                // cannot contain 'natural' inlined expressions (though they may contain normal inlined expressions)
                if (status.inStructure && !status.inCommentLine) {
                    throw new TextParseException(
                            "Incomplete structure: \"" + new String(buffer, lastStart, lastLen) + "\"", status.line, status.col);
                }

                handler.handleText(buffer, lastStart, lastLen, status.line, status.col);

                // As we have produced an additional text event, we need to fast-forward the
                // lastLine and lastCol position to include the last text structure.
                for (int i = lastStart; i < (lastStart + lastLen); i++) {
                    final char c = buffer[i];
                    if (c == '\n') {
                        lastLine++;
                        lastCol = 1;
                    } else {
                        lastCol++;
                    }

                }

            }

            final long parsingEndTimeNanos = System.nanoTime();
            handler.handleDocumentEnd(parsingEndTimeNanos, (parsingEndTimeNanos - parsingStartTimeNanos), lastLine, lastCol);

        } catch (final TextParseException e) {
            throw e;
        } catch (final Exception e) {
            throw new TextParseException(e);
        } finally {
            this.pool.releaseBuffer(buffer);
            try {
                reader.close();
            } catch (final Throwable ignored) {
                // This exception can be safely ignored
            }
        }

    }
838040
private static String checkBufferSize(final String str) {
        // try to get value
        int nb_mega;
        try {
            nb_mega = Integer.parseInt(str);
        } catch (final NumberFormatException e) {
            return null;
        }

        // Compute the real size and the power of 2
        final long size = (long) nb_mega * 1024 * 1024;
        long l = size;
        int cnt;
        for (cnt = 0; l > 0; cnt++) {
            l >>= 1;
        }
        cnt--;

        // Check if number ob Mb is not power of 2
        if (Math.pow(2, cnt) < size) {
            cnt++;
        }
        System.out.println(nb_mega + " Mbytes  (2^" + cnt + ")");

        final int jacorb_size = cnt - 4;
        return Integer.toString(jacorb_size);
    }
1315058
private static String checkORBgiopMaxMsgSize() {
        /*
         * JacORB definition (see jacorb.properties file):
         *
         * This is NOT the maximum buffer size that can be used, but just the
         * largest size of buffers that will be kept and managed. This value
         * will be added to an internal constant of 5, so the real value in
         * bytes is 2**(5+maxManagedBufSize-1). You only need to increase this
         * value if you are dealing with LOTS of LARGE data structures. You may
         * decrease it to make the buffer manager release large buffers
         * immediately rather than keeping them for later reuse.
         */
        String str = "20"; // Set to 16 Mbytes

        // Check if environment ask for bigger size.
        String tmp = ApiUtil.getORBgiopMaxMsgSize();
        if (tmp != null) {
            if ((tmp = checkBufferSize(tmp)) != null) {
                str = tmp;
            }
        }
        return str;
    }
352275
public void setBufferSize(int size)
    {
        HttpOutputStream out = (HttpOutputStream)_httpResponse.getOutputStream();
        if (out.isWritten()  || _writer!=null && _writer.isWritten())
            throw new IllegalStateException("Output written");
        out.setBufferSize(size);
    }
1290008
function ByteBuffer(size) {
                /*private*/ this.bigEndian = true;
                this.bytes = null;
                this.cursor = 0;
                this.bytes = (function (s) { var a = []; while (s-- > 0)
                    a.push(0); return a; })(size);
                this.cursor = 0;
            }
783487
private int findFrameSizeValueLength(final ByteBuf buffer) {
        final int readerIndex = buffer.readerIndex();
        int index = buffer.forEachByte(BYTE_PROCESSOR);

        if (index >= 0) {
            return index - readerIndex;
        } else {
            return -1;
        }
    }
767513
public final void increaseReadBufferSize() {
        if (AbstractIoSessionConfig.ENABLE_BUFFER_SIZE) {
            System.out.println("AbstractIoSession.increaseReadBufferSize()");
            int newReadBufferSize = getConfig().getReadBufferSize() << 1;
            if (newReadBufferSize <= getConfig().getMaxReadBufferSize()) {
                getConfig().setReadBufferSize(newReadBufferSize);
            } else {
                getConfig().setReadBufferSize(getConfig().getMaxReadBufferSize());
            }
        }

        deferDecreaseReadBuffer = true;
    }
484895
private static @Nullable Pair<Integer, Integer> getVP8LDimension(final InputStream is)
      throws IOException {
    // Skip 4 bytes
    getInt(is);
    //We have a check here
    final byte check = getByte(is);
    if (check != 0x2F) {
      return null;
    }
    int data1 = ((byte) is.read()) & 0xFF;
    int data2 = ((byte) is.read()) & 0xFF;
    int data3 = ((byte) is.read()) & 0xFF;
    int data4 = ((byte) is.read()) & 0xFF;
    // In this case the bits for size are 14!!! The sizes are -1!!!
    final int width = ((data2 & 0x3F) << 8 | data1) + 1;
    final int height = ((data4 & 0x0F) << 10 | data3 << 2 | (data2 & 0xC0) >> 6) + 1;
    return new Pair<>(width, height);
  }
1291573
private void parseOutgoingBufferSize(Map<Object, Object> props) {
        Object value = props.get(HttpConfigConstants.PROPNAME_OUTGOING_HDR_BUFFSIZE);
        if (null != value) {
            try {
                this.outgoingHdrBuffSize = rangeLimit(convertInteger(value), HttpConfigConstants.MIN_BUFFER_SIZE, HttpConfigConstants.MAX_BUFFER_SIZE);
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(tc, "Config: Outgoing hdr buffer size is " + getOutgoingHdrBufferSize());
                }
            } catch (NumberFormatException nfe) {
                FFDCFilter.processException(nfe, getClass().getName() + ".parseOutgoingBufferSize", "1");
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(tc, "Config: Invalid outgoing header buffer size; " + value);
                }
            }
        }
    }
927759
public static int cusolverDnSsygvd_bufferSize(
        cusolverDnHandle handle, 
        int itype, 
        int jobz, 
        int uplo, 
        int n, 
        Pointer A, 
        int lda, 
        Pointer B, 
        int ldb, 
        Pointer W, 
        int[] lwork)
    {
        return checkResult(cusolverDnSsygvd_bufferSizeNative(handle, itype, jobz, uplo, n, A, lda, B, ldb, W, lwork));
    }
964022
protected final void initSrcBuffer(int sizeBytes) {
        ChannelOptions config = channel.options();
        src = (S) newByteBuffer(sizeBytes, config.getOption(DIRECT_BUF));
    }
769590
byte[] getBuffer()
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled()) {
            trace.entry(this,
                        cclass,
                        "getBuffer");
            trace.exit(this,
                       cclass,
                       "getBuffer",
                       "return length="
                                       + buf.length);
        }
        return buf;
    }
461113
private synchronized void readBlockSizeInfo() throws IOException {
    if (!transferBlockSize) {
      return;
    }
    blkLenInfoUpdated = true;
    isBlockFinalized = in.readBoolean();
    updatedBlockLength = in.readLong();
    if (dataTransferVersion >= DataTransferProtocol.READ_PROFILING_VERSION) {
      readDataNodeProfilingData();
    }
    
    if (LOG.isDebugEnabled()) {
      LOG.debug("ifBlockComplete? " + isBlockFinalized + " block size: "
          + updatedBlockLength);
    }      
  }
645007
public void checkSkipReadForFixLengthPart(AbstractPagedInputView source) throws IOException {
		// skip if there is no enough size.
		// Note: Use currentSegmentLimit instead of segmentSize.
		int available = source.getCurrentSegmentLimit() - source.getCurrentPositionInSegment();
		if (available < getSerializedRowFixedPartLength()) {
			source.advance();
		}
	}
495462
function ensureBufferSize(buffer, minimumSize, contentSize) {
        if (buffer.length >= minimumSize) {
            return buffer;
        }
        var newBuffer = new Buffer(minimumSize);
        if (contentSize) {
            buffer.copy(newBuffer, 0, 0, contentSize);
        } else {
            buffer.copy(newBuffer);
        }
        return newBuffer;
    }
968475
function ByteBuffer(arg) {
    var initial_size;
    if (arg == null) {
        initial_size = 1024 * 1024;
    } else if (typeof arg === "number") {
        initial_size = arg;
    } else if (arg instanceof Uint8Array) {
        this.buffer = arg;
        this.position = 0;  // Overwrite
        return;
    } else {
        // typeof arg -> String
        throw typeof arg + " is invalid parameter type for ByteBuffer constructor";
    }
    // arg is null or number
    this.buffer = new Uint8Array(initial_size);
    this.position = 0;
}
1027804
@Override
	public long getSize() throws IOException {
		if (length < 0) {
			try {
				if (activeMethod != null) {
					length = activeMethod.getResponseContentLength();
				} else {
					acquireLength();
				}
			} catch (URISyntaxException e) {
				throw new IOException(e);
			}
		}
		return length;
	}