/** * Method for reading sequence of Objects from parser stream. */ @Override public <T> MappingIterator<T> readValues(JsonParser p, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return readValues(p, _typeFactory.constructType(valueTypeRef)); }
/** * Convenience method, equivalent in function to: *<pre> * readerFor(valueType).readValues(p); *</pre> *<p> * Method for reading sequence of Objects from parser stream. * Sequence can be either root-level "unwrapped" sequence (without surrounding * JSON array), or a sequence contained in a JSON Array. * In either case {@link JsonParser} <b>MUST</b> point to the first token of * the first element, OR not point to any token (in which case it is advanced * to the next token). This means, specifically, that for wrapped sequences, * parser MUST NOT point to the surrounding <code>START_ARRAY</code> (one that * contains values to read) but rather to the token following it which is the first * token of the first value to read. *<p> * Note that {@link ObjectReader} has more complete set of variants. */ @Override public <T> MappingIterator<T> readValues(JsonParser p, ResolvedType valueType) throws IOException, JsonProcessingException { return readValues(p, (JavaType) valueType); }
/** * Convenience method, equivalent in function to: *<pre> * readerFor(valueType).readValues(p); *</pre> *<p> * Type-safe overload of {@link #readValues(JsonParser, ResolvedType)}. */ @Override public <T> MappingIterator<T> readValues(JsonParser p, Class<T> valueType) throws IOException, JsonProcessingException { return readValues(p, _typeFactory.constructType(valueType)); }
public static MappingIterator<Map<String, Object>> readValues( final InputStream stream, final TypeReference<Map<String, Object>> typeReference) throws IOException { final JsonParser parser = OBJECT_MAPPER.getFactory().createParser(stream); return OBJECT_MAPPER.readValues(parser, typeReference); }
public static MappingIterator<JsonNode> readValues( final InputStream stream) throws IOException { final JsonParser parser = OBJECT_MAPPER.getFactory().createParser(stream); return OBJECT_MAPPER.readValues(parser, JsonNode.class); }
private MappingIterator<Entry<KeyType>> read(final File file, final Class<KeyType> keyClazz) { try { return spillMapper.readValues( spillMapper.getFactory().createParser(new LZ4BlockInputStream(new FileInputStream(file))), spillMapper.getTypeFactory().constructParametricType(Entry.class, keyClazz) ); } catch (IOException e) { throw Throwables.propagate(e); } }
private void init() throws IOException { _parser = _factory.createParser(RecordReaderUtils.getFileReader(_dataFile)); try { _iterator = JsonUtils.DEFAULT_MAPPER.readValues(_parser, Map.class); } catch (Exception e) { _parser.close(); throw e; } }
ProgressStream(final InputStream stream) throws IOException { this.stream = stream; final JsonParser parser = objectMapper().getFactory().createParser(stream); iterator = objectMapper().readValues(parser, ProgressMessage.class); }
/** * Returns a dictionary of string keys added to this grouper. Note that the dictionary of keySerde is spilled on * local storage whenever the inner grouper is spilled. If there are spilled dictionaries, this method loads them * from disk and returns a merged dictionary. * * @return a dictionary which is a list of unique strings */ public List<String> mergeAndGetDictionary() { final Set<String> mergedDictionary = new HashSet<>(); mergedDictionary.addAll(keySerde.getDictionary()); for (File dictFile : dictionaryFiles) { try ( final MappingIterator<String> dictIterator = spillMapper.readValues( spillMapper.getFactory().createParser(new LZ4BlockInputStream(new FileInputStream(dictFile))), spillMapper.getTypeFactory().constructType(String.class) ) ) { while (dictIterator.hasNext()) { mergedDictionary.add(dictIterator.next()); } } catch (IOException e) { throw new RuntimeException(e); } } return new ArrayList<>(mergedDictionary); }
private List<String> readFromCache(final Cache.NamedKey key) { final byte[] bytes = cache.get(key); if (bytes == null) { return null; } try ( final MappingIterator<Map<String, String>> iterator = objectMapper.readValues( objectMapper.getFactory().createParser(bytes), JacksonUtils.TYPE_REFERENCE_MAP_STRING_STRING ) ) { final List<Map<String, String>> retVal = new ArrayList<>(); Iterators.addAll(retVal, iterator); // Undo map-wrapping that was done in wrapAndReturn. return retVal.stream().map(m -> m.get("s")).collect(Collectors.toList()); } catch (IOException e) { throw new RuntimeException(e); } } }
private Sequence<T> deserializeResults(final byte[] cachedResult, CacheStrategy strategy, String resultSetId) { if (cachedResult == null) { log.error("Cached result set is null"); } final Function<Object, T> pullFromCacheFunction = strategy.pullFromCache(true); final TypeReference<Object> cacheObjectClazz = strategy.getCacheObjectClazz(); //Skip the resultsetID and its length bytes Sequence<T> cachedSequence = Sequences.simple(() -> { try { int resultOffset = Integer.BYTES + resultSetId.length(); return objectMapper.readValues( objectMapper.getFactory().createParser( cachedResult, resultOffset, cachedResult.length - resultOffset ), cacheObjectClazz ); } catch (IOException e) { throw new RE(e, "Failed to retrieve results from cache for query ID [%s]", query.getId()); } }); return Sequences.map(cachedSequence, pullFromCacheFunction); }
public static Stream<Object> loadJson(String url, Map<String,Object> headers, String payload, String path, boolean failOnError) { try { url = Util.getLoadUrlByConfigFile("json",url, "url").orElse(url); FileUtils.checkReadAllowed(url); url = FileUtils.changeFileUrlIfImportDirectoryConstrained(url); InputStream input = Util.openInputStream(url, headers, payload); JsonParser parser = OBJECT_MAPPER.getFactory().createParser(input); MappingIterator<Object> it = OBJECT_MAPPER.readValues(parser, Object.class); Stream<Object> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, 0), false); return (path==null||path.isEmpty()) ? stream : stream.map((value) -> JsonPath.parse(value,JSON_PATH_CONFIG).read(path)); } catch (IOException e) { String u = Util.cleanUrl(url); if(!failOnError) return Stream.of(); else throw new RuntimeException("Can't read url or key " + u + " as json: "+e.getMessage()); } }
/** * Method for reading sequence of Objects from parser stream. */ @Override public <T> MappingIterator<T> readValues(JsonParser p, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return readValues(p, _typeFactory.constructType(valueTypeRef)); }
/** * Method for reading sequence of Objects from parser stream. */ @Override public <T> MappingIterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return readValues(jp, _typeFactory.constructType(valueTypeRef)); }
/** * Method for reading sequence of Objects from parser stream. */ @Override public <T> MappingIterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return readValues(jp, _typeFactory.constructType(valueTypeRef)); }
@Override public <T> MappingIterator<T> readValues(JsonParser p, Class<T> valueType) { try { return super.readValues(p, valueType); } catch (IOException e) { throw new UncheckedIOException(e); } }
/** * Method for reading sequence of Objects from parser stream. */ @Override public <T> MappingIterator<T> readValues(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return readValues(jp, _typeFactory.constructType(valueTypeRef)); }
/** * Type-safe overloaded method, basically alias for {@link #readValues(JsonParser, ResolvedType)}. */ @Override public <T> MappingIterator<T> readValues(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException { return readValues(jp, _typeFactory.constructType(valueType)); }
/** * Type-safe overloaded method, basically alias for {@link #readValues(JsonParser, ResolvedType)}. */ @Override public <T> MappingIterator<T> readValues(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException { return readValues(jp, _typeFactory.constructType(valueType)); }
private MappingIterator<Entry<KeyType>> read(final File file, final Class<KeyType> keyClazz) { try { return spillMapper.readValues( spillMapper.getFactory().createParser(new LZ4BlockInputStream(new FileInputStream(file))), spillMapper.getTypeFactory().constructParametricType(Entry.class, keyClazz) ); } catch (IOException e) { throw Throwables.propagate(e); } }