if(parser != null) { try { parser.close(); } catch (IOException e) {
if(parser != null) { try { parser.close(); } catch (IOException e) {
private static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException { BytesReference retVal; XContentParser parser = null; try { parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, reader); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); retVal = BytesReference.bytes(builder); } finally { if (parser != null) { parser.close(); } } //validate Settings.builder().loadFromStream("dummy.json", new ByteArrayInputStream(BytesReference.toBytes(retVal)), true).build(); return retVal; }
public static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException { BytesReference retVal; XContentParser parser = null; try { parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, reader); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); retVal = BytesReference.bytes(builder); } finally { if (parser != null) { parser.close(); } } //validate Settings.builder().loadFromStream("dummy.json", new ByteArrayInputStream(BytesReference.toBytes(retVal)), true).build(); return retVal; }
public static BytesReference readYamlContentFromString(final String yaml) { XContentParser parser = null; try { parser = XContentFactory.xContent(XContentType.YAML).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, new StringReader(yaml)); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); return BytesReference.bytes(builder); } catch (Exception e) { throw new RuntimeException(e); } finally { if (parser != null) { try { parser.close(); } catch (IOException e) { //ignore } } } } }
public static BytesReference readYamlContent(final String file) { XContentParser parser = null; try { parser = XContentFactory.xContent(XContentType.YAML).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, new StringReader(loadFile(file))); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); return BytesReference.bytes(builder); } catch (Exception e) { throw new RuntimeException(e); } finally { if (parser != null) { try { parser.close(); } catch (IOException e) { //ignore } } } }
} finally { if (parser != null) { parser.close();
public FacetCollector createInternalCollector() throws IOException { XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(internalFacetConfig); try { return internalProcessor.parse("facet", parser, searchContext); } finally { parser.close(); } }
public XContentBuilder serialize(Event event) { XContentBuilder builder = null; try { XContentParser parser = XContentFactory .xContent(XContentType.JSON) .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, new String(event.getBody(), Charsets.UTF_8)); builder = jsonBuilder().copyCurrentStructure(parser); parser.close(); } catch (IOException e) { logger.error("Error in Converting the body to json field " + e.getMessage(), e); } return builder; }
private void validateAliasFilter(XContentParser parser, IndexQueryParserService indexQueryParserService) throws IOException { QueryParseContext context = indexQueryParserService.getParseContext(); try { context.reset(parser); context.parseInnerFilter(); } finally { context.reset(null); parser.close(); } } }
private Map<String, Object> parse(String source) { Map<String, Object> map = null; XContentParser parser = null; try { parser = XContentFactory.xContent(source).createParser(source); map = parser.map(); } catch (Exception e) { logger.error("unable to parse: {}", source); } finally { if (parser != null) { parser.close(); } } return map; }
public ParsedQuery parse(QueryParseContext context, BytesReference source) { XContentParser parser = null; try { parser = XContentFactory.xContent(source).createParser(source); return innerParse(context, parser); } catch (QueryParsingException e) { throw e; } catch (Exception e) { throw new QueryParsingException(context, "Failed to parse", e); } finally { if (parser != null) { parser.close(); } } }
/** * Read JSON file from classpath into Map of Map structure. * * @param filePath path inside jar/classpath pointing to JSON file to read * @return parsed JSON file * @throws SettingsException */ public static Map<String, Object> loadJSONFromJarPackagedFile(String filePath) throws SettingsException { XContentParser parser = null; try { parser = XContentFactory.xContent(XContentType.JSON).createParser(Utils.class.getResourceAsStream(filePath)); Map<String, Object> ret = parser.mapAndClose(); if (logger.isDebugEnabled()) logger.debug("jar packaged JSON file {} content is: {}", filePath, ret); return ret; } catch (IOException e) { throw new SettingsException(e.getMessage(), e); } finally { if (parser != null) parser.close(); } }
public ParsedQuery parse(byte[] source, int offset, int length) { XContentParser parser = null; try { parser = XContentFactory.xContent(source, offset, length).createParser(source, offset, length); return parse(cache.get(), parser); } catch (QueryParsingException e) { throw e; } catch (Exception e) { throw new QueryParsingException(getParseContext(), "Failed to parse", e); } finally { if (parser != null) { parser.close(); } } }
public ParsedQuery parse(String source) throws QueryParsingException { XContentParser parser = null; try { parser = XContentFactory.xContent(source).createParser(source); return innerParse(cache.get(), parser); } catch (QueryParsingException e) { throw e; } catch (Exception e) { throw new QueryParsingException(getParseContext(), "Failed to parse [" + source + "]", e); } finally { if (parser != null) { parser.close(); } } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { BytesReference source = hit.sourceRef(); XContentType contentType = XContentFactory.xContentType(source); XContentParser parser = XContentFactory.xContent(contentType).createParser(source); try { parser.nextToken(); builder.field(Fields._SOURCE); builder.copyCurrentStructure(parser); } finally { parser.close(); } return builder; } }
public ParsedQuery parse(QueryBuilder queryBuilder) { XContentParser parser = null; try { BytesReference bytes = queryBuilder.buildAsBytes(); parser = XContentFactory.xContent(bytes).createParser(bytes); return parse(cache.get(), parser); } catch (QueryParsingException e) { throw e; } catch (Exception e) { throw new QueryParsingException(getParseContext(), "Failed to parse", e); } finally { if (parser != null) { parser.close(); } } }
private static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException { BytesReference retVal; XContentParser parser = null; try { parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, reader); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); retVal = BytesReference.bytes(builder); } finally { if (parser != null) { parser.close(); } } //validate Settings.builder().loadFromStream("dummy.json", new ByteArrayInputStream(BytesReference.toBytes(retVal)), true).build(); return retVal; }
public static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException { BytesReference retVal; XContentParser parser = null; try { parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, SearchGuardDeprecationHandler.INSTANCE, reader); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); retVal = BytesReference.bytes(builder); } finally { if (parser != null) { parser.close(); } } //validate Settings.builder().loadFromStream("dummy.json", new ByteArrayInputStream(BytesReference.toBytes(retVal)), true).build(); return retVal; }
protected void copyRawValue(BytesReference content, XContent xContent) throws IOException { XContentParser parser = null; try { if (content.hasArray()) { parser = xContent.createParser(content.array(), content.arrayOffset(), content.length()); } else { parser = xContent.createParser(content.streamInput()); } copyCurrentStructure(parser); } finally { if (parser != null) { parser.close(); } } }