code: private byte[] shrinkBuffer(byte[] buffer, int size)
      {
          if (size == 0) {
              return null;
          }
  
          if (size == buffer.length) {
              return buffer;
          }
  
          byte[] output = new byte[size];
          System.arraycopy(buffer, 0, output, 0, size);
          return output;
      }
docs: Return a buffer of {@code size} bytes containing the {@code size} first byte of {@code buffer}.
  
  @param buffer the buffer.
  @param size the size.
  @return null if size is 0, the buffer if it has the right size, or a new truncated copy of buffer.