Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright (c) 2017 WANG Lingsong
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jsfr.json;
import org.jsfr.json.path.JsonPath;
import org.jsfr.json.provider.JsonProvider;
import java.io.Reader;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import static org.jsfr.json.compiler.JsonPathCompiler.compile;
/**
* JsonSurfer traverses the whole json DOM tree, compare the path of each node with registered JsonPath
* and return the matched value immediately. JsonSurfer is fully streaming which means that it doesn't construct the DOM tree in memory.
*/
public class JsonSurfer {
private static final String KEY_HAS_MATCH = "_JSURFER_INTERNAL_HAS_MATCH_";
private static final String KEY_MATCH = "_JSURFER_INTERNAL_MATCH_";
private JsonProvider jsonProvider;
private JsonParserAdapter jsonParserAdapter;
private ErrorHandlingStrategy errorHandlingStrategy;
/**
* @param jsonParserAdapter jsonParserAdapter
* @param jsonProvider jsonProvider
*/
public JsonSurfer(JsonParserAdapter jsonParserAdapter, JsonProvider jsonProvider) {
this(jsonParserAdapter, jsonProvider, new DefaultErrorHandlingStrategy());
}
/**
* @param jsonParserAdapter jsonParserAdapter
* @param jsonProvider jsonProvider
* @param errorHandlingStrategy errorHandlingStrategy
*/
public JsonSurfer(JsonParserAdapter jsonParserAdapter, JsonProvider jsonProvider, ErrorHandlingStrategy errorHandlingStrategy) {
this.jsonProvider = jsonProvider;
this.jsonParserAdapter = jsonParserAdapter;
this.errorHandlingStrategy = errorHandlingStrategy;
}
/**
* Create SurfingConfiguration builder associated with this surfer
*
* @return SurfingConfiguration builder
*/
public SurfingConfiguration.Builder configBuilder() {
return SurfingConfiguration.builder().withSurfer(this);
}
/**
* Create a streaming iterator which can pull matched value one by one according to provided JsonPath. Internally, only one matched value stored in memory
*
* @param reader Json source
* @param jsonPath JsonPath
* @return Streaming iterator
*/
public Iterator