Example usage for org.joda.time DateTime getMillis

List of usage examples for org.joda.time DateTime getMillis

Introduction

In this page you can find the example usage for org.joda.time DateTime getMillis.

Prototype

public long getMillis() 

Source Link

Document

Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.

Usage

From source file:com.mastfrog.tinymavenproxy.FileFinder.java

License:Open Source License

public synchronized File put(final Path path, final File file, final DateTime lastModified) throws IOException {
    if (file.length() == 0) {
        return file;
    }//from w  w  w.  j ava2 s.  co  m
    final File target = new File(config.dir, path.toString().replace('/', File.separatorChar));
    if (!target.getParentFile().exists() && !target.getParentFile().mkdirs()) {
        throw new IOException("Could not create dirs " + target.getParent());
    }
    if (!file.renameTo(target)) {
        throw new IOException("Could not rename " + file + " to " + target);
    }
    if (lastModified != null) {
        target.setLastModified(lastModified.getMillis());
    }
    return target;
}

From source file:com.mastfrog.tinymavenproxy.FileFinder.java

License:Open Source License

public synchronized void put(final Path path, final ByteBuf content, final DateTime lastModified) {
    // This method is currently unused, but if we enhance the server to accept
    // uploads, we will likely need code a lot like this
    if (content.readableBytes() == 0) {
        return;// w  ww  .j  av  a 2s.c om
    }
    final ByteBuf buf = content.duplicate();
    threadPool.submit(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            final File target = new File(config.dir, path.toString().replace('/', File.separatorChar));
            buf.retain();
            if (!target.exists()) {
                if (!target.getParentFile().exists()) {
                    if (!target.getParentFile().mkdirs()) {
                        throw new IOException("Could not create " + target.getParentFile());
                    }
                }
                if (!target.createNewFile()) {
                    throw new IOException("Could not create " + target);
                }
            }
            try (ByteBufInputStream in = new ByteBufInputStream(buf)) {
                try (OutputStream out = new BufferedOutputStream(new FileOutputStream(target))) {
                    Streams.copy(in, out, 1024);
                }
            } catch (IOException ioe) {
                if (target.exists()) {
                    target.delete();
                }
                throw ioe;
            } finally {
                buf.release();
            }
            threadPool.submit(new Runnable() {

                @Override
                public void run() {
                    if (lastModified != null) {
                        target.setLastModified(lastModified.getMillis());
                    }
                }
            });
            return null;
        }
    });
}

From source file:com.messagemedia.restapi.client.v1.messaging.deliveryreports.DeliveryReport.java

License:Apache License

private DateTime validatedDateReceived(DateTime dateReceived) {
    if (dateReceived == null) {
        throw new IllegalArgumentException("Property 'date_received' cannot be null.");
    }/* ww  w.ja v  a2s.c  o  m*/
    return new DateTime(dateReceived.getMillis(), DateTimeZone.UTC);
}

From source file:com.messagemedia.restapi.client.v1.messaging.messages.Message.java

License:Apache License

Message(String callbackUrl, String content, Boolean deliveryReport, String destinationNumber,
        MessageFormat format, DateTime scheduled, String sourceNumber, AddressType sourceNumberType,
        DateTime messageExpiryTimestamp, Map<String, String> metadata) {

    this.content = validatedContent(content);
    this.destinationNumber = validatedDestinationNumber(destinationNumber);

    this.callbackUrl = callbackUrl;
    this.deliveryReport = deliveryReport == null ? false : deliveryReport;
    this.format = format == null ? MessageFormat.SMS : format;
    this.messageId = null;
    this.scheduled = scheduled == null ? null : new DateTime(scheduled.getMillis(), DateTimeZone.UTC);
    this.sourceNumber = sourceNumber;
    this.status = null;
    this.statusReason = null;
    this.messageExpiryTimestamp = messageExpiryTimestamp == null ? null
            : new DateTime(messageExpiryTimestamp.getMillis(), DateTimeZone.UTC);
    this.metadata = Collections
            .unmodifiableMap(metadata != null ? metadata : Collections.<String, String>emptyMap());
    this.sourceNumberType = sourceNumberType;
}

From source file:com.messagemedia.restapi.client.v1.messaging.messages.Message.java

License:Apache License

@JsonCreator
Message(@JsonProperty(value = "callback_url", required = false) String callbackUrl,
        @JsonProperty(value = "content") String content,
        @JsonProperty(value = "delivery_report", required = false) Boolean deliveryReport,
        @JsonProperty(value = "destination_number") String destinationNumber,
        @JsonProperty(value = "format", required = false) MessageFormat format,
        @JsonProperty(value = "message_id") String messageId,
        @JsonProperty(value = "scheduled", required = false) DateTime scheduled,
        @JsonProperty(value = "source_number", required = false) String sourceNumber,
        @JsonProperty(value = "source_number_type", required = false) AddressType sourceNumberType,
        @JsonProperty(value = "status") MessageStatus status,
        @JsonProperty(value = "status_reason", required = false) String statusReason,
        @JsonProperty(value = "message_expiry_timestamp") DateTime messageExpiryTimestamp,
        @JsonProperty(value = "metadata") Map<String, String> metadata) {

    this.content = validatedContent(content);
    this.destinationNumber = validatedDestinationNumber(destinationNumber);

    // When de-serialising a message from JSON format, the message must
    // have a message ID
    this.messageId = validatedMessageId(messageId);

    // When de-serialising a message from JSON format, the message must
    // have a status
    this.status = validatedStatus(status);

    this.callbackUrl = callbackUrl;
    this.deliveryReport = deliveryReport == null ? false : deliveryReport;
    this.format = format == null ? MessageFormat.SMS : format;
    this.scheduled = scheduled == null ? null : new DateTime(scheduled.getMillis(), DateTimeZone.UTC);
    this.sourceNumber = sourceNumber;
    this.sourceNumberType = sourceNumberType;
    this.statusReason = statusReason;
    this.messageExpiryTimestamp = messageExpiryTimestamp == null ? null
            : new DateTime(messageExpiryTimestamp.getMillis(), DateTimeZone.UTC);
    this.metadata = Collections
            .unmodifiableMap(metadata != null ? metadata : Collections.<String, String>emptyMap());
}

From source file:com.metalware.rubric.core.dto.Document.java

License:Open Source License

/**
 * Sets a value within the document.//from   w  w w  . j a  va 2 s  .  co  m
 * @param key The key of the value to set. The argument is converted to a string.
 * @param value The value to assign.
 * @return A reference to this instance.
 */
public Document setDateTime(Object key, DateTime value) {
    setLong(key, value.getMillis());
    return this;
}

From source file:com.metamx.druid.DurationGranularity.java

License:Open Source License

@JsonCreator
public DurationGranularity(@JsonProperty("duration") long duration, @JsonProperty("origin") DateTime origin) {
    this(duration, origin == null ? 0 : origin.getMillis());
}

From source file:com.metamx.druid.index.v1.IndexStorageAdapter.java

License:Open Source License

private Pair<Integer, Integer> computeTimeStartEnd(Interval interval) {
    DateTime actualIntervalStart = index.dataInterval.getStart();
    DateTime actualIntervalEnd = index.dataInterval.getEnd();

    if (index.dataInterval.contains(interval.getStart())) {
        actualIntervalStart = interval.getStart();
    }// w w  w.j  a  va  2 s.c  o  m

    if (index.dataInterval.contains(interval.getEnd())) {
        actualIntervalEnd = interval.getEnd();
    }

    return computeOffsets(actualIntervalStart.getMillis(), 0, actualIntervalEnd.getMillis(),
            index.timeOffsets.length);
}

From source file:com.metamx.druid.indexer.data.StringInputRowParser.java

License:Open Source License

public InputRow parse(String input) throws FormattedException {
    Map<String, Object> theMap = parser.parse(input);

    final List<String> dimensions = dataSpec.hasCustomDimensions() ? dataSpec.getDimensions()
            : Lists.newArrayList(Sets.difference(theMap.keySet(), dimensionExclusions));

    final DateTime timestamp = timestampSpec.extractTimestamp(theMap);
    if (timestamp == null) {
        throw new NullPointerException(String.format("Null timestamp in input string: %s",
                input.length() < 100 ? input : input.substring(0, 100) + "..."));
    }/*from   www. j  a v a  2s . c  om*/

    return new MapBasedInputRow(timestamp.getMillis(), dimensions, theMap);
}

From source file:com.metamx.druid.PeriodGranularity.java

License:Open Source License

@JsonCreator
public PeriodGranularity(@JsonProperty("period") Period period, @JsonProperty("origin") DateTime origin,
        @JsonProperty("timeZone") DateTimeZone tz) {
    this.period = period;
    this.chronology = tz == null ? ISOChronology.getInstanceUTC() : ISOChronology.getInstance(tz);
    if (origin == null) {
        // default to origin in given time zone when aligning multi-period granularities
        this.origin = new DateTime(0, DateTimeZone.UTC).withZoneRetainFields(chronology.getZone()).getMillis();
        this.hasOrigin = false;
    } else {/*  w  w  w.j a v  a2 s  .  co  m*/
        this.origin = origin.getMillis();
        this.hasOrigin = true;
    }
    this.isCompound = isCompoundPeriod(period);
}