Example usage for java.util GregorianCalendar add

List of usage examples for java.util GregorianCalendar add

Introduction

In this page you can find the example usage for java.util GregorianCalendar add.

Prototype

@Override
public void add(int field, int amount) 

Source Link

Document

Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount.java

private static String generateSAS(CloudBlobContainer container, boolean readonly) throws Exception {

    // Create a container if it does not exist.
    container.createIfNotExists();/*from w w  w . ja  v  a 2s.  com*/

    // Create a new shared access policy.
    SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy();

    // Create a UTC Gregorian calendar value.
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

    // Specify the current time as the start time for the shared access
    // signature.
    //
    calendar.setTime(new Date());
    sasPolicy.setSharedAccessStartTime(calendar.getTime());

    // Use the start time delta one hour as the end time for the shared
    // access signature.
    calendar.add(Calendar.HOUR, 10);
    sasPolicy.setSharedAccessExpiryTime(calendar.getTime());

    if (readonly) {
        // Set READ permissions
        sasPolicy
                .setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST));
    } else {
        // Set READ and WRITE permissions.
        //
        sasPolicy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE,
                SharedAccessBlobPermissions.LIST));
    }

    // Create the container permissions.
    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

    // Turn public access to the container off.
    containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF);

    container.uploadPermissions(containerPermissions);

    // Create a shared access signature for the container.
    String sas = container.generateSharedAccessSignature(sasPolicy, null);
    // HACK: when the just generated SAS is used straight away, we get an
    // authorization error intermittently. Sleeping for 1.5 seconds fixes that
    // on my box.
    Thread.sleep(1500);

    // Return to caller with the shared access signature.
    return sas;
}

From source file:org.xdi.oxauth.model.crypto.signature.RSAKeyFactory.java

public RSAKeyFactory(SignatureAlgorithm signatureAlgorithm, String dnName)
        throws InvalidParameterException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException,
        InvalidKeyException, CertificateEncodingException {
    if (signatureAlgorithm == null) {
        throw new InvalidParameterException("The signature algorithm cannot be null");
    }//  w  w w  .j  a  v a  2s  .c  om

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC");
    keyGen.initialize(2048, new SecureRandom());

    KeyPair keyPair = keyGen.generateKeyPair();

    JCERSAPrivateCrtKey jcersaPrivateCrtKey = (JCERSAPrivateCrtKey) keyPair.getPrivate();
    JCERSAPublicKey jcersaPublicKey = (JCERSAPublicKey) keyPair.getPublic();

    rsaPrivateKey = new RSAPrivateKey(jcersaPrivateCrtKey.getModulus(),
            jcersaPrivateCrtKey.getPrivateExponent());

    rsaPublicKey = new RSAPublicKey(jcersaPublicKey.getModulus(), jcersaPublicKey.getPublicExponent());

    if (StringUtils.isNotBlank(dnName)) {
        // Create certificate
        GregorianCalendar startDate = new GregorianCalendar(); // time from which certificate is valid
        GregorianCalendar expiryDate = new GregorianCalendar(); // time after which certificate is not valid
        expiryDate.add(Calendar.YEAR, 1);
        BigInteger serialNumber = new BigInteger(1024, new Random()); // serial number for certificate

        X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
        X500Principal principal = new X500Principal(dnName);

        certGen.setSerialNumber(serialNumber);
        certGen.setIssuerDN(principal);
        certGen.setNotBefore(startDate.getTime());
        certGen.setNotAfter(expiryDate.getTime());
        certGen.setSubjectDN(principal); // note: same as issuer
        certGen.setPublicKey(keyPair.getPublic());
        certGen.setSignatureAlgorithm(signatureAlgorithm.getAlgorithm());

        X509Certificate x509Certificate = certGen.generate(jcersaPrivateCrtKey, "BC");
        certificate = new Certificate(signatureAlgorithm, x509Certificate);
    }
}

From source file:org.chililog.server.workbench.workers.AuthenticationTokenAO.java

/**
 * Updates the expiry date of the token to the current time + number of expiry seconds.
 */// w  w w  . j a  v a  2 s .  co  m
public void updateExpiresOn() {
    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.SECOND, _expirySeconds);
    _expiresOn = cal.getTime();
}

From source file:op.tools.SYSCalendar.java

/**
 * Addiert (bzw. Subtrahiert) eine angebenene Anzahl von Tagen auf das (bzw. von dem)
 * bergebenen Datum und gibt es dann zurck.
 *
 * @param date    - Ausgangsdatum//from   w  ww  . ja va 2  s . co m
 * @param numDays - Anzahl der Tage die addiert bzw. subtrahiert werdenn sollen.
 * @return neues Datum
 */
public static Date addDate(Date date, int numDays) {
    GregorianCalendar gc = toGC(date);
    gc.add(GregorianCalendar.DATE, numDays);
    return new Date(gc.getTimeInMillis());
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar Aschermittwoch(int year) {
    GregorianCalendar gc = Ostersonntag(year);
    gc.add(GregorianCalendar.DAY_OF_MONTH, -46);
    return gc;/*from w  ww.  j a va 2 s  .  c o  m*/
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar Rosenmontag(int year) {
    GregorianCalendar gc = Ostersonntag(year);
    gc.add(GregorianCalendar.DAY_OF_MONTH, -48);
    return gc;/*from  w  w w  .j  a va 2 s.  co  m*/
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar Weiberfastnacht(int year) {
    GregorianCalendar gc = Ostersonntag(year);
    gc.add(GregorianCalendar.DAY_OF_MONTH, -52);
    return gc;/*from  www  .  j a  v a  2  s.c  o m*/
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar Ostermontag(int year) {
    GregorianCalendar gc = Ostersonntag(year);
    gc.add(GregorianCalendar.DAY_OF_MONTH, 1);
    return gc;//w  w  w.j  ava2  s . c o  m
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar Karfreitag(int year) {
    GregorianCalendar gc = Ostersonntag(year);
    gc.add(GregorianCalendar.DAY_OF_MONTH, -2);
    return gc;//w w w  .  j a  v a 2 s  .  co  m
}

From source file:op.tools.SYSCalendar.java

public static GregorianCalendar Pfingstsonntag(int year) {
    GregorianCalendar gc = Ostersonntag(year);
    gc.add(GregorianCalendar.DAY_OF_MONTH, 49);
    return gc;/*from  w w w  . jav  a 2 s .  co  m*/
}