本文整理了Java中org.apache.jena.atlas.json.JSON
类的一些代码示例,展示了JSON
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON
类的具体详情如下:
包路径:org.apache.jena.atlas.json.JSON
类名称:JSON
[英]A class that is the front door to the JSON subsystem
[中]一个类,它是JSON子系统的前门
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-base
/** Return a {@link JsonObject} parsed out of bytes. */
public static JsonObject fromBytes(byte[] bytes) {
return JSON.parse(new ByteArrayInputStream(bytes));
}
代码示例来源:origin: apache/jena
/** Write out a JSON value - pass a JSON Object to get legal exchangeable JSON */
public static void write(JsonValue jValue) {
write(IndentedWriter.stdout, jValue) ;
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-cmds
public static DeltaServerConfig read(String file) {
JsonObject obj = JSON.read(file);
return create(obj);
}
代码示例来源:origin: apache/jena
@Test public void jsonAPI_03() {
JsonValue jv1 = JSON.parseAny("2") ;
JsonValue jv2 = JSON.copy(jv1);
assertSame(jv1, jv2);
}
}
代码示例来源:origin: apache/jena
public static void main(String... args)
{
if ( args.length == 0 )
args = new String[] {"-"} ;
try {
for ( String fn : args )
{
JsonValue json =null ;
try {
json = JSON.readAny(fn) ;
} catch (JsonParseException ex)
{
String name = fn.equals("-") ? "<stdin>" : fn ;
System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ;
continue ;
}
JSON.write(IndentedWriter.stdout, json) ;
IndentedWriter.stdout.ensureStartOfLine() ;
}
} finally { IndentedWriter.stdout.flush() ; }
}
代码示例来源:origin: apache/jena
@Test public void jsonAPI_02() {
JsonObject obj = JSON.parse("{ key1: 'str1' , key2: [ 1 , 2 ] }") ;
JsonObject obj2 = (JsonObject)JSON.copy(obj);
assertNotSame(obj, obj2);
assertEquals(obj, obj2);
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-server-local
LOG.info(JSON.toStringFlat(obj));
try (OutputStream out = Files.newOutputStream(sourcePath.resolve(FileNames.DS_CONFIG))) {
JSON.write(out, obj);
} catch (IOException ex) { throw IOX.exception(ex); }
return sourcePath;
代码示例来源:origin: apache/jena
/** Read any JSON value, not just an object, from a file */
public static JsonValue readAny(String filename) {
try {
try (InputStream in = IO.openFileEx(filename)) {
return JSON.parseAny(in) ;
}
}
catch (FileNotFoundException ex) {
throw new RuntimeException("File not found: " + filename, ex) ;
}
catch (IOException ex) {
IO.exception("IOException: " + filename, ex) ;
return null ;
}
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-client
private JsonValue rpcToValue(String opName, JsonObject arg) {
JsonObject argx = ( arg == null ) ? emptyObject : arg;
// [NET] Network point
return retry(()->DRPC.rpc(remoteServer + DeltaConst.EP_RPC, opName, argx),
()->true,
()->format("Retry : %s",opName),
()->format("Failed : %s %s",opName,JSON.toStringFlat(argx))
);
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-client
throw new DeltaException() ;
String argStr = JSON.toString(object) ;
try (TypedInputStream x =
HttpOp.execHttpPostStream(url, WebContent.contentTypeJSON, argStr, WebContent.contentTypeJSON)
try {
String s = IO.readWholeFileAsUTF8(x) ;
return JSON.parseAny(s) ;
} catch (IOException ex) { throw IOX.exception(ex); }
return JSON.parseAny(x) ;
} catch (HttpException ex) {
if ( HttpSC.BAD_REQUEST_400 == ex.getResponseCode() ) {
代码示例来源:origin: apache/jena
/** Parse a complete JSON object */
public static JsonObject parse(String string) {
return _parse(new StringReader(string)) ;
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
public static void main(String... args)
{
if ( args.length == 0 )
args = new String[] {"-"} ;
try {
for ( String fn : args )
{
JsonValue json =null ;
try {
json = JSON.readAny(fn) ;
} catch (JsonParseException ex)
{
String name = fn.equals("-") ? "<stdin>" : fn ;
System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ;
continue ;
}
JSON.write(IndentedWriter.stdout, json) ;
IndentedWriter.stdout.ensureStartOfLine() ;
}
} finally { IndentedWriter.stdout.flush() ; }
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
/** Read any JSON value, not just an object, from a file */
public static JsonValue readAny(String filename)
{
try
{
InputStream in = IO.openFileEx(filename) ;
try { return JSON.parseAny(in) ; } finally { in.close() ; }
}
catch (FileNotFoundException ex)
{
throw new RuntimeException("File not found: "+filename, ex) ;
}
catch (IOException ex)
{
IO.exception("IOException: "+filename, ex);
return null ;
}
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-base
public static Version create(JsonValue version) {
Objects.requireNonNull(version, "version");
if ( version.isNumber() ) {
long ver = JSONX.getLong(version, -2);
if ( ver < -1 )
throw new DeltaException("Bad version number: '"+JSON.toStringFlat(version)+"'");
return create(ver);
}
if ( version.isString() ) {
try {
String s = version.getAsString().value();
long ver = Long.parseLong(s);
return create(ver);
} catch (NumberFormatException ex) {
throw new DeltaException("Bad format for version: '"+JSON.toStringFlat(version)+"'");
}
}
throw new DeltaException("Unrecognized JSON version: '"+JSON.toStringFlat(version)+"'");
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
/** Parse a complete JSON object */
public static JsonObject parse(String string)
{
return _parse(new StringReader(string)) ;
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-client
/** Set version and datasource id from a string which is JOSN */
private static void setStateFromString(DataState state, String string) {
JsonObject obj = JSON.parse(string);
setFromJsonObject(state, obj);
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
/** Write out a JSON value to - pass a JSON Object to get legal exchangeable JSON */
public static void write(JsonValue jValue)
{
write(IndentedWriter.stdout, jValue) ;
}
}
代码示例来源:origin: org.apache.jena/jena-cmds
public static void main(String... args)
{
if ( args.length == 0 )
args = new String[] {"-"} ;
try {
for ( String fn : args )
{
JsonValue json =null ;
try {
json = JSON.readAny(fn) ;
} catch (JsonParseException ex)
{
String name = fn.equals("-") ? "<stdin>" : fn ;
System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ;
continue ;
}
JSON.write(IndentedWriter.stdout, json) ;
IndentedWriter.stdout.ensureStartOfLine() ;
}
} finally { IndentedWriter.stdout.flush() ; }
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-server-local
/**
* Look for {@link DataSource DataSources} in a disk area given by {@code location}.
* <p>
* Scan the given area for directories (must have a config file), check they are enabled,
* and deal with {@code log_type}.
*/
public static List<DataSourceDescription> scanForLogs(Path location, PatchStore ps) {
// PatchStore's that rely on the scan of local directories and checking the "log_type" field.
Pair<List<Path>, List<Path>> pair = scanDirectory(location);
List<Path> dataSourcePaths = pair.getLeft();
List<Path> disabledDataSources = pair.getRight();
//dataSourcePaths.forEach(p->LOG.info("Data source paths: "+p));
disabledDataSources.forEach(p->LOG.info("Data source: "+p+" : Disabled"));
List<DataSourceDescription> descriptions = ListUtils.toList
(dataSourcePaths.stream()
.map(p->{
// Extract name from disk name.
String dsName = p.getFileName().toString();
// read config file.
JsonObject sourceObj = JSON.read(p.resolve(FileNames.DS_CONFIG).toString());
DataSourceDescription dsd = DataSourceDescription.fromJson(sourceObj);
if ( ! Objects.equals(dsName, dsd.getName()) )
throw new DeltaConfigException("Names do not match: directory="+dsName+", dsd="+dsd);
return dsd;
})
.filter(Objects::nonNull)
);
return descriptions;
}
代码示例来源:origin: apache/jena
/** Read-compare */
public static void read(String string, JsonValue expected)
{
JsonValue v = JSON.parseAny(string) ;
assertEquals(expected, v) ;
}
内容来源于网络,如有侵权,请联系作者删除!