Java Code Examples for org.apache.jena.atlas.json.JSON#write()

The following examples show how to use org.apache.jena.atlas.json.JSON#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: S_JSON.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
public static void json(HttpServletRequest req, HttpServletResponse resp, JsonValue responseContent) {
    try { 
        resp.setHeader(HttpNames.hCacheControl, "no-cache");
        resp.setHeader(HttpNames.hContentType,  WebContent.contentTypeJSON);
        resp.setStatus(HttpSC.OK_200);
        try(ServletOutputStream out = resp.getOutputStream(); IndentedWriter b = new IndentedWriter(out); ) {
            b.setFlatMode(true);
            JSON.write(b, responseContent);
            b.ensureStartOfLine();
            b.flush();
            out.write('\n');
        }
    } catch (IOException ex) {
        LOG.warn("json: IOException", ex);
        try { 
            resp.sendError(HttpSC.INTERNAL_SERVER_ERROR_500, "Internal server error");
        } catch (IOException ex2) {}
    }
}
 
Example 2
Source File: TestDeltaServerConfig.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private void roundTrip(DeltaServerConfig c) {
    JsonObject obj = c.asJSON();
    DeltaServerConfig c2 = DeltaServerConfig.create(obj);
    if ( ! c.equals(c2) ) {
        System.out.println("c  : "+c.zkMode);
        System.out.println("c2 : "+c2.zkMode);
        JSON.write(obj);
        JSON.write(c2.asJSON());
    }
    assertEquals(c, c2);
}
 
Example 3
Source File: FileArea.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
/**
 * Set up a disk file area for the data source
 * @param root
 * @param patchStore
 * @param dsd
 */
/*package*/ public static Path setupDataSourceByFile(Path root, PatchStore patchStore, DataSourceDescription dsd) {
    // Disk file setup

    Path sourcePath = root.resolve(dsd.getName());

    if ( patchStore.logExists(dsd.getId()) )
        throw new DeltaBadRequestException("DataSource area already exists and is active at: "+sourcePath);

    // Checking.
    // The area can exist, but it must not be formatted for a DataSource
    //        if ( sourceArea.exists() )
    //            throw new DeltaException("Area already exists");

    if ( FileArea.isMinimalDataSource(sourcePath) )
        throw new DeltaBadRequestException("DataSource area already exists at: "+sourcePath);
    if ( ! FileArea.isEnabled(sourcePath) )
        throw new DeltaBadRequestException("DataSource area disabled: "+sourcePath);

    try {
        Files.createDirectories(sourcePath);
    }
    catch (IOException e) {
        throw new DeltaBadRequestException("Failed to create DataSource area: "+sourcePath);
    }

    // Create source.cfg.
    JsonObject obj = dsd.asJson();
    obj.put(F_LOG_TYPE, patchStore.getProvider().getShortName());
    try (OutputStream out = Files.newOutputStream(sourcePath.resolve(FileNames.DS_CONFIG))) {
        JSON.write(out, obj);
    } catch (IOException ex)  { throw IOX.exception(ex); }
    return sourcePath;
}
 
Example 4
Source File: DeltaBackupServer.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private void writeConf(BackupConfig cfg) {
    JsonObject obj = JSONX.buildObject(b->{
        b   .pair(jPort, cfg.port)
            .key(jLogs).startArray();
        cfg.logs.forEach(a->
            b.startObject().pair(jName, a.name).pair(jDir, a.dir).pair(jFile, a.file).finishObject()
            );
        b.finishArray();
    });
    JSON.write(System.out, obj);
}
 
Example 5
Source File: DeltaServerConfig.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
public static void writeJSON(DeltaServerConfig config, OutputStream out) {
    JsonObject obj = config.asJSON();
    JSON.write(out, obj);
}
 
Example 6
Source File: PatchStoreZk.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
private static byte[] jsonBytes(JsonValue json) {
    ByteArrayOutputStream out = new ByteArrayOutputStream(8*1024);
    JSON.write(out, json);
    return out.toByteArray();
}