当前位置: 首页>>代码示例>>Java>>正文


Java JsonWriter.setIndent方法代码示例

本文整理汇总了Java中com.google.gson.stream.JsonWriter.setIndent方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter.setIndent方法的具体用法?Java JsonWriter.setIndent怎么用?Java JsonWriter.setIndent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.stream.JsonWriter的用法示例。


在下文中一共展示了JsonWriter.setIndent方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void run(OutputStream optionalOutput, boolean extractUnpublished) throws IOException {
  // fill sources with extra input:
  JsonDataSources sources = new ExtraInput().fetchAllDataSources();
  // fill sources with vendor API input:
  VendorDynamicInput vendorInput = new VendorDynamicInput();
  vendorInput.setExtractUnpublished(extractUnpublished);
  sources.putAll(vendorInput.fetchAllDataSources());
  // extract session data from inputs:
  JsonObject newData = new DataExtractor(false).extractFromDataSources(sources);

  // send data to the outputstream
  Writer writer = Channels.newWriter(Channels.newChannel(optionalOutput), "UTF-8");
  JsonWriter optionalOutputWriter = new JsonWriter(writer);
  optionalOutputWriter.setIndent("  ");
  new Gson().toJson(newData, optionalOutputWriter);
  optionalOutputWriter.flush();
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:18,代码来源:APIExtractor.java

示例2: writeModList

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
private boolean writeModList(File file, ForgeModList modList)
{
    try
    {
        log.info("Writing mod list to '{}'...", file.getAbsolutePath());
        File parent = file.getParentFile();
        if (!parent.exists() && !parent.mkdirs())
        {
            log.error("Failed to create required directories for file '{}', aborting!", file.getAbsolutePath());
            return false;
        }
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        JsonWriter jsonWriter = new JsonWriter(writer);
        jsonWriter.setIndent("  ");
        CurseSync.GSON.toJson(modList, ForgeModList.class, jsonWriter);
        writer.close();
    }
    catch (IOException e)
    {
        log.error(new FormattedMessageFactory().newMessage("Failed to write Mod List JSON '{}', aborting!", file.getAbsolutePath()), e);
        return false;
    }
    return true;
}
 
开发者ID:PaleoCrafter,项目名称:CurseSync,代码行数:25,代码来源:Installer.java

示例3: saveInstallation

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
protected InstallStep.Result saveInstallation()
{
    Installation newInstallation = new Installation(config.projectId(), config.projectNameSlug(), config.gameVersion, config.server, installation.modRepository, installation.forgeVersion, config.projectVersion, manifest.mods, installation.overrides);
    File installationFile = config.installationFile();
    try
    {
        log.info("Saving installation data to '{}'...", installationFile.getAbsolutePath());
        File parent = installationFile.getParentFile();
        if (!parent.exists() && !parent.mkdirs())
        {
            log.error("Failed to create required directories for installation file, aborting!");
            return FAILURE;
        }
        BufferedWriter writer = new BufferedWriter(new FileWriter(installationFile));
        JsonWriter jsonWriter = new JsonWriter(writer);
        jsonWriter.setIndent("  ");
        CurseSync.GSON.toJson(newInstallation, Installation.class, jsonWriter);
        writer.close();
    }
    catch (IOException e)
    {
        log.error("Failed to write installation file, aborting!", e);
        return FAILURE;
    }
    return SUCCESS;
}
 
开发者ID:PaleoCrafter,项目名称:CurseSync,代码行数:27,代码来源:Installer.java

示例4: export

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public static void export(Generator generator) {
  if (generator == null || generator.database == null) {
    return;
  }

  try (Connection connection = generator.database.getConnection()) {
    File outDirectory = Exporter.getOutputFolder("statistics", null);
    String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
    Path outFilePath = outDirectory.toPath().resolve("statistics-" + timeStamp + ".json");

    JsonWriter writer = new JsonWriter(new FileWriter(outFilePath.toFile()));
    writer.setIndent("  ");
    writer.beginObject(); // top-level

    reportParameters(writer);
    processOutcomes(connection, writer);
    processAccess(connection, writer);
    processCosts(connection, writer);

    writer.endObject(); // top-level
    writer.close();

  } catch (IOException | SQLException e) {
    e.printStackTrace();
    throw new RuntimeException("error exporting statistics");
  }
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:28,代码来源:ReportExporter.java

示例5: newJsonWriter

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
private JsonWriter newJsonWriter(Writer writer) throws IOException {
    if (this.generateNonExecutableJson) {
        writer.write(JSON_NON_EXECUTABLE_PREFIX);
    }
    JsonWriter jsonWriter = new JsonWriter(writer);
    if (this.prettyPrinting) {
        jsonWriter.setIndent("  ");
    }
    jsonWriter.setSerializeNulls(this.serializeNulls);
    return jsonWriter;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:Gson.java

示例6: newJsonWriter

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
 * Returns a new JSON writer configured for this GSON and with the non-execute
 * prefix if that is configured.
 */
private JsonWriter newJsonWriter(Writer writer) throws IOException {
  if (generateNonExecutableJson) {
    writer.write(JSON_NON_EXECUTABLE_PREFIX);
  }
  JsonWriter jsonWriter = new JsonWriter(writer);
  if (prettyPrinting) {
    jsonWriter.setIndent("  ");
  }
  jsonWriter.setSerializeNulls(serializeNulls);
  return jsonWriter;
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:16,代码来源:Gson.java

示例7: main

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	JsonObject json = convertToJSON("test2.thjson");
	StringWriter out = new StringWriter();
	JsonWriter writer = new JsonWriter(out);
	writer.setIndent("\t");
	Gson gson = new Gson();
	gson.toJson(json, writer);
	writer.flush();
	Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(out.getBuffer().toString()), null);
	System.out.println(out.getBuffer().toString());
}
 
开发者ID:Puppygames,项目名称:thjson,代码行数:12,代码来源:THJSONReader.java

示例8: saveConfig

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
private void saveConfig()
{
    try
    {
        BufferedWriter writer = new BufferedWriter(new FileWriter(configFile));
        JsonWriter jsonWriter = new JsonWriter(writer);
        jsonWriter.setIndent("  ");
        CurseSync.GSON.toJson(config, Configuration.class, jsonWriter);
        writer.close();
    }
    catch (IOException e)
    {
        System.err.println("Failed to write configuration back to disk, aborting!");
    }
}
 
开发者ID:PaleoCrafter,项目名称:CurseSync,代码行数:16,代码来源:CurseSync.java

示例9: writeHistoryJson

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void writeHistoryJson(final OutputStream os, final List<Address> addresses) throws JsonWritingException {
    try {
        JsonWriter writer = new JsonWriter(new OutputStreamWriter(os, "UTF-8"));
        writer.setIndent("  ");
        writer.beginArray();
        for (Address address : addresses) {
            gson.toJson(address, Address.class, writer);
        }
        writer.endArray();
        writer.close();
    } catch (Exception e) {
        throw new JsonWritingException(e);
    }
}
 
开发者ID:RacZo,项目名称:Smarty-Streets-AutoCompleteTextView,代码行数:16,代码来源:GsonSmartyStreetsApiJsonParser.java

示例10: setWriterOptions

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
void setWriterOptions(JsonWriter writer) {
  writer.setSerializeNulls(serializeNulls);
  writer.setLenient(lenient);
  writer.setHtmlSafe(htmlSafe);
  writer.setIndent(prettyPrinting ? "  " : "");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:GsonMessageBodyProvider.java

示例11: process

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
private void process(HttpServletResponse resp, boolean showOnly) throws IOException {
  // everything ok, let's update
  StringBuilder summary = new StringBuilder();
  JsonObject contents = new JsonObject();
  JsonDataSources sources = new VendorDynamicInput().fetchAllDataSources();
  for (String entity: sources) {
    JsonArray array = new JsonArray();
    JsonDataSource source = sources.getSource(entity);
    for (JsonObject obj: source) {
      array.add(obj);
    }
    summary.append(entity).append(": ").append(source.size()).append("\n");
    contents.add(entity, array);
  }

  if (showOnly) {
    // Show generated contents to the output
    resp.setContentType("application/json");
    Writer writer = Channels.newWriter(Channels.newChannel(resp.getOutputStream()), "UTF-8");
    JsonWriter outputWriter = new JsonWriter(writer);
    outputWriter.setIndent("  ");
    new Gson().toJson(contents, outputWriter);
    outputWriter.flush();

  } else {
    // Write file to cloud storage
    CloudFileManager fileManager = new CloudFileManager();
    fileManager.createOrUpdate("__raw_session_data.json", contents, true);

    // send email
    Message message = new Message();
    message.setSender(Config.EMAIL_FROM);
    message.setSubject("[iosched-data-update] Manual sync from CMS");
    message.setTextBody(
        "Hey,\n\n"
        + "(this message is autogenerated)\n"
        + "This is a heads up that "+userService.getCurrentUser().getEmail()+" has just updated the IOSched 2015 data from the Vendor CMS.\n\n"
            + "Here is a brief status of what has been extracted from the Vendor API:\n"
            + summary
            + "\n\n"
            + "If you want to check the most current data that will soon be sync'ed to the IOSched Android app, "
            + "check this link: http://storage.googleapis.com/iosched-updater-dev.appspot.com/__raw_session_data.json\n"
            + "This data will remain unchanged until someone with proper privileges updates it again on https://iosched-updater-dev.appspot.com/cmsupdate\n\n"
            + "Thanks!\n\n"
            + "A robot on behalf of the IOSched team!\n\n"
            + "PS: you are receiving this either because you are an admin of the IOSched project or "
            + "because you are in a hard-coded list of I/O organizers. If you don't want to "
            + "receive it anymore, pay me a beer and ask kindly.");
    MailServiceFactory.getMailService().sendToAdmins(message);

    resp.sendRedirect("/admin/schedule/updateok.html");
  }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:54,代码来源:CMSUpdateServlet.java

示例12: execute

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void execute() throws IOException {
    RuntimeTypeAdapterFactory<DASTNodeLowLevel> nodeAdapter =
            RuntimeTypeAdapterFactory.of(DASTNodeLowLevel.class, "node")
                    .registerSubtype(DAPICallLowLevel.class, "DAPICall")
                    .registerSubtype(DBranchLowLevel.class, "DBranch")
                    .registerSubtype(DExceptLowLevel.class, "DExcept")
                    .registerSubtype(DLoopLowLevel.class, "DLoop")
                    .registerSubtype(DSubTreeLowLevel.class, "DSubTree");
    Gson gsonIn = new GsonBuilder().registerTypeAdapterFactory(nodeAdapter).
            serializeNulls().create();
    JsonReader reader = new JsonReader(new FileReader(inFile));

    Gson gsonOut = new GsonBuilder().serializeNulls().create();
    JsonWriter writer = new JsonWriter(new FileWriter(outFile));

    reader.beginObject();
    reader.nextName();
    reader.beginArray();

    writer.setIndent("  ");
    writer.beginObject();
    writer.name("programs");
    writer.beginArray();

    System.out.println();
    for (int i = 0; reader.hasNext(); i++) {
        System.out.print(String.format("\rProcessed %s programs", i));
        JSONInputWrapper inputProgram = gsonIn.fromJson(reader, JSONInputWrapper.class);
        JsonOutputWrapper outputProgram = new JsonOutputWrapper();

        outputProgram.file = inputProgram.file;
        outputProgram.ast = inputProgram.ast;
        outputProgram.low_level_sketch = inputProgram.ast.getLowLevelSketch();
        outputProgram.sequences = inputProgram.sequences;
        outputProgram.apicalls = inputProgram.apicalls;
        outputProgram.types = inputProgram.types;

        gsonOut.toJson(outputProgram, JsonOutputWrapper.class, writer);
    }
    System.out.println();

    reader.close();
    writer.endArray();
    writer.endObject();
    writer.close();
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:47,代码来源:LowLevelSketchExtractor.java

示例13: load

import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public static Config load(int configVersion, File configFile, Function<Void, InputStream> defaultConfigFactory) throws ServerException {
	try {
		int version = 0;

		JsonObject configObject = null;
		if (configFile.exists()) {
			try {
				configObject = new JsonParser().parse(new InputStreamReader(new FileInputStream(configFile))).getAsJsonObject();
				JsonElement jversion = configObject.get("_version");
				if (jversion != null && !jversion.isJsonNull()) {
					version = jversion.getAsInt();
				}
			} catch (Exception ignored) {}
		}

		if (version == 0 || version < configVersion) {
			InputStream configInputStream = defaultConfigFactory.apply(null);
			if (configInputStream == null) {
				throw new ServerException("Failed to get default config resource.");
			}

			if (version == 0) {
				logger.warn("Resetting your config...");

				final byte[] bytes = IO.getByteArray(configInputStream, true);
				if (bytes == null) {
					throw new ServerException("Failed to get default config.");
				}

				configObject = new JsonParser().parse(new InputStreamReader(new ByteArrayInputStream(bytes))).getAsJsonObject();
				try (OutputStream os = new FileOutputStream(configFile)) {
					os.write(bytes);
				}
			} else if (version < configVersion) {
				JsonObject defaultConfig = new JsonParser().parse(new InputStreamReader(configInputStream)).getAsJsonObject();
				GsonUtils.extendJsonObject(defaultConfig, GsonUtils.ConflictStrategy.PREFER_FIRST_OBJ, configObject);
				configObject = defaultConfig;
			}

			configObject.addProperty("_version", configVersion);

			logger.warn("Saving config...");
			JsonWriter writer = new JsonWriter(new FileWriter(configFile));
			writer.setIndent("\t");
			new Gson().toJson(configObject, writer);
			writer.close();

			logger.warn("Check out your config and start the server.");
			return null;
		}

		return new Config(configObject);
	} catch (Throwable e) {
		logger.fatal("Cannot read config.", e);
		throw new ServerException("Cannot read config.");
	}
}
 
开发者ID:Tarik02,项目名称:cr-private-server,代码行数:58,代码来源:Config.java


注:本文中的com.google.gson.stream.JsonWriter.setIndent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。