• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JsonGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.api.client.json.JsonGenerator的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator类的具体用法?Java JsonGenerator怎么用?Java JsonGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonGenerator类属于com.google.api.client.json包,在下文中一共展示了JsonGenerator类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: unauthorized

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
protected void unauthorized(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {

	String userAgent = req.getHeader("User-Agent");

	resp.setHeader("Content-Type", "text/javascript");
	resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

	JsonGenerator generator = jsonFactory.createJsonGenerator(resp.getWriter());
	generator.writeStartObject();
	generator.writeFieldName("error");
	generator.writeString("Login required.");
	generator.writeFieldName("q");
	generator.writeString(req.getQueryString());
	generator.writeFieldName("agent");
	generator.writeString(userAgent);
	generator.writeEndObject();
	generator.flush();
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgentExamples,代码行数:20,代码来源:UnauthorizedServlet.java


示例2: createTempJsonKeyFile

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
public static String createTempJsonKeyFile(String clientEmail,
                                           PrivateKey privateKey) throws
        IOException {
  final File tempJsonKey = File.createTempFile("temp-key", ".json",
          getTempFolder());
  JsonGenerator jsonGenerator = null;
  try {
    jsonGenerator = new JacksonFactory()
            .createJsonGenerator(new FileOutputStream(tempJsonKey),
                    Charset.forName("UTF-8"));
    jsonGenerator.enablePrettyPrint();
    jsonGenerator.serialize(createJsonKey(clientEmail, privateKey));
  } finally {
    if (jsonGenerator != null) {
      jsonGenerator.close();
    }
  }
  return tempJsonKey.getAbsolutePath();
}
 
开发者ID:jenkinsci,项目名称:google-oauth-plugin,代码行数:20,代码来源:JsonServiceAccountConfigTestUtil.java


示例3: createTempLegacyJsonKeyFileWithMissingClientEmail

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
public static String createTempLegacyJsonKeyFileWithMissingClientEmail()
        throws IOException {
  final File tempLegacyJsonKey =
          File.createTempFile("temp-legacykey", ".json", getTempFolder());
  JsonGenerator jsonGenerator = null;
  try {
    jsonGenerator = new JacksonFactory()
            .createJsonGenerator(new FileOutputStream(tempLegacyJsonKey),
                    Charset.forName("UTF-8"));
    jsonGenerator.enablePrettyPrint();
    jsonGenerator.serialize(createLegacyJsonKeyWithMissingClientEmail());
  } finally {
    if (jsonGenerator != null) {
      jsonGenerator.close();
    }
  }
  return tempLegacyJsonKey.getAbsolutePath();
}
 
开发者ID:jenkinsci,项目名称:google-oauth-plugin,代码行数:19,代码来源:LegacyJsonServiceAccountConfigUtil.java


示例4: save

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
private void save() throws IOException {
  FileOutputStream fos = new FileOutputStream(file);
  try {
    JsonGenerator generator = jsonFactory.createJsonGenerator(fos, Charsets.UTF_8);
    generator.serialize(credentials);
    generator.close();
  } finally {
    fos.close();
  }
}
 
开发者ID:agilie,项目名称:dribbble-android-sdk,代码行数:11,代码来源:FileCredentialStore.java


示例5: save

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
public void save() {
	try (FileOutputStream fos = new FileOutputStream(configFile)) {
		JsonGenerator generator = Start.JSON_FACTORY.createJsonGenerator(
				fos, Charset.forName("UTF-8"));
		generator.enablePrettyPrint();
		generator.serialize(this);
		generator.close();
	} catch (IOException ex) {
		throw new RuntimeException(ex);
	}
	
	for(ConfigChangeListener listener : this.listeners) {
		listener.onConfigChanged();
	}
}
 
开发者ID:r04r,项目名称:KSPModClient,代码行数:16,代码来源:Config.java


示例6: saveEnabledMods

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
private void saveEnabledMods(EnabledMods mods) throws IOException {
	try (FileOutputStream fos = new FileOutputStream(
			enabledModsFile.toFile())) {
		JsonGenerator generator = Start.JSON_FACTORY.createJsonGenerator(
				fos, Charset.forName("UTF-8"));
		generator.enablePrettyPrint();
		generator.serialize(mods);
		generator.close();
		_enabledMods = mods;
	}
}
 
开发者ID:r04r,项目名称:KSPModClient,代码行数:12,代码来源:ModManager.java


示例7: createTempLegacyJsonKeyFile

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
public static String createTempLegacyJsonKeyFile(String clientEmail)
        throws IOException {
  final File tempLegacyJsonKey =
          File.createTempFile("temp-legacykey", ".json", getTempFolder());
  final JsonGenerator jsonGenerator = new JacksonFactory()
          .createJsonGenerator(new FileOutputStream(tempLegacyJsonKey),
                  Charset.forName("UTF-8"));
  jsonGenerator.enablePrettyPrint();
  jsonGenerator.serialize(createLegacyJsonKey(clientEmail));
  jsonGenerator.close();
  return tempLegacyJsonKey.getAbsolutePath();
}
 
开发者ID:jenkinsci,项目名称:google-oauth-plugin,代码行数:13,代码来源:LegacyJsonServiceAccountConfigUtil.java


示例8: createTempLegacyJsonKeyFileWithMissingWebObject

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
public static String createTempLegacyJsonKeyFileWithMissingWebObject()
        throws IOException {
  final File tempLegacyJsonKey =
          File.createTempFile("temp-legacykey", ".json", getTempFolder());
  final JsonGenerator jsonGenerator = new JacksonFactory()
          .createJsonGenerator(new FileOutputStream(tempLegacyJsonKey),
                  Charset.forName("UTF-8"));
  jsonGenerator.enablePrettyPrint();
  jsonGenerator.serialize(createLegacyJsonKeyWithMissingWebObject());
  jsonGenerator.close();
  return tempLegacyJsonKey.getAbsolutePath();
}
 
开发者ID:jenkinsci,项目名称:google-oauth-plugin,代码行数:13,代码来源:LegacyJsonServiceAccountConfigUtil.java


示例9: storeClientToken

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
private void storeClientToken(final JsonFactory jsonFactory) throws IOException
{
	final StringWriter jsonTrWriter = new StringWriter();
	final JsonGenerator generator = jsonFactory.createJsonGenerator(jsonTrWriter);
	generator.serialize(clientToken);
	generator.flush();
	generator.close();

	FileUtils.writeStringToFile(clientTokenPath.toFile(), jsonTrWriter.toString(), charset);
}
 
开发者ID:HolgerHees,项目名称:cloudsync,代码行数:11,代码来源:RemoteGoogleDriveConnector.java


示例10: writeToken

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
private void writeToken() throws IOException {
  try (OutputStream outputStream = new FileOutputStream(tokenFile);
      OutputStreamWriter outputWriter = new OutputStreamWriter(outputStream)) {
    JsonGenerator generator = new JacksonFactory().createJsonGenerator(outputWriter);
    generator.enablePrettyPrint();
    generator.serialize(token);
    generator.flush();
  }
}
 
开发者ID:googleads,项目名称:googleads-shopping-samples,代码行数:10,代码来源:ConfigDataStoreFactory.java


示例11: downloadMod

import com.google.api.client.json.JsonGenerator; //导入依赖的package包/类
private File downloadMod(ApiMod mod) throws IOException {
	System.out.println("Starting download for " + mod.getTitle());

	String url = mod.getDownloadUrl();
	HttpURLConnection connection;
	boolean redirect = false;

	do {
		URL website = new URL(url);
		System.out.println("Accessing " + url);
		connection = (HttpURLConnection) website.openConnection();
		connection.setInstanceFollowRedirects(false);
		String location = connection.getHeaderField("Location");
		if (location != null) {
			connection.disconnect();
			url = location.replaceAll("(?i)/(\\d+)\\\\(\\d+)/", "/$1/$2/");

			if (!url.startsWith("http"))
				url = "http:" + url;

			URL u = new URL(url);
			String[] parts = u.getPath().split("/");
			for (int i = 0; i < parts.length; i++) {
				parts[i] = CharEscapers.escapeUriPath(parts[i]);
			}

			url = u.getProtocol() + "://" + u.getHost() + "/"
					+ Joiner.on('/').join(parts)
					+ (u.getQuery() != null ? "?" + u.getQuery() : "");
			redirect = true;
		} else {
			redirect = false;
		}
	} while (redirect);

	MessageDigest digest;
	try {
		digest = MessageDigest.getInstance("SHA1");
	} catch (NoSuchAlgorithmException e) {
		throw new RuntimeException(e);
	}

	File cacheFile = new File(Config.cachedir, "mod-" + mod.getId()
			+ ".zip");
	File cacheConfigFile = new File(Config.cachedir, mod.getInfoName());

	try (DigestInputStream dis = new DigestInputStream(
			connection.getInputStream(), digest);
			FileOutputStream fos = new FileOutputStream(cacheFile)) {
		IOUtils.copy(dis, fos);
	}

	try (FileOutputStream fos = new FileOutputStream(cacheConfigFile)) {
		JsonGenerator generator = Start.JSON_FACTORY.createJsonGenerator(
				fos, Charset.forName("UTF-8"));
		generator.enablePrettyPrint();
		generator.serialize(mod);
		generator.close();
	}

	System.out.println("Download finished "
			+ byteArray2Hex(digest.digest()) + " vs " + mod.getSha1sum());
	return cacheFile;
}
 
开发者ID:r04r,项目名称:KSPModClient,代码行数:65,代码来源:ModManager.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KNXNetworkLinkIP类代码示例发布时间:2022-05-22
下一篇:
Java IncomingOperationType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap