httpcommonlib/src/main/java/com/streamsets/pipeline/lib/sdcipc/SdcIpcRequestFragmenter.java
static byte[] extract(InputStream is, ByteArrayOutputStream overflowBuffer, int limit) throws IOException {
    // the inputstream we get has been already stripped of the magic byte if first call
    byte[] message;
    if (copy(is, overflowBuffer, limit - overflowBuffer.size())) {
      // got rest of payload without exceeding the max message size
      if (overflowBuffer.size() == 0) {
        // there is no more payload
        message = null;
      } else {
        // extract the rest payload and prefix it with the magic byte
        byte[] data = overflowBuffer.toByteArray();
        message = new byte[data.length + 1];
        message[0] = JSON1_MAGIC_NUMBER;
        System.arraycopy(data, 0, message, 1, data.length);
        overflowBuffer.reset();
      }
    } else {
      // got partial payload, exceeded the max message size
      byte[] data = overflowBuffer.toByteArray();
      // find last full record in partial payload
      int lastEOL = findEndOfLastLineBeforeLimit(data, limit);
      if (lastEOL == -1) {
        throw new IOException(Utils.format("Maximum message size '{}' exceeded", limit));
      }
      // extract payload up to last EOL and prefix with the magic byte
      message = new byte[lastEOL + 1];
      message[0] = JSON1_MAGIC_NUMBER;
      System.arraycopy(data, 0, message, 1, lastEOL);

      // put back in the stream buffer the portion of the payload that did not make it to the message
      overflowBuffer.reset();
      overflowBuffer.write(data, lastEOL, data.length - lastEOL);
    }
    return message;
  }
static byte[] extract(InputStream is, ByteArrayOutputStream overflowBuffer, int limit) throws IOException {
    // the inputstream we get has been already stripped of the magic byte if first call
    byte[] message;
    if (copy(is, overflowBuffer, limit - overflowBuffer.size())) {
      // got rest of payload without exceeding the max message size
      if (overflowBuffer.size() == 0) {
        // there is no more payload
        message = null;
      } else {
        // extract the rest payload and prefix it with the magic byte
        byte[] data = overflowBuffer.toByteArray();
        message = new byte[data.length + 1];
        message[0] = JSON1_MAGIC_NUMBER;
        System.arraycopy(data, 0, message, 1, data.length);
        overflowBuffer.reset();
      }
    } else {
      // got partial payload, exceeded the max message size
      byte[] data = overflowBuffer.toByteArray();
      // find last full record in partial payload
      int lastEOL = findEndOfLastLineBeforeLimit(data, limit);
      if (lastEOL == -1) {
        throw new IOException(Utils.format("Maximum message size '{}' exceeded", limit));
      }
      // extract payload up to last EOL and prefix with the magic byte
      message = new byte[lastEOL + 1];
      message[0] = JSON1_MAGIC_NUMBER;
      System.arraycopy(data, 0, message, 1, lastEOL);

      // put back in the stream buffer the portion of the payload that did not make it to the message
      overflowBuffer.reset();
      overflowBuffer.write(data, lastEOL, data.length - lastEOL);
    }
    return message;
  }
static byte [ ] extract ( InputStream is , ByteArrayOutputStream overflowBuffer , int limit ) throws IOException { // the inputstream we get has been already stripped of the magic byte if first call byte [ ] message ; if ( copy ( is , overflowBuffer , limit - overflowBuffer . size ( ) ) ) { // got rest of payload without exceeding the max message size if ( overflowBuffer . size ( ) == 0 ) { // there is no more payload message = null ; } else { // extract the rest payload and prefix it with the magic byte byte [ ] data = overflowBuffer . toByteArray ( ) ; message = new byte [ data . length + 1 ] ; message [ 0 ] = JSON1_MAGIC_NUMBER ; System . arraycopy ( data , 0 , message , 1 , data . length ) ; overflowBuffer . reset ( ) ; } } else { // got partial payload, exceeded the max message size byte [ ] data = overflowBuffer . toByteArray ( ) ; // find last full record in partial payload int lastEOL = findEndOfLastLineBeforeLimit ( data , limit ) ; if ( lastEOL == - 1 ) { throw new IOException ( Utils . format ( "Maximum message size '{}' exceeded" , limit ) ) ; } // extract payload up to last EOL and prefix with the magic byte message = new byte [ lastEOL + 1 ] ; message [ 0 ] = JSON1_MAGIC_NUMBER ; System . arraycopy ( data , 0 , message , 1 , lastEOL ) ; // put back in the stream buffer the portion of the payload that did not make it to the message overflowBuffer . reset ( ) ; overflowBuffer . write ( data , lastEOL , data . length - lastEOL ) ; } return message ; }
max array size will be limit + 1 (because the magic byte is being added)
max array size will be limit + 1 ( because the magic byte is being added )