Example usage for org.apache.commons.lang3.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT

List of usage examples for org.apache.commons.lang3.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT.

Prototype

FastDateFormat ISO_DATETIME_TIME_ZONE_FORMAT

To view the source code for org.apache.commons.lang3.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT.

Click Source Link

Document

ISO 8601 formatter for date-time with time zone.

Usage

From source file:com.ibm.iotf.devicemgmt.device.resource.DateResource.java

/**
 * Returns the value in Json Format//from w  w w.  ja  v a 2 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:com.azaptree.services.command.impl.CommandExcecutionMetric.java

@Override
public String toString() {
    final StringBuilder sb = new StringBuilder(256);
    sb.append("CommandExcecutionMetric [key=");
    key.toString(sb);//from   ww  w .  jav a2s. co  m
    sb.append(", executionTimeStart=")
            .append(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(executionTimeStart));
    sb.append(", executionTime=").append(executionTimeEnd - executionTimeStart).append(" msec, success=")
            .append(success);
    if (throwable != null) {
        sb.append(", throwable=").append(ExceptionUtils.getStackTrace(throwable));
    }
    sb.append(']');

    return sb.toString();
}

From source file:com.ah.be.common.PresenceUtil.java

private static void saveCustoemrInformation(String customerId, HmDomain domain) {
    try {/*  ww w. ja va 2 s .  c  om*/
        long current = System.currentTimeMillis();
        PresenceAnalyticsCustomer customer = new PresenceAnalyticsCustomer();
        customer.setCustomerId(customerId);
        customer.setOwner(domain);
        customer.setCreateAt(
                DateFormatUtils.format(current, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()));
        QueryUtil.createBo(customer);
        putPresenceCustomerId(customerId, domain.getId());
    } catch (Exception e) {
        log.error("saveCustoemrInformation error, domain: " + domain.getDomainName());
    }
}

From source file:com.codealot.url2text.Response.java

/**
 * Constructor to build an instance from the output of {@link #toJson()}.
 * /*www . j av a  2  s  .  c om*/
 * @param json
 * @throws IOException
 * @throws JsonProcessingException
 * @throws ParseException 
 */
public Response(final String json) throws JsonProcessingException, IOException, ParseException {
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode rootNode = mapper.readTree(json);

    final JsonNode transactionNode = rootNode.get(HDR_TRANSACTION_METADATA);
    this.requestPage = transactionNode.get(HDR_REQUEST_PAGE).textValue();
    this.landingPage = transactionNode.get(HDR_LANDING_PAGE).textValue();
    this.status = transactionNode.get(HDR_STATUS).asInt();
    this.statusMessage = transactionNode.get(HDR_STATUS_MESSAGE).textValue();
    this.fetchDate = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT
            .parse(transactionNode.get(HDR_FETCH_DATE).textValue());
    this.fetchDuration = transactionNode.get(HDR_FETCH_DURATION).asLong();
    this.contentType = transactionNode.get(HDR_CONTENT_TYPE).textValue();
    this.contentCharset = transactionNode.get(HDR_CONTENT_CHARSET).textValue();
    this.contentLength = transactionNode.get(HDR_CONTENT_LENGTH).asLong();
    this.etag = transactionNode.get(HDR_ETAG).textValue();
    this.lastModified = transactionNode.get(HDR_LAST_MODIFIED).textValue();
    this.conversionDuration = transactionNode.get(HDR_CONVERSION_DURATION).asLong();

    final JsonNode headersNode = rootNode.get(HDR_RESPONSE_HEADERS);
    for (final Iterator<String> i = headersNode.fieldNames(); i.hasNext();) {
        final String key = i.next();
        final String value = headersNode.get(key).textValue();
        this.responseHeaders.add(new NameAndValue(key, value));
    }

    final JsonNode metadataNode = rootNode.get(HDR_CONTENT_METADATA);
    for (final Iterator<String> i = metadataNode.fieldNames(); i.hasNext();) {
        final String key = i.next();
        final String value = metadataNode.get(key).textValue();
        this.contentMetadata.add(new NameAndValue(key, value));
    }

    this.textReader = new StringReader(rootNode.get(HDR_CONVERTED_TEXT).textValue());
}

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/*ww  w. j  av a 2 s .  c  om*/
 */
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.keedio.nifi.processors.azure.blob.PutAzureBlobObjectTest.java

@Test
public void testPutAzureBlobObjectProcessorOverride()
        throws IOException, ParseException, InitializationException, InterruptedException, InvalidKeyException,
        StorageException, URISyntaxException {
    CloudBlobWrapper blob = null;//  w w  w .ja va  2 s.com
    try {

        String connectionString = System.getProperty("storageConnectionString");
        String containerName = System.getProperty("containerName");

        Assume.assumeTrue(StringUtils.isNoneEmpty(connectionString, containerName));

        AzureBlobConnectionService connectionService = new AzureBlobConnectionServiceImpl();
        Map<String, String> controllerProperties = new HashMap<>();
        controllerProperties.put(AZURE_STORAGE_CONNECTION_STRING.getName(), connectionString);
        controllerProperties.put(AZURE_STORAGE_CONTAINER_NAME.getName(), containerName);

        testRunner.addControllerService("my-put-test-connection-service", connectionService,
                controllerProperties);

        testRunner.enableControllerService(connectionService);
        testRunner.assertValid(connectionService);
        testRunner.setProperty(AZURE_STORAGE_CONTROLLER_SERVICE, connectionService.getIdentifier());

        Date now = new Date();

        Thread.sleep(1100);

        testRunner.setProperty(AZURE_STORAGE_BEHAVIOUR_IF_BLOB_EXISTS, "overwrite");

        final String DYNAMIC_ATTRIB_KEY_1 = "runTimestamp";
        final String DYNAMIC_ATTRIB_VALUE_1 = String.valueOf(System.nanoTime());
        final String DYNAMIC_ATTRIB_KEY_2 = "testUploader";
        final String DYNAMIC_ATTRIB_VALUE_2 = "KEEDIO";

        PropertyDescriptor testAttrib1 = processor.getSupportedDynamicPropertyDescriptor(DYNAMIC_ATTRIB_KEY_1);
        testRunner.setProperty(testAttrib1, DYNAMIC_ATTRIB_VALUE_1);
        PropertyDescriptor testAttrib2 = processor.getSupportedDynamicPropertyDescriptor(DYNAMIC_ATTRIB_KEY_2);
        testRunner.setProperty(testAttrib2, DYNAMIC_ATTRIB_VALUE_2);

        final Map<String, String> attrs = new HashMap<>();
        attrs.put(CoreAttributes.FILENAME.key(), TEST_PUT_AZURE_BLOB_OBJECT_BLOCKBLOB_TMP);

        testRunner.enqueue(getResourcePath("/blockblob.tmp"), attrs);
        testRunner.assertValid();

        testRunner.run(1);
        testRunner.assertAllFlowFilesTransferred(REL_SUCCESS, 1);

        MockFlowFile mockFlowFile = testRunner.getFlowFilesForRelationship(REL_SUCCESS).get(0);
        Map<String, String> attributes = mockFlowFile.getAttributes();
        assertTrue(attributes.size() >= 3);

        assertEquals(TEST_PUT_AZURE_BLOB_OBJECT_BLOCKBLOB_TMP, attributes.get("metadata.blobName"));
        assertEquals("blobbasics3d8a33d05e7940dabbb92476fc4fb345", attributes.get("metadata.containerName"));
        assertNotNull(attributes.get("property.lastModified"));

        Date lastModified = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT
                .parse(attributes.get("property.lastModified"));

        assertTrue(lastModified.after(now) || lastModified.equals(now));

        assertTrue(Long.parseLong(attributes.get("property.length")) >= 0);
        assertFalse(attributes.containsKey("property.contentDisposition"));
        assertFalse(attributes.containsKey("property.copyState"));

        File localTestFile = new File("src/test/resources/blockblob.tmp");
        mockFlowFile.assertContentEquals(localTestFile);

        blob = new CloudBlobWrapper(TEST_PUT_AZURE_BLOB_OBJECT_BLOCKBLOB_TMP,
                connectionService.getCloudBlobContainerReference());

        try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
            blob.download(os);
            assertEquals(localTestFile.length(), os.toByteArray().length);
        }
    } finally {
        if (blob != null)
            blob.deleteIfExists();
    }
}

From source file:com.ibm.iotf.devicemgmt.device.DeviceLocation.java

/**
 * Return the <code>JsonObject</code> representation of the <code>DeviceLocation</code> object.
 * @return JsonObject object//from ww w . jav  a  2s . com
 */
public JsonObject toJsonObject() {
    JsonObject json = new JsonObject();
    json.addProperty(this.latitude.getResourceName(), latitude.getValue());
    json.addProperty(this.longitude.getResourceName(), longitude.getValue());
    if (elevation != null) {
        json.addProperty(this.elevation.getResourceName(), elevation.getValue());
    }

    String utcTime = DateFormatUtils.formatUTC(measuredDateTime.getValue(),
            DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());

    json.addProperty(this.measuredDateTime.getResourceName(), utcTime);

    if (accuracy != null) {
        json.addProperty(this.accuracy.getResourceName(), accuracy.getValue());
    }
    return json;
}

From source file:com.codealot.url2text.Response.java

/**
 * Renders this object as JSON.//  w  w w .j  a  v  a2 s .c  o m
 * <p>
 * Beware. This method consumes the internal Reader, creating a buffer of
 * unlimited size.
 * 
 * @return
 * @throws Url2TextException
 */
public String toJson() throws Url2TextException {

    final JsonFactory jFactory = new JsonFactory();
    final ByteArrayOutputStream destination = new ByteArrayOutputStream();

    try (final JsonGenerator jsonGenerator = jFactory.createGenerator(destination);) {
        jsonGenerator.writeStartObject();

        // transaction metadata
        jsonGenerator.writeFieldName(HDR_TRANSACTION_METADATA);
        jsonGenerator.writeStartObject();

        jsonGenerator.writeStringField(HDR_REQUEST_PAGE, this.requestPage);
        jsonGenerator.writeStringField(HDR_LANDING_PAGE, this.landingPage);
        jsonGenerator.writeNumberField(HDR_STATUS, this.status);
        jsonGenerator.writeStringField(HDR_STATUS_MESSAGE, this.statusMessage);
        jsonGenerator.writeStringField(HDR_FETCH_DATE,
                DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(this.fetchDate));
        jsonGenerator.writeNumberField(HDR_FETCH_DURATION, this.fetchDuration);
        jsonGenerator.writeStringField(HDR_CONTENT_TYPE, this.contentType);
        jsonGenerator.writeStringField(HDR_CONTENT_CHARSET, this.contentCharset);
        jsonGenerator.writeNumberField(HDR_CONTENT_LENGTH, this.contentLength);
        jsonGenerator.writeStringField(HDR_ETAG, this.etag);
        jsonGenerator.writeStringField(HDR_LAST_MODIFIED, this.lastModified);
        jsonGenerator.writeNumberField(HDR_CONVERSION_DURATION, this.conversionDuration);

        jsonGenerator.writeEndObject();

        // response headers
        if (!this.responseHeaders.isEmpty()) {
            outputNameAndValueArray(jsonGenerator, HDR_RESPONSE_HEADERS, this.responseHeaders);
        }

        // content metadata
        if (!this.contentMetadata.isEmpty()) {
            outputNameAndValueArray(jsonGenerator, HDR_CONTENT_METADATA, this.contentMetadata);
        }

        // text
        jsonGenerator.writeStringField(HDR_CONVERTED_TEXT, this.getText());
        jsonGenerator.writeEndObject();
        jsonGenerator.close();

        String result = destination.toString(UTF_8);
        return result;
    } catch (IOException e) {
        throw new Url2TextException("Error emitting JSON", e);
    }
}

From source file:com.streamsets.pipeline.stage.origin.jdbc.table.BaseTableJdbcSourceIT.java

protected static String getStringRepOfFieldValueForInsert(Field field) {
    switch (field.getType()) {
    case BYTE_ARRAY:
        //Do a hex encode.
        return Hex.encodeHexString(field.getValueAsByteArray());
    case BYTE:/*from  w ww.  j  a v  a 2 s.  c  o m*/
        return String.valueOf(field.getValueAsInteger());
    case TIME:
        return DateFormatUtils.format(field.getValueAsDate(), "HH:mm:ss.SSS");
    case DATE:
        return DateFormatUtils.format(field.getValueAsDate(), "yyyy-MM-dd");
    case DATETIME:
        return DateFormatUtils.format(field.getValueAsDate(), "yyyy-MM-dd HH:mm:ss.SSS");
    case ZONED_DATETIME:
        return DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT
                .format(field.getValueAsZonedDateTime().toInstant().toEpochMilli());
    default:
        return String.valueOf(field.getValue());
    }
}

From source file:com.codealot.url2text.Response.java

/**
 * Full dump of the response content in plain text format.
 * <p>/*from  w  w w  . j  av a  2  s .c om*/
 * Beware. This method consumes the internal Reader, creating a buffer of
 * unlimited size.
 */
@Override
public String toString() {
    final StringBuilder buffer = new StringBuilder(350);

    buffer.append("################ TRANSACTION METADATA ################");
    buffer.append("\nRequest page     : ").append(this.requestPage);
    buffer.append("\nLanding page     : ").append(this.landingPage);
    buffer.append("\nStatus           : ").append(this.status).append(' ').append(this.statusMessage);
    buffer.append("\nFetch date       : ")
            .append(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(this.fetchDate));
    buffer.append("\nFetch duration   : ").append(this.fetchDuration).append(" ms");
    buffer.append("\nContent type     : ").append(this.contentType);
    buffer.append("\nContent charset  : ").append(this.contentCharset);
    buffer.append("\nContent length   : ").append(this.contentLength);
    buffer.append("\nEtag             : ").append(this.etag);
    buffer.append("\nLast Modified    : ").append(this.lastModified);
    buffer.append("\nConvert duration : ").append(this.conversionDuration).append(" ms\n\n");

    if (!responseHeaders.isEmpty()) {
        buffer.append("################ RESPONSE HEADERS ####################\n");
        for (final NameAndValue kvp : responseHeaders) {
            buffer.append(kvp.getName()).append(" = ").append(kvp.getValue()).append('\n');
        }
        buffer.append('\n');
    }

    if (!contentMetadata.isEmpty()) {
        buffer.append("################ CONTENT METADATA ####################\n");

        for (final NameAndValue kvp : contentMetadata) {
            buffer.append(kvp.getName()).append(" = ").append(kvp.getValue()).append('\n');
        }
        buffer.append('\n');
    }
    buffer.append("################ CONVERTED TEXT ######################\n");
    try {
        buffer.append(this.getText());
    } catch (Url2TextException e) {
        throw new RuntimeException(e);
    }
    buffer.append('\n');

    return buffer.toString();
}