List of usage examples for org.apache.commons.lang3.time DateFormatUtils formatUTC
public static String formatUTC(final Date date, final String pattern)
Formats a date/time into a specific pattern using the UTC time zone.
From source file:com.ibm.iotf.devicemgmt.device.resource.DateResource.java
/** * Returns the value in Json Format//from www . j a v a2 s. c om */ @Override public JsonElement toJsonObject() { String utcTime = DateFormatUtils.formatUTC(getValue(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); return (JsonElement) new JsonPrimitive(utcTime); }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
/** * @param date/* w ww. ja v a2 s.co m*/ */ protected static String formatDate(Calendar date) { return DateFormatUtils.formatUTC(date.getTimeInMillis(), "yyyy-MM-dd'T'HH:mm:ss'Z'"); //$NON-NLS-1$ }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
/** * @param date/*from w ww .j a v a2 s.co m*/ */ protected static String formatDateWithMillis(Calendar date) { return DateFormatUtils.formatUTC(date.getTimeInMillis(), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); //$NON-NLS-1$ }
From source file:com.eryansky.common.utils.TimeUtils.java
/** * * @param date */ public TimeUtils(Date date) { this(DateFormatUtils.formatUTC(date, "HH:mm:ss")); }
From source file:com.dowdandassociates.gentoo.bootstrap.DefaultKeyPairInformation.java
@PostConstruct private void setup() { boolean nameSet = (null != name); boolean filenameSet = (null != filename); boolean keyExists = false; if (nameSet) { log.info("Checking if key pair \"" + name + "\" exists"); keyExists = !(ec2Client//from w w w . j a v a2s.com .describeKeyPairs(new DescribeKeyPairsRequest() .withFilters(new Filter().withName("key-name").withValues(name))) .getKeyPairs().isEmpty()); } if (keyExists && !filenameSet) { log.warn("Key pair \"" + name + "\" exists, but private key location is not specified"); keyExists = false; } if (!keyExists) { if (!nameSet) { name = "gentoo-bootstrap-" + DateFormatUtils.formatUTC(System.currentTimeMillis(), "yyyyMMdd'T'HHmmssSSS'Z'"); } if (!filenameSet) { try { filename = Files .createTempFile(name, ".pem", PosixFilePermissions .asFileAttribute(PosixFilePermissions.fromString("rw-------"))) .toString(); } catch (IOException ioe) { log.warn("Cannot create temp file", ioe); filename = name + ".pem"; } } log.info("Creating key pair \"" + name + "\""); CreateKeyPairResult createResult = ec2Client .createKeyPair(new CreateKeyPairRequest().withKeyName(name)); try { log.info("Saving pem file to \"" + filename + "\""); BufferedWriter outfile = new BufferedWriter(new FileWriter(filename)); try { outfile.write(createResult.getKeyPair().getKeyMaterial()); } catch (IOException ioe) { String message = "Error writing to file \"" + filename + "\""; log.error(message, ioe); throw new RuntimeException(message, ioe); } finally { outfile.close(); } } catch (IOException ioe) { String message = "Error opening file \"" + filename + "\""; log.error(message, ioe); throw new RuntimeException(message, ioe); } builtKeyPair = true; log.info("Key pair \"" + name + "\" built"); } else { builtKeyPair = false; log.info("Key pair \"" + name + "\" exists"); } if (filename.startsWith("~" + File.separator)) { filename = System.getProperty("user.home") + filename.substring(1); } }
From source file:com.dominion.salud.mpr.hl7.AbstractParser.java
/** * Dado un mensaje HL7 genera un mensaje ACK de respuesta correcta basado en * el mensaje original./*w w w . j ava2 s . c o m*/ * <p> * @param message base para generar la respuesta * @param text a mostrar en el campo MSA.3 * <p> * @return ACK basado en el mensaje original */ public ACK generateACK(Message message, String text) { if (message != null) { try { ACK ack = (ACK) message.generateACK(); //MSH ack.getMSH().getDateTimeOfMessage().getTime() .setValue(DateFormatUtils.formatUTC(System.currentTimeMillis(), "yyyyMMddHHmmss")); //MSH.7.1 ack.getMSH().getMessageControlID().setValue(new NanoTimeGenerator().getID()); //MSH.10 //MSA ack.getMSA().getTextMessage().setValue(text); return ack; } catch (HL7Exception | IOException e) { return generateNACK(message, e.toString()); } } else { return generateNACK(message); } }
From source file:com.dowdandassociates.gentoo.bootstrap.DefaultTestImageProvider.java
public Optional<Image> get() { if (!testSnapshot.isPresent()) { log.info("test snapshot not present"); return Optional.absent(); }// ww w . ja v a2 s. c om StringBuilder name = new StringBuilder(); name.append(prefix.get()); if (StringUtils.isNotBlank(dateFormat.get())) { name.append(DateFormatUtils.formatUTC(System.currentTimeMillis(), dateFormat.get())); } String architecture = imageInformation.getArchitecture(); String virtualizationType = imageInformation.getVirtualizationType(); RegisterImageRequest registerImageRequest = new RegisterImageRequest().withArchitecture(architecture) .withVirtualizationType(virtualizationType).withDescription(description.get()) .withName(name.toString()).withRootDeviceName(rootDeviceName.get()); if ("paravirtual".equals(virtualizationType)) { if (!kernelImage.isPresent()) { log.info("kernel image not present"); return Optional.absent(); } registerImageRequest = registerImageRequest.withKernelId(kernelImage.get().getImageId()); } if ("i386".equals(architecture)) { registerImageRequest = registerImageRequest.withBlockDeviceMappings( new BlockDeviceMapping().withDeviceName(rootDeviceName.get()) .withEbs(new EbsBlockDevice().withSnapshotId(testSnapshot.get().getSnapshotId())), new BlockDeviceMapping().withDeviceName("/dev/sda2").withVirtualName("ephemeral0"), new BlockDeviceMapping().withDeviceName("/dev/sda3").withVirtualName("ephemeral1")); } else { registerImageRequest = registerImageRequest.withBlockDeviceMappings( new BlockDeviceMapping().withDeviceName(rootDeviceName.get()) .withEbs(new EbsBlockDevice().withSnapshotId(testSnapshot.get().getSnapshotId())), new BlockDeviceMapping().withDeviceName("/dev/sdb").withVirtualName("ephemeral0"), new BlockDeviceMapping().withDeviceName("/dev/sdc").withVirtualName("ephemeral1"), new BlockDeviceMapping().withDeviceName("/dev/sdd").withVirtualName("ephemeral2"), new BlockDeviceMapping().withDeviceName("/dev/sde").withVirtualName("ephemeral3")); } RegisterImageResult registerImageResult = ec2Client.registerImage(registerImageRequest); String imageId = registerImageResult.getImageId(); DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest().withImageIds(imageId); try { while (true) { log.info("Sleeping for " + sleep.get() + " ms"); Thread.sleep(sleep.get()); DescribeImagesResult describeImagesResult = ec2Client.describeImages(describeImagesRequest); if (describeImagesResult.getImages().isEmpty()) { return Optional.absent(); } Image image = describeImagesResult.getImages().get(0); String state = image.getState(); log.info("Image state = " + state); if ("pending".equals(state)) { continue; } if (!"available".equals(state)) { return Optional.absent(); } return Optional.fromNullable(image); } } catch (InterruptedException e) { return Optional.absent(); } }
From source file:com.dominion.salud.mpr.hl7.AbstractParser.java
/** * Genera una respuesta erronea generica. * <p>/* w w w .java2 s . c o m*/ * @param text a mostrar en el campo MSA.3 * <p> * @return NACK de respuesta generico */ public ACK generateNACK(String text) { ACK ack = new ACK(); try { ack.initQuickstart("ACK", null, "P"); //MSH ack.getMSH().getSendingApplication().getNamespaceID().setValue("MPR"); //MSH.3.1 ack.getMSH().getSendingFacility().getNamespaceID().setValue("mpr-ws"); //MSH.4.1 ack.getMSH().getDateTimeOfMessage().getTime() .setValue(DateFormatUtils.formatUTC(System.currentTimeMillis(), yyyyMMddHHmmss)); //MSH.7.1 ack.getMSH().getMessageControlID().setValue(new NanoTimeGenerator().getID()); //MSH.10 //MSA ack.getMSA().getAcknowledgmentCode().setValue("AE"); //ERR ack.getERR().getHL7ErrorCode().getIdentifier().setValue("207"); ack.getERR().getSeverity().setValue("E"); ack.getERR().getDiagnosticInformation().setValue(text); } catch (HL7Exception | IOException e) { logger.error("No se ha podido generar la respuesta por defecto: " + e.toString()); } return ack; }
From source file:com.ibm.iotf.devicemgmt.device.DiagnosticLog.java
/** * Return the <code>JsonObject</code> representation of the <code>DeviceDiagnostic</code> object. * @return JsonObject object/*w w w .j a v a2 s .co m*/ */ public JsonObject toJsonObject() { JsonObject o = new JsonObject(); o.add("message", new JsonPrimitive(this.message)); o.add("severity", new JsonPrimitive(severity.getSeverity())); String utcTime = DateFormatUtils.formatUTC(timestamp, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); o.add("timestamp", new JsonPrimitive(utcTime)); if (this.data != null) { byte[] encodedBytes = Base64.encodeBase64(data.getBytes()); o.add("data", new JsonPrimitive(new String(encodedBytes))); } return o; }
From source file:com.github.nlloyd.hornofmongo.util.BSONizer.java
public static Object convertJStoBSON(Object jsObject, boolean isJsObj, String dateFormat) { Object bsonObject = null;/* www. j a v a 2 s . com*/ if (jsObject instanceof NativeArray) { NativeArray jsArray = (NativeArray) jsObject; List<Object> bsonArray = new ArrayList<Object>(Long.valueOf(jsArray.getLength()).intValue()); for (Object jsEntry : jsArray) { bsonArray.add(convertJStoBSON(jsEntry, isJsObj, dateFormat)); } bsonObject = bsonArray; } else if (jsObject instanceof NativeRegExp) { Object source = ScriptableObject.getProperty((Scriptable) jsObject, "source"); String fullRegex = (String) Context.jsToJava(jsObject, String.class); String options = fullRegex.substring(fullRegex.lastIndexOf("/") + 1); bsonObject = Pattern.compile(source.toString(), Bytes.regexFlags(options)); ; } else if (jsObject instanceof NativeObject) { BasicDBObject bson = new BasicDBObject(); bsonObject = bson; NativeObject rawJsObject = (NativeObject) jsObject; for (Object key : rawJsObject.keySet()) { Object value = extractJSProperty(rawJsObject, key); //GC: 17/11/15 allow for UTC $date object if (key.equals("$date")) { try { bsonObject = DateUtils.parseDate(value.toString(), new String[] { "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" }); } catch (java.text.ParseException e) { bson.put(key.toString(), convertJStoBSON(value, isJsObj, dateFormat)); } } else { bson.put(key.toString(), convertJStoBSON(value, isJsObj, dateFormat)); } } } else if (jsObject instanceof ScriptableMongoObject) { bsonObject = convertScriptableMongoToBSON((ScriptableMongoObject) jsObject, isJsObj, dateFormat); } else if (jsObject instanceof BaseFunction) { BaseFunction funcObject = (BaseFunction) jsObject; Object classPrototype = ScriptableObject.getClassPrototype(funcObject, funcObject.getFunctionName()); if ((classPrototype instanceof MinKey) || (classPrototype instanceof MaxKey)) { // this is a special case handler for instances where MinKey or // MaxKey are provided without explicit constructor calls // index_check3.js does this bsonObject = convertScriptableMongoToBSON((ScriptableMongoObject) classPrototype, isJsObj, dateFormat); } else { // comes from eval calls String decompiledCode = (String) MongoRuntime.call(new JSDecompileAction(funcObject)); bsonObject = new Code(decompiledCode); } } else if (jsObject instanceof ScriptableObject) { // we found a ScriptableObject that isn't any of the concrete // ScriptableObjects above... String jsClassName = ((ScriptableObject) jsObject).getClassName(); if ("Date".equals(jsClassName)) { Date dt = (Date) Context.jsToJava(jsObject, Date.class); bsonObject = dt; //GC: 18/11/15 use dateFormat parameter to format date fields if (dateFormat != null && dateFormat.length() > 0) bsonObject = DateFormatUtils.formatUTC(dt, dateFormat); } else { Context.throwAsScriptRuntimeEx( new MongoScopeException("bsonizer couldnt convert js class: " + jsClassName)); bsonObject = jsObject; } } else if (jsObject instanceof ConsString) { bsonObject = jsObject.toString(); } else if (jsObject instanceof Undefined) { bsonObject = jsObject; } else if (jsObject instanceof Integer) { // this may seem strange, but JavaScript only knows about the number // type // which means in the official client we need to pass a Double // this applies to Long and Integer values bsonObject = Double.valueOf((Integer) jsObject); } else if (jsObject instanceof Long) { bsonObject = Double.valueOf((Long) jsObject); } else { bsonObject = jsObject; } return bsonObject; }