<commit_before>package info.bowkett.joxy;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by IntelliJ IDEA.
 * User: jbowkett
 * Date: Jul 24, 2013
 * Time: 9:29:34 PM
 * To change this template use File | Settings | File Templates.
 */
public class RequestReader {
  private static final int BUFFER_SIZE = 32768;

  public byte [] readRequest(InputStream incomingInputStream) throws IOException {
    byte [] request = new byte[0];
    try {
      final byte[] buffer = new byte[BUFFER_SIZE];
      int bytesRead;

      do{
        bytesRead = incomingInputStream.read(buffer, 0, BUFFER_SIZE);
        request = appendBuffer(request, buffer, bytesRead);
      }
      while (bytesRead != -1 && bytesRead == BUFFER_SIZE);

      return request;
    }
    catch (IOException e) {
      System.out.println("Cannot read from socket:" + e.getMessage());
      throw e;
    }
    finally {
      try {
        if (incomingInputStream != null) incomingInputStream.close();
      }
      catch (Exception e) {
      }//do nothing as closing
    }
  }

  private byte[] appendBuffer(byte[] previouslyBuffered, byte[] bufferToAppend, int bytesRead) {
    byte[] expandedBuffer = previouslyBuffered;
    if(bytesRead > -1) {
      expandedBuffer = new byte[previouslyBuffered.length + bytesRead];
      System.arraycopy(bufferToAppend, 0, expandedBuffer, previouslyBuffered.length, bytesRead);
    }
    return expandedBuffer;
  }
}<commit_msg>tidied implementation, old impl was not reading everything<commit_after>package info.bowkett.joxy;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by IntelliJ IDEA.
 * User: jbowkett
 * Date: Jul 24, 2013
 * Time: 9:29:34 PM
 * To change this template use File | Settings | File Templates.
 */
public class RequestReader {
  private static final int BUFFER_SIZE = 32768;

  public byte [] readRequest(InputStream incomingInputStream) throws IOException {
    try {
      final byte[] readBuffer = new byte[BUFFER_SIZE];

      final ByteArrayOutputStream bufferToReturn = new ByteArrayOutputStream();

      int bytesRead;

      while((bytesRead = incomingInputStream.read(readBuffer)) >= 0 ){
        bufferToReturn.write(readBuffer, 0, bytesRead);
      }
      bufferToReturn.flush();
      return bufferToReturn.toByteArray();
    }
    catch (IOException e) {
      System.out.println("Cannot read from socket:" + e.getMessage());
      throw e;
    }
    finally {
      try {
//        if (incomingInputStream != null) incomingInputStream.close();
      }
      catch (Exception e) {
      }//do nothing as closing
    }
  }
}
{'fraction_non_alphanumeric': 0.10462928114414753, 'fraction_numerical': 0.014678208505833647, 'mean_word_length': 3.1209302325581394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6714195', 'n_tokens_mistral': 783, 'n_tokens_neox': 746, 'n_words': 215}