/** * Returns a {@link ContentType} from a given {@link XContentType}. * * @param xContentType the {@link XContentType} * @return the {@link ContentType} */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); }
public String mediaType() { return mediaTypeWithoutParameters(); }
public String mediaType() { return mediaTypeWithoutParameters(); }
public String mediaType() { return mediaTypeWithoutParameters(); }
private static boolean isSameMediaTypeOrFormatAs(String stringType, XContentType type) { return type.mediaTypeWithoutParameters().equalsIgnoreCase(stringType) || stringType.toLowerCase(Locale.ROOT).startsWith(type.mediaTypeWithoutParameters().toLowerCase(Locale.ROOT) + ";") || type.shortName().equalsIgnoreCase(stringType); }
private static boolean isSameMediaTypeOrFormatAs(String stringType, XContentType type) { return type.mediaTypeWithoutParameters().equalsIgnoreCase(stringType) || stringType.toLowerCase(Locale.ROOT).startsWith(type.mediaTypeWithoutParameters().toLowerCase(Locale.ROOT) + ";") || type.shortName().equalsIgnoreCase(stringType); }
private static boolean isSameMediaTypeOrFormatAs(String stringType, XContentType type) { return type.mediaTypeWithoutParameters().equalsIgnoreCase(stringType) || stringType.toLowerCase(Locale.ROOT).startsWith(type.mediaTypeWithoutParameters().toLowerCase(Locale.ROOT) + ";") || type.shortName().equalsIgnoreCase(stringType); }
/** * Returns a {@link ContentType} from a given {@link XContentType}. * * @param xContentType the {@link XContentType} * @return the {@link ContentType} */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); }
/** * Returns a {@link ContentType} from a given {@link XContentType}. * * @param xContentType the {@link XContentType} * @return the {@link ContentType} */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); }
/** * Attempts to match the given media type with the known {@link XContentType} values. This match is done in a case-insensitive manner. * The provided media type should not include any parameters. This method is suitable for parsing part of the {@code Content-Type} * HTTP header. This method will return {@code null} if no match is found */ public static XContentType fromMediaType(String mediaType) { final String lowercaseMediaType = Objects.requireNonNull(mediaType, "mediaType cannot be null").toLowerCase(Locale.ROOT); for (XContentType type : values()) { if (type.mediaTypeWithoutParameters().equals(lowercaseMediaType)) { return type; } } return null; }
/** * Returns a {@link ContentType} from a given {@link XContentType}. * * @param xContentType the {@link XContentType} * @return the {@link ContentType} */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); }
/** * Attempts to match the given media type with the known {@link XContentType} values. This match is done in a case-insensitive manner. * The provided media type should not include any parameters. This method is suitable for parsing part of the {@code Content-Type} * HTTP header. This method will return {@code null} if no match is found */ public static XContentType fromMediaType(String mediaType) { final String lowercaseMediaType = Objects.requireNonNull(mediaType, "mediaType cannot be null").toLowerCase(Locale.ROOT); for (XContentType type : values()) { if (type.mediaTypeWithoutParameters().equals(lowercaseMediaType)) { return type; } } return null; }
/** * Attempts to match the given media type with the known {@link XContentType} values. This match is done in a case-insensitive manner. * The provided media type should not include any parameters. This method is suitable for parsing part of the {@code Content-Type} * HTTP header. This method will return {@code null} if no match is found */ public static XContentType fromMediaType(String mediaType) { final String lowercaseMediaType = Objects.requireNonNull(mediaType, "mediaType cannot be null").toLowerCase(Locale.ROOT); for (XContentType type : values()) { if (type.mediaTypeWithoutParameters().equals(lowercaseMediaType)) { return type; } } return null; }
private HttpEntity createEntity(List<Map<String, Object>> bodies, Map<String, String> headers) throws IOException { if (bodies.isEmpty()) { return null; } if (bodies.size() == 1) { XContentType xContentType = getContentType(headers, XContentType.values()); BytesRef bytesRef = bodyAsBytesRef(bodies.get(0), xContentType); return new ByteArrayEntity(bytesRef.bytes, bytesRef.offset, bytesRef.length, ContentType.create(xContentType.mediaTypeWithoutParameters(), StandardCharsets.UTF_8)); } else { XContentType xContentType = getContentType(headers, STREAMING_CONTENT_TYPES); List<BytesRef> bytesRefList = new ArrayList<>(bodies.size()); int totalBytesLength = 0; for (Map<String, Object> body : bodies) { BytesRef bytesRef = bodyAsBytesRef(body, xContentType); bytesRefList.add(bytesRef); totalBytesLength += bytesRef.length - bytesRef.offset + 1; } byte[] bytes = new byte[totalBytesLength]; int position = 0; for (BytesRef bytesRef : bytesRefList) { for (int i = bytesRef.offset; i < bytesRef.length; i++) { bytes[position++] = bytesRef.bytes[i]; } bytes[position++] = xContentType.xContent().streamSeparator(); } return new ByteArrayEntity(bytes, ContentType.create(xContentType.mediaTypeWithoutParameters(), StandardCharsets.UTF_8)); } }
@Override public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(index); out.writeOptionalBytesReference(document); out.writeOptionalString(xContentType != null ? xContentType.mediaTypeWithoutParameters(): null); out.writeOptionalNamedWriteable(query); }