List of usage examples for org.joda.time Instant parse
@FromString public static Instant parse(String str)
From source file:com.amediamanager.scheduled.ElasticTranscoderTasks.java
License:Apache License
protected void handleMessage(final Message message) { try {/* w ww .j a v a2s . co m*/ LOG.info("Handling message received from checkStatus"); ObjectNode snsMessage = (ObjectNode) mapper.readTree(message.getBody()); ObjectNode notification = (ObjectNode) mapper.readTree(snsMessage.get("Message").asText()); String state = notification.get("state").asText(); String jobId = notification.get("jobId").asText(); String pipelineId = notification.get("pipelineId").asText(); Video video = videoService.findByTranscodeJobId(jobId); if (video == null) { LOG.warn("Unable to process result for job {} because it does not exist.", jobId); Instant msgTime = Instant.parse(snsMessage.get("Timestamp").asText()); if (Minutes.minutesBetween(msgTime, new Instant()).getMinutes() > 20) { LOG.error("Job {} has not been found for over 20 minutes, deleting message from queue", jobId); deleteMessage(message); } // Leave it on the queue for now. return; } if ("ERROR".equals(state)) { LOG.warn("Job {} for pipeline {} failed to complete. Body: \n{}", jobId, pipelineId, notification.get("messageDetails").asText()); video.setThumbnailKey(videoService.getDefaultVideoPosterKey()); videoService.save(video); } else { // Construct our url prefix: https://bucketname.s3.amazonaws.com/output/key/ String prefix = notification.get("outputKeyPrefix").asText(); if (!prefix.endsWith("/")) { prefix += "/"; } ObjectNode output = ((ObjectNode) ((ArrayNode) notification.get("outputs")).get(0)); String previewFilename = prefix + output.get("key").asText(); String thumbnailFilename = prefix + output.get("thumbnailPattern").asText().replaceAll("\\{count\\}", "00002") + ".png"; video.setPreviewKey(previewFilename); video.setThumbnailKey(thumbnailFilename); videoService.save(video); } deleteMessage(message); } catch (JsonProcessingException e) { LOG.error("JSON exception handling notification: {}", message.getBody(), e); } catch (IOException e) { LOG.error("IOException handling notification: {}", message.getBody(), e); } }
From source file:com.arangodb.velocypack.module.joda.internal.util.JodaTimeUtil.java
License:Apache License
public static Instant parseInstant(final String source) { return Instant.parse(source); }
From source file:com.github.cassandra.jdbc.CassandraDataTypeConverters.java
License:Apache License
protected void init() { // use "null" instead of empty string to avoid "InvalidQueryException: Key may not be empty" addMapping(String.class, "null", new Function<Object, String>() { public String apply(Object input) { String result;/*from w ww. j a v a 2s. c o m*/ if (input instanceof Readable) { try { result = CharStreams.toString(((Readable) input)); } catch (IOException e) { throw new IllegalArgumentException("Failed to read from Readable " + input, e); } } else { result = String.valueOf(input); } return result; } }); addMapping(java.util.UUID.class, java.util.UUID.randomUUID(), new Function<Object, UUID>() { public UUID apply(Object input) { return java.util.UUID.fromString(String.valueOf(input)); } }); InetAddress defaultAddress = null; try { defaultAddress = InetAddress.getLocalHost(); } catch (UnknownHostException e) { Logger.warn(e, "Failed to get local host"); } addMapping(InetAddress.class, defaultAddress, new Function<Object, InetAddress>() { public InetAddress apply(Object input) { try { return InetAddress.getByName(String.valueOf(input)); } catch (UnknownHostException e) { throw CassandraErrors.unexpectedException(e); } } }); addMapping(Blob.class, new CassandraBlob(new byte[0]), new Function<Object, Blob>() { public Blob apply(Object input) { CassandraBlob blob; if (input instanceof ByteBuffer) { blob = new CassandraBlob((ByteBuffer) input); } else if (input instanceof byte[]) { blob = new CassandraBlob((byte[]) input); } else if (input instanceof InputStream) { try { blob = new CassandraBlob(ByteStreams.toByteArray((InputStream) input)); } catch (IOException e) { throw new IllegalArgumentException("Failed to read from input stream " + input, e); } } else { blob = new CassandraBlob(String.valueOf(input).getBytes()); } return blob; } }); addMapping(byte[].class, emptyByteArray, new Function<Object, byte[]>() { public byte[] apply(Object input) { byte[] result; if (input instanceof ByteBuffer) { result = ((ByteBuffer) input).array(); } else { result = String.valueOf(input).getBytes(); } return result; } }); /* addMapping(ByteBuffer.class, ByteBuffer.wrap(new byte[0]), new Function<Object, ByteBuffer>() { public ByteBuffer apply(Object input) { return ByteBuffer.wrap(input instanceof byte[] ? (byte[]) input : String.valueOf(input).getBytes()); } }); */ addMapping(Boolean.class, Boolean.FALSE, new Function<Object, Boolean>() { public Boolean apply(Object input) { return Boolean.valueOf(String.valueOf(input)); } }); addMapping(Byte.class, (byte) 0, new Function<Object, Byte>() { public Byte apply(Object input) { return input instanceof Number ? ((Number) input).byteValue() : Ints.tryParse(String.valueOf(input)).byteValue(); } }); addMapping(Short.class, (short) 0, new Function<Object, Short>() { public Short apply(Object input) { return input instanceof Number ? ((Number) input).shortValue() : Ints.tryParse(String.valueOf(input)).shortValue(); } }); addMapping(Integer.class, 0, new Function<Object, Integer>() { public Integer apply(Object input) { return input instanceof Number ? ((Number) input).intValue() : Ints.tryParse(String.valueOf(input)); } }); addMapping(Long.class, 0L, new Function<Object, Long>() { public Long apply(Object input) { return input instanceof Number ? ((Number) input).longValue() : Long.parseLong(String.valueOf(input)); } }); addMapping(Float.class, 0.0F, new Function<Object, Float>() { public Float apply(Object input) { return input instanceof Number ? ((Number) input).floatValue() : Doubles.tryParse(String.valueOf(input)).floatValue(); } }); addMapping(Double.class, 0.0D, new Function<Object, Double>() { public Double apply(Object input) { return input instanceof Number ? ((Number) input).doubleValue() : Doubles.tryParse(String.valueOf(input)); } }); addMapping(BigDecimal.class, BigDecimal.ZERO, new Function<Object, BigDecimal>() { public BigDecimal apply(Object input) { return new BigDecimal(String.valueOf(input)); } }); addMapping(BigInteger.class, BigInteger.ZERO, new Function<Object, BigInteger>() { public BigInteger apply(Object input) { return new BigInteger(String.valueOf(input)); } }); addMapping(Date.class, new Date(System.currentTimeMillis()), new Function<Object, Date>() { public Date apply(Object input) { Date result; if (input instanceof LocalDate) { result = new Date(((LocalDate) input).toDate().getTime()); } else if (input instanceof java.util.Date) { result = new Date(((java.util.Date) input).getTime()); } else { result = new Date(LocalDate.parse(String.valueOf(input)).toDate().getTime()); } return result; } }); addMapping(Time.class, new Time(System.currentTimeMillis()), new Function<Object, Time>() { public Time apply(Object input) { Time result; if (input instanceof LocalTime) { result = new Time(((LocalTime) input).toDateTimeToday().getMillis()); } else if (input instanceof java.util.Date) { result = new Time(((java.util.Date) input).getTime()); } else { result = new Time(LocalTime.parse(String.valueOf(input)).toDateTimeToday().getMillis()); } return result; } }); addMapping(Timestamp.class, new Timestamp(System.currentTimeMillis()), new Function<Object, Timestamp>() { public Timestamp apply(Object input) { Timestamp result; if (input instanceof Instant) { result = new Timestamp(((Instant) input).toDate().getTime()); } else if (input instanceof java.util.Date) { result = new Timestamp(((java.util.Date) input).getTime()); } else if (input instanceof Number) { result = new Timestamp(((Number) input).longValue()); } else { String dateTime = String.valueOf(input); if (dateTime.indexOf(' ') == 10 && dateTime.indexOf('Z') < 0) { StringBuilder builder = new StringBuilder(dateTime).append('Z'); builder.setCharAt(10, 'T'); dateTime = builder.toString(); } result = new Timestamp(Instant.parse(dateTime).toDate().getTime()); } return result; } }); // now collections addMapping(List.class, emptyList, new Function<Object, List>() { public List apply(Object input) { List result; if (input instanceof Iterable) { result = Lists.newArrayList((Iterable) input); } else if (input instanceof Object[]) { result = Lists.newArrayList((Object[]) input); } else { result = valueSplitter.splitToList(String.valueOf(input)); } return result; } }); addMapping(Set.class, emptySet, new Function<Object, Set>() { public Set apply(Object input) { Set result; if (input instanceof Iterable) { result = Sets.newTreeSet((Iterable) input); } else if (input instanceof Object[]) { result = Sets.newHashSet((Object[]) input); } else { result = Sets.newTreeSet(valueSplitter.splitToList(String.valueOf(input))); } return result; } }); addMapping(Set.class, emptyMap, new Function<Object, Map>() { public Map apply(Object input) { return Map.class.cast(input); } }); }
From source file:com.github.cassandra.jdbc.provider.datastax.codecs.StringTimestampCodec.java
License:Apache License
@Override public ByteBuffer serialize(String value, ProtocolVersion protocolVersion) { if (value == null) { return null; }// w ww . ja v a 2 s. c o m if (value.indexOf(' ') == 10 && value.indexOf('Z') < 0) { StringBuilder builder = new StringBuilder(value).append('Z'); builder.setCharAt(10, 'T'); value = builder.toString(); } return bigint().serializeNoBoxing(Instant.parse(value).getMillis(), protocolVersion); }
From source file:com.google.cloud.dataflow.examples.opinionanalysis.util.PartitionedTableRef.java
License:Apache License
/** * input - a tupel that contains the data element (TableRow), the window, the timestamp, and the pane */// ww w. java 2 s . c om @Override public TableDestination apply(ValueInSingleWindow<TableRow> input) { String partition; if (this.isTimeField) { String sTime = (String) input.getValue().get(this.fieldName); Instant time = Instant.parse(sTime); partition = time.toString(partitionFormatter); } else { partition = ((Integer) input.getValue().get(this.fieldName)).toString(); } TableReference reference = new TableReference(); reference.setProjectId(this.projectId); reference.setDatasetId(this.datasetId); reference.setTableId(this.partitionPrefix + partition); return new TableDestination(reference, null); }
From source file:com.google.cloud.training.dataanalyst.flights.PredictRealtime.java
License:Apache License
public static Instant toInstant(String date, String hourmin) { // e.g: 2015-01-01 and 0837 int hrmin = Integer.parseInt(hourmin); int hr = hrmin / 100; int min = hrmin % 100; return Instant.parse(date) // .plus(Duration.standardHours(hr)) // .plus(Duration.standardMinutes(min)); }
From source file:griffon.plugins.jodatime.editors.InstantPropertyEditor.java
License:Apache License
private void handleAsString(String str) { if (isBlank(str)) { super.setValueInternal(null); return;/* w w w . j a v a 2s . co m*/ } try { super.setValueInternal(parse(Long.parseLong(str))); return; } catch (NumberFormatException nfe) { // ignore } try { super.setValueInternal(Instant.parse(str)); } catch (IllegalArgumentException e) { throw illegalValue(str, Instant.class, e); } }
From source file:griffon.plugins.jodatime.editors.IntervalPropertyEditor.java
License:Apache License
private void handleAsString(String str) { if (isBlank(str)) { super.setValueInternal(null); return;//from ww w. j av a2 s .co m } try { super.setValueInternal(Instant.parse(str)); } catch (IllegalArgumentException e) { throw illegalValue(str, Interval.class, e); } }
From source file:griffon.plugins.jodatime.JodatimeExtension.java
License:Apache License
public static Instant toInstant(String string) { return Instant.parse(string); }
From source file:griffon.plugins.scaffolding.atoms.InstantValue.java
License:Apache License
@Override public void setValue(Object value) { if (value == null || value instanceof Instant) { super.setValue(value); } else if (value instanceof DateTime) { super.setValue(((DateTime) value).toInstant()); } else if (value instanceof DateMidnight) { super.setValue(((DateMidnight) value).toInstant()); } else if (value instanceof LocalDate) { super.setValue(new Instant(((LocalDate) value).toDate())); } else if (value instanceof LocalDateTime) { super.setValue(new Instant(((LocalDateTime) value).toDate())); } else if (value instanceof LocalTime) { super.setValue(((LocalTime) value).toDateTimeToday().toInstant()); } else if (value instanceof Calendar) { super.setValue(new Instant(value)); } else if (value instanceof Date) { super.setValue(new Instant(value)); } else if (value instanceof CharSequence) { super.setValue(Instant.parse(value.toString())); } else {/*from w w w . j a v a2 s. c o m*/ throw new IllegalArgumentException("Invalid value " + value); } }