Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (c) 2012, Francis Galiegue <>
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the Lesser GNU General Public License as
  * published by the Free Software Foundation, either version 3 of the
  * License, or (at your option) any later version.
  * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <>.
package com.github.fge.jsonschema.format.draftv3;
Validator for the utc-millisec format attribute.

As an extra step, this validator also ensures that the number in the instance is not negative, and does not overflow: Java's java.lang.System.currentTimeMillis() may return a long, but internally the return code is a signed 32-bit integer, therefore must not be greater than 2^31 - 1.

public final class UnixEpochFormatAttribute
    extends FormatAttribute
    private static final FormatAttribute INSTANCE
        = new UnixEpochFormatAttribute();

The maximum bit length of a Unix timestamp value
    private static final int EPOCH_BITLENGTH = 31;

    private static final BigInteger ONE_THOUSAND = new BigInteger("1000");
    private UnixEpochFormatAttribute()
    public static FormatAttribute getInstance()
        return ;
    public void checkValue(final String fmtfinal ValidationReport report,
        final JsonNode value)
        BigInteger epoch = value.bigIntegerValue();
        final Message.Builder msg;
        if (epoch.signum() == -1) {
            msg = newMsg(fmt).setMessage("epoch cannot be negative")
        epoch = epoch.divide();
        if (epoch.bitLength() > ) {
            msg = newMsg(fmt).setMessage("epoch time would overflow")
New to GrepCode? Check out our FAQ X