public void writeDate(String name, Date val) throws IOException { // updated to use Joda time writeDate(name, new DateTime(val).toString(dateFormat)); }
try { XContentBuilder json = XContentFactory.jsonBuilder().startObject(); json.field("time", nowdt.toDateTimeISO().toString()); json.field("starttime", startdt.toDateTimeISO().toString()); json.field("localaddr", localaddr); json.field("localport", localport); json.field("size", contentLength); json.field("duration", latency); json.field("year", nowdt.toString("yyyy")); json.field("month", nowdt.toString("MM")); json.field("day", nowdt.toString("dd")); json.field("hour", nowdt.toString("HH")); json.field("minute", nowdt.toString("mm")); json.field("dow", nowdt.toString("EEE")); json.field("cluster", clusterName); if (remoteuser != null) { } catch (IOException e) { logger.info("## Could not serialize to json: {} {} {} {} {} {} {} {} [{}]", nowdt.toDateTimeISO().toString(), method, path,
@Override public RestResponse buildResponse(ConsistencyCheckResponse response) throws Exception { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); builder.field("ok", true); builder.startObject("state"); response.getState().toXContent(builder, ToXContent.EMPTY_PARAMS); builder.startArray("files"); for (File file : response.getFiles()) { Instant instant = new Instant(file.lastModified()); builder.startObject() .field("path", file.getAbsolutePath()) .field("lastmodified", instant.toDateTime().toString()) .field("size", new SizeValue(file.length(), SizeUnit.SINGLE).toString()) .field("totalspace", new SizeValue(file.getTotalSpace(), SizeUnit.SINGLE).toString()) .field("usablespace", new SizeValue(file.getUsableSpace(), SizeUnit.SINGLE).toString()) .field("freespace", new SizeValue(file.getFreeSpace(), SizeUnit.SINGLE).toString()) .endObject(); } builder.endArray(); builder.endObject(); return new BytesRestResponse(OK, builder); } });