本文整理汇总了Java中com.eclipsesource.json.WriterConfig类的典型用法代码示例。如果您正苦于以下问题:Java WriterConfig类的具体用法?Java WriterConfig怎么用?Java WriterConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriterConfig类属于com.eclipsesource.json包,在下文中一共展示了WriterConfig类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: write
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
public static boolean write() {
FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
JsonObject json = new JsonObject();
for (Map.Entry<String, Setting> entry : settings.entrySet()) {
json.set(entry.getKey(), entry.getValue().toJson());
}
try {
Writer writer = fileHandle.writer(false);
json.writeTo(writer, WriterConfig.PRETTY_PRINT);
writer.close();
} catch (Exception e) {
Log.error("Failed to write settings", e);
fileHandle.delete();
return false;
}
return true;
}
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:18,代码来源:Settings.java
示例2: write
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
public static boolean write() {
FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
JsonObject json = new JsonObject();
for (Map.Entry<String, Setting> entry : settings.entrySet()) {
json.set(entry.getKey(), entry.getValue().toJson());
}
try {
Writer writer = fileHandle.writer(false);
json.writeTo(writer, WriterConfig.PRETTY_PRINT);
writer.close();
} catch (Exception e) {
Log.error("Failed to write settings", e);
fileHandle.delete();
return false;
}
return true;
}
开发者ID:RedTroop,项目名称:Cubes,代码行数:18,代码来源:Settings.java
示例3: des_ser_must_be_equals
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
@Test
public void des_ser_must_be_equals() throws IOException {
// load file
InputStream inputStream = ObjectModelSerDesTest.class.getResourceAsStream("/model.json");
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String smodel = result.toString("UTF-8");
// deserialize
ObjectModelSerDes serDes = new ObjectModelSerDes();
JsonValue json = Json.parse(smodel);
List<ObjectModel> models = serDes.deserialize(json.asArray());
// serialize
JsonArray arr = serDes.jSerialize(models);
String res = arr.toString(WriterConfig.PRETTY_PRINT);
Assert.assertEquals("value should be equals", smodel, res);
}
开发者ID:eclipse,项目名称:leshan,代码行数:24,代码来源:ObjectModelSerDesTest.java
示例4: composeHtmlResponseBody
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
protected void composeHtmlResponseBody(HttpServletRequest request,
HttpServletResponse response, HtmlComposer html)
throws ServletException, IOException {
html.h(3, "chatter " + _chatterItemSegment);
JsonObject chatterItemJson = null;
try {
long chatterItemOrdinal = Long.parseLong(_chatterItemSegment);
ChatterItemDetails chatterItemDetails = getChatterItemDetails(chatterItemOrdinal);
chatterItemJson = chatterItemDetails.getJson();
} catch (NumberFormatException ex) {
//
}
if (chatterItemJson == null) {
html.p("item not found.");
} else {
html.pre(chatterItemJson.toString(WriterConfig.PRETTY_PRINT));
}
}
开发者ID:cjdaly,项目名称:fold,代码行数:21,代码来源:ChatterChannel.java
示例5: composeHtmlResponseBody
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
protected void composeHtmlResponseBody(HttpServletRequest request,
HttpServletResponse response, HtmlComposer html)
throws ServletException, IOException {
html.h(3, "vitals " + _vitalsItemSegment);
JsonObject vitalsItemJson = null;
try {
long vitalsItemOrdinal = Long.parseLong(_vitalsItemSegment);
ChannelItemNode vitalsItemNode = new ChannelItemNode(
VitalsChannel.this, "Vitals");
vitalsItemJson = vitalsItemNode
.getOrdinalNode(vitalsItemOrdinal);
} catch (NumberFormatException ex) {
//
}
if (vitalsItemJson == null) {
html.p("item not found.");
} else {
html.pre(vitalsItemJson.toString(WriterConfig.PRETTY_PRINT));
}
}
开发者ID:cjdaly,项目名称:fold,代码行数:22,代码来源:VitalsChannel.java
示例6: invokeCypher
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
public void invokeCypher(ICypher cypher, boolean logErrors) {
if (_neo4jController.isNeo4jReady()) {
JsonObject response;
if (cypher.allowParallelInvocation()) {
response = Neo4jRestUtil.doPostJson(Neo4jRestUtil.CYPHER_URI,
cypher.getRequest());
} else {
response = serialInvokeCypher(cypher, logErrors);
}
((Cypher) cypher).setResponse(response);
if ((cypher.getErrorCount() > 0) && logErrors) {
System.out.println("------");
System.out.println("Cypher In:");
System.out.println(cypher.getRequest().toString(
WriterConfig.PRETTY_PRINT));
System.out.println("------");
System.out.println("Cypher Out:");
System.out.println(cypher.getResponse().toString(
WriterConfig.PRETTY_PRINT));
System.out.println("------");
}
}
}
开发者ID:cjdaly,项目名称:fold,代码行数:27,代码来源:Neo4jService.java
示例7: toString
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
public String toString(PrintMode printMode) {
StringWriter sw = new StringWriter();
try {
switch (printMode) {
case REGULAR:
Json.parse(toString()).writeTo(sw, PrettyPrint.singleLine());
break;
case PRETTY:
Json.parse(toString()).writeTo(sw, WriterConfig.PRETTY_PRINT);
break;
default:
return toString();
}
} catch (IOException e) {}
return sw.toString();
}
开发者ID:wnameless,项目名称:json-flattener,代码行数:18,代码来源:JsonifyLinkedHashMap.java
示例8: testPrintMode
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
@Test
public void testPrintMode() throws IOException {
String src = "{\"abc.def\":123}";
String json =
new JsonUnflattener(src).withPrintMode(PrintMode.MINIMAL).unflatten();
StringWriter sw = new StringWriter();
Json.parse(json).writeTo(sw, WriterConfig.MINIMAL);
assertEquals(sw.toString(), json);
json =
new JsonUnflattener(src).withPrintMode(PrintMode.REGULAR).unflatten();
sw = new StringWriter();
Json.parse(json).writeTo(sw, PrettyPrint.singleLine());
assertEquals(sw.toString(), json);
json = new JsonUnflattener(src).withPrintMode(PrintMode.PRETTY).unflatten();
sw = new StringWriter();
Json.parse(json).writeTo(sw, WriterConfig.PRETTY_PRINT);
assertEquals(sw.toString(), json);
}
开发者ID:wnameless,项目名称:json-flattener,代码行数:21,代码来源:JsonUnflattenerTest.java
示例9: getRawTransaction
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
public synchronized String getRawTransaction(String txID)
throws WalletCallException, IOException, InterruptedException
{
JsonObject jsonTransaction = this.executeCommandAndGetJsonObject(
"gettransaction", wrapStringParameter(txID));
return jsonTransaction.toString(WriterConfig.PRETTY_PRINT);
}
开发者ID:ZencashOfficial,项目名称:zencash-swing-wallet-ui,代码行数:9,代码来源:ZCashClientCaller.java
示例10: save
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
/**
* Save current settings to configuration.
*/
public void save() {
try {
if (!confFile.exists() && !confFile.createNewFile()) {
// Return if config file cannot be found and cannot be created.
return;
}
JsonObject json = Json.object();
for (Field field : this.getClass().getDeclaredFields()) {
// Skip private and static fields.
int mod = field.getModifiers();
if (Modifier.isPrivate(mod) || Modifier.isStatic(mod)) {
continue;
}
// Access via reflection, add value to json object.
field.setAccessible(true);
String name = field.getName();
Object value = field.get(this);
if (value instanceof Boolean) {
json.set(name, (boolean) value);
} else if (value instanceof Integer) {
json.set(name, (int) value);
} else if (value instanceof String) {
json.set(name, (String) value);
} else {
JsonValue converted = convert(field.getType(), value);
if (converted != null) {
json.set(name, converted);
}
}
}
// Write json to file
StringWriter w = new StringWriter();
json.writeTo(w, WriterConfig.PRETTY_PRINT);
Files.writeFile(confFile.getAbsolutePath(), w.toString());
} catch (Exception e) {
Recaf.INSTANCE.logging.error(e);
}
}
开发者ID:Col-E,项目名称:Recaf,代码行数:42,代码来源:Config.java
示例11: toJSON
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
@Override
public String toJSON() {
JsonObject object = Json.object();
object.set("type", 1);
object.set("matchTime", matchTime);
object.set("systemTime", systemTime);
return object.toString(Constants.LOGGER_PRETTY_PRINT ? WriterConfig.PRETTY_PRINT : WriterConfig.MINIMAL);
}
开发者ID:FRC1458,项目名称:turtleshell,代码行数:11,代码来源:BlastoiseDataLogger.java
示例12: getWriterConfig
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
private WriterConfig getWriterConfig() {
switch (printMode) {
case REGULAR:
return PrettyPrint.singleLine();
case PRETTY:
return WriterConfig.PRETTY_PRINT;
default:
return WriterConfig.MINIMAL;
}
}
开发者ID:wnameless,项目名称:json-flattener,代码行数:11,代码来源:JsonUnflattener.java
示例13: testPrintMode
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
@Test
public void testPrintMode() throws IOException {
URL url = Resources.getResource("test.json");
String src = Resources.toString(url, Charsets.UTF_8);
String json =
new JsonFlattener(src).withPrintMode(PrintMode.MINIMAL).flatten();
StringWriter sw = new StringWriter();
Json.parse(json).writeTo(sw, WriterConfig.MINIMAL);
assertEquals(sw.toString(), json);
json = new JsonFlattener(src).withPrintMode(PrintMode.REGULAR).flatten();
sw = new StringWriter();
Json.parse(json).writeTo(sw, PrettyPrint.singleLine());
assertEquals(sw.toString(), json);
json = new JsonFlattener(src).withPrintMode(PrintMode.PRETTY).flatten();
sw = new StringWriter();
Json.parse(json).writeTo(sw, WriterConfig.PRETTY_PRINT);
assertEquals(sw.toString(), json);
src = "[[123]]";
json = new JsonFlattener(src).withFlattenMode(FlattenMode.KEEP_ARRAYS)
.withPrintMode(PrintMode.MINIMAL).flatten();
sw = new StringWriter();
Json.parse(json).writeTo(sw, WriterConfig.MINIMAL);
assertEquals(sw.toString(), json);
json = new JsonFlattener(src).withFlattenMode(FlattenMode.KEEP_ARRAYS)
.withPrintMode(PrintMode.REGULAR).flatten();
sw = new StringWriter();
Json.parse(json).writeTo(sw, PrettyPrint.singleLine());
assertEquals(sw.toString(), json);
json = new JsonFlattener(src).withFlattenMode(FlattenMode.KEEP_ARRAYS)
.withPrintMode(PrintMode.PRETTY).flatten();
sw = new StringWriter();
Json.parse(json).writeTo(sw, WriterConfig.PRETTY_PRINT);
assertEquals(sw.toString(), json);
}
开发者ID:wnameless,项目名称:json-flattener,代码行数:41,代码来源:JsonFlattenerTest.java
示例14: composeHtmlResponseBody
import com.eclipsesource.json.WriterConfig; //导入依赖的package包/类
protected void composeHtmlResponseBody(HttpServletRequest request,
HttpServletResponse response, HtmlComposer html)
throws ServletException, IOException {
GetTimesNode sketch = new GetTimesNode(getEpochNodeId());
long timeNodeId = sketch.getTimeNodeId(_path);
if (timeNodeId == -1) {
html.p("node not found.");
} else {
html.p("node: ");
MultiPropertyAccessNode propsNode = new MultiPropertyAccessNode(
timeNodeId);
JsonObject jsonObject = propsNode.getProperties();
html.pre(jsonObject.toString(WriterConfig.PRETTY_PRINT));
switch (_path.segmentCount()) {
case 2: // epoch
html.p("years: ");
break;
case 3: // year
html.p("months: ");
break;
case 4: // month
html.p("days: ");
break;
case 5: // day
html.p("hours: ");
break;
case 6: // hour
html.p("minutes: ");
break;
case 7: // minute
String imageUrl = "/fold"
+ _path.removeTrailingSeparator().toString()
+ "/time-tree-slice.svg";
html.object(imageUrl, "image/svg+xml");
}
HierarchyNode hierNode = new HierarchyNode(timeNodeId);
String[] segments = hierNode.getSubSegments();
if (segments.length > 0) {
html.ul();
for (String segment : segments) {
html.li(html.A("/fold"
+ _path.removeTrailingSeparator().toString()
+ "/" + segment, segment));
}
html.ul(false);
}
RefTimesNode refNodes = new RefTimesNode(timeNodeId);
TreeMap<String, TreeMap<Long, IChannelItemDetails>> minuteMap = refNodes
.populateMinuteMap(getChannelService());
for (Entry<String, TreeMap<Long, IChannelItemDetails>> channelEntry : minuteMap
.entrySet()) {
html.h(4, channelEntry.getKey());
html.ul();
for (Entry<Long, IChannelItemDetails> channelItemEntry : channelEntry
.getValue().entrySet()) {
html.li(html.A(
channelItemEntry.getValue().getUrlPath(),
channelItemEntry.getKey().toString()));
}
html.ul(false);
}
}
}
开发者ID:cjdaly,项目名称:fold,代码行数:68,代码来源:TimesChannel.java
注:本文中的com.eclipsesource.json.WriterConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论