<commit_before>package com.github.ambry.network;

import java.io.EOFException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
import java.nio.ByteBuffer;


/**
 * A byte buffer version of Receive to buffer the incoming request or response.
 */
public class BoundedByteBufferReceive implements Receive {

  private ByteBuffer buffer = null;
  private ByteBuffer sizeBuffer;
  private long sizeToRead;
  private long sizeRead;
  private Logger logger = LoggerFactory.getLogger(getClass());

  public BoundedByteBufferReceive() {
    sizeToRead = 0;
    sizeRead = 0;
    sizeBuffer = ByteBuffer.allocate(8);
  }

  @Override
  public boolean isReadComplete() {
    return !(buffer == null || sizeRead < sizeToRead);
  }

  @Override
  public long readFrom(ReadableByteChannel channel)
      throws IOException {
    long bytesRead = 0;
    if (buffer == null) {
      bytesRead = channel.read(sizeBuffer);
      if (bytesRead < 0) {
        throw new EOFException();
      }
      if (sizeBuffer.position() == sizeBuffer.capacity()) {
        sizeBuffer.flip();
        // for now we support only intmax size. We need to extend it to streaming
        sizeToRead = sizeBuffer.getLong();
        sizeRead += 8;
        bytesRead += 8;
        buffer = ByteBuffer.allocate((int) sizeToRead - 8);
      }
    }
    if (buffer != null && sizeRead < sizeToRead) {
      long bytesReadFromChannel = channel.read(buffer);
      if (bytesReadFromChannel < 0) {
        throw new EOFException();
      }
      sizeRead += bytesReadFromChannel;
      bytesRead += bytesReadFromChannel;
      if (sizeRead == sizeToRead) {
        buffer.flip();
      }
    }
    logger.trace("size read from channel {}", sizeRead);
    return bytesRead;
  }<commit_msg>remove outdated comments<commit_after>package com.github.ambry.network;

import java.io.EOFException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
import java.nio.ByteBuffer;


/**
 * A byte buffer version of Receive to buffer the incoming request or response.
 */
public class BoundedByteBufferReceive implements Receive {

  private ByteBuffer buffer = null;
  private ByteBuffer sizeBuffer;
  private long sizeToRead;
  private long sizeRead;
  private Logger logger = LoggerFactory.getLogger(getClass());

  public BoundedByteBufferReceive() {
    sizeToRead = 0;
    sizeRead = 0;
    sizeBuffer = ByteBuffer.allocate(8);
  }

  @Override
  public boolean isReadComplete() {
    return !(buffer == null || sizeRead < sizeToRead);
  }

  @Override
  public long readFrom(ReadableByteChannel channel)
      throws IOException {
    long bytesRead = 0;
    if (buffer == null) {
      bytesRead = channel.read(sizeBuffer);
      if (bytesRead < 0) {
        throw new EOFException();
      }
      if (sizeBuffer.position() == sizeBuffer.capacity()) {
        sizeBuffer.flip();
        sizeToRead = sizeBuffer.getLong();
        sizeRead += 8;
        bytesRead += 8;
        buffer = ByteBuffer.allocate((int) sizeToRead - 8);
      }
    }
    if (buffer != null && sizeRead < sizeToRead) {
      long bytesReadFromChannel = channel.read(buffer);
      if (bytesReadFromChannel < 0) {
        throw new EOFException();
      }
      sizeRead += bytesReadFromChannel;
      bytesRead += bytesReadFromChannel;
      if (sizeRead == sizeToRead) {
        buffer.flip();
      }
    }
    logger.trace("size read from channel {}", sizeRead);
    return bytesRead;
  }
{'fraction_non_alphanumeric': 0.10248533929070092, 'fraction_numerical': 0.006143535325328121, 'mean_word_length': 3.0202020202020203, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6819202', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1020, 'n_words': 276}