Sets the response body to the UTF-8 encoded bytes of {@code body}, chunked every {@code
maxChunkSize} bytes.
971702
public MockResponse setChunkedBody(String body, int maxChunkSize) {
    return setChunkedBody(new Buffer().writeUtf8(body), maxChunkSize);
  }
968532
public static String toStringUTF8(byte[] input)
    {
        if (input == null)
        {
            return null;
        }

        try
        {
            return new String(input, "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            // This won't happen.
            return null;
        }
    }
977873
def to_bytes(x):
    
    if isinstance(x, bytes):
        return x
    if isinstance(x, basestring):
        return x.encode('utf-8')
738070
public void set(final byte[] utf8, final int start, final int len) {
		setCapacity(len, false);
		System.arraycopy(utf8, start, bytes, 0, len);
		this.length = len;
		this.hash = 0;
	}
47296
public void setResponse(String response) {
		this.response = response;
		try {
			this.responseLength = response.getBytes("UTF-8").length;
		} catch (UnsupportedEncodingException e) {
			this.responseLength = response.length();
		}
	}
1100585
private int utf8Position(int charPosition) {
    int pos = offset;
    for (int i = 0; i < charPosition; i++) {
      int byteValue = data[pos] & 0xff;
      if (byteValue < 0x80) {
        pos += 1;
      } else if (byteValue < 0xC2) {
        throw new UncheckedIOException("invalid UTF8", new CharacterCodingException());
      } else if (byteValue < 0xE0) {
        pos += 2;
      } else if (byteValue < 0xF0) {
        pos += 3;
      } else if (byteValue < 0xF8) {
        pos += 4;
      } else {
        throw new UncheckedIOException("invalid UTF8", new CharacterCodingException());
      }
    }
    return pos;
  }
1263135
public void writeBodyFromString(String bodyAsString, Charset charset) {
        message.contentEncoding(charset.name())
                .contentType(Message.TEXT_PLAIN);
        byte[] bodyContent = bodyAsString.getBytes(charset);
        message.body(bodyContent);
    }
949315
public void setBody(CharSequence body) {
        String bodyString;
        if (body != null) {
            bodyString = body.toString();
        } else {
            bodyString = null;
        }
        setBody(bodyString);
    }
366935
public void setRawResponseContent(String rawResponseContent) {
        this.rawResponse = rawResponseContent == null ? null : rawResponseContent.getBytes
                (StringUtils.UTF8);
    }
1254423
public RawResponse charset(Charset charset) {
        return new RawResponse(method, url, statusCode, statusLine, cookies, headers, body, charset, decompress);
    }
986399
public void setMaxHeaderTableSize(long maxHeaderTableSize) throws Http2Exception {
        if (maxHeaderTableSize < MIN_HEADER_TABLE_SIZE || maxHeaderTableSize > MAX_HEADER_TABLE_SIZE) {
            throw connectionError(PROTOCOL_ERROR, "Header Table Size must be >= %d and <= %d but was %d",
                    MIN_HEADER_TABLE_SIZE, MAX_HEADER_TABLE_SIZE, maxHeaderTableSize);
        }
        maxDynamicTableSize = maxHeaderTableSize;
        if (maxDynamicTableSize < encoderMaxDynamicTableSize) {
            // decoder requires less space than encoder
            // encoder MUST signal this change
            maxDynamicTableSizeChangeRequired = true;
            hpackDynamicTable.setCapacity(maxDynamicTableSize);
        }
    }
824903
private void setResponeHeaders(HttpServletResponse response) {

        response.setHeader("Cache-Control", "no-store, no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", System.currentTimeMillis());
        response.setContentType("text/plain; charset=utf-8");
        response.setCharacterEncoding("utf-8");
    }
1009250
public static RequestContext handle(final HttpServletRequest request, final HttpServletResponse response) {
        try {
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
        } catch (final Exception e) {
            LOGGER.log(Level.ERROR, "Sets request context character encoding failed", e);
        }

        final RequestContext ret = new RequestContext();
        ret.setRequest(request);
        ret.setResponse(response);
        Latkes.REQUEST_CONTEXT.set(ret);

        for (final Handler handler : HANDLERS) {
            ret.addHandler(handler);
        }

        ret.handle();
        result(ret);
        Latkes.REQUEST_CONTEXT.set(null);

        return ret;
    }
42460
static String tokenize(PageMetadata<?, ?> pageMetadata) {
        try {
            Gson g = getGsonWithKeyAdapter(pageMetadata.pageRequestParameters);
            return new String(Base64.encodeBase64URLSafe(g.toJson(new PaginationToken
                    (pageMetadata)).getBytes("UTF-8")),
                    Charset.forName("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            //all JVMs should support UTF-8
            throw new RuntimeException(e);
        }
    }
68790
public void setResponse(Map<String, Object> headers) {
        int size = RES_200.length;
        byte[] len = stringToBytes(String.valueOf(0));
        size += CONTENT_LENGTH.length;
        size += len.length;
        size += TextCommandConstants.RETURN.length;
        if (headers != null) {
            for (Map.Entry<String, Object> entry : headers.entrySet()) {
                size += stringToBytes(HEADER_CUSTOM_PREFIX + entry.getKey() + ": ").length;
                size += stringToBytes(entry.getValue().toString()).length;
                size += TextCommandConstants.RETURN.length;
            }
        }
        size += TextCommandConstants.RETURN.length;
        this.response = ByteBuffer.allocate(size);
        response.put(RES_200);
        response.put(CONTENT_LENGTH);
        response.put(len);
        response.put(TextCommandConstants.RETURN);
        if (headers != null) {
            for (Map.Entry<String, Object> entry : headers.entrySet()) {
                response.put(stringToBytes(HEADER_CUSTOM_PREFIX + entry.getKey() + ": "));
                response.put(stringToBytes(entry.getValue().toString()));
                response.put(TextCommandConstants.RETURN);
            }
        }
        response.put(TextCommandConstants.RETURN);
        response.flip();
    }
394632
private static String bytesToBase64(final byte[] body) {
    final String encoded = Base64.getEncoder().encodeToString(body);
    return encoded;
  }
983135
public <T> Message body(T body, Charset charset) {
        messageWriter.writeBody(body, charset);
        return this;
    }