support yaml detection on char sequence
This commit is contained in:
parent
6468c15446
commit
6f1932ab67
|
@ -115,6 +115,21 @@ public class XContentFactory {
|
||||||
*/
|
*/
|
||||||
public static XContentType xContentType(CharSequence content) {
|
public static XContentType xContentType(CharSequence content) {
|
||||||
int length = content.length() < GUESS_HEADER_LENGTH ? content.length() : GUESS_HEADER_LENGTH;
|
int length = content.length() < GUESS_HEADER_LENGTH ? content.length() : GUESS_HEADER_LENGTH;
|
||||||
|
if (length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
char first = content.charAt(0);
|
||||||
|
if (first == '{') {
|
||||||
|
return XContentType.JSON;
|
||||||
|
}
|
||||||
|
// Should we throw a failure here? Smile idea is to use it in bytes....
|
||||||
|
if (length > 2 && first == SmileConstants.HEADER_BYTE_1 && content.charAt(1) == SmileConstants.HEADER_BYTE_2 && content.charAt(2) == SmileConstants.HEADER_BYTE_3) {
|
||||||
|
return XContentType.SMILE;
|
||||||
|
}
|
||||||
|
if (length > 2 && first == '-' && content.charAt(1) == '-' && content.charAt(2) == '-') {
|
||||||
|
return XContentType.YAML;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
char c = content.charAt(i);
|
char c = content.charAt(i);
|
||||||
if (c == '{') {
|
if (c == '{') {
|
||||||
|
|
Loading…
Reference in New Issue