### Question:
TransportFrameUtil { @SuppressWarnings("BetaApi") public static byte[][] toHttp2Headers(Metadata headers) { byte[][] serializedHeaders = InternalMetadata.serialize(headers); if (serializedHeaders == null) { return new byte[][]{}; } int k = 0; for (int i = 0; i < serializedHeaders.length; i += 2) { byte[] key = serializedHeaders[i]; byte[] value = serializedHeaders[i + 1]; if (endsWith(key, binaryHeaderSuffixBytes)) { serializedHeaders[k] = key; serializedHeaders[k + 1] = InternalMetadata.BASE64_ENCODING_OMIT_PADDING.encode(value).getBytes(US_ASCII); k += 2; } else { if (isSpecCompliantAscii(value)) { serializedHeaders[k] = key; serializedHeaders[k + 1] = value; k += 2; } else { String keyString = new String(key, US_ASCII); logger.warning("Metadata key=" + keyString + ", value=" + Arrays.toString(value) + " contains invalid ASCII characters"); } } } if (k == serializedHeaders.length) { return serializedHeaders; } return Arrays.copyOfRange(serializedHeaders, 0, k); } private  TransportFrameUtil(); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 static byte[][] toHttp2Headers(Metadata headers); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 @CheckReturnValue static byte[][] toRawSerializedHeaders(byte[][] http2Headers);  }### Answer:
@Test public void testToHttp2Headers() { Metadata headers = new Metadata(); headers.put(PLAIN_STRING, COMPLIANT_ASCII_STRING); headers.put(BINARY_STRING, NONCOMPLIANT_ASCII_STRING); headers.put(BINARY_STRING_WITHOUT_SUFFIX, NONCOMPLIANT_ASCII_STRING); byte[][] http2Headers = TransportFrameUtil.toHttp2Headers(headers); byte[][] answer = new byte[][] { "plainstring".getBytes(US_ASCII), COMPLIANT_ASCII_STRING.getBytes(US_ASCII), "string-bin".getBytes(US_ASCII), base64Encode(NONCOMPLIANT_ASCII_STRING.getBytes(US_ASCII))}; assertEquals(answer.length, http2Headers.length); for (int i = 0; i < answer.length; i += 2) { assertContains(http2Headers, answer[i], answer[i + 1]); } }