Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

In this page you can find the example usage for java.util Calendar HOUR.

Prototype

int HOUR

To view the source code for java.util Calendar HOUR.

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:com.emc.atmos.api.test.AtmosApiClientTest.java

@Test
public void testGetShareableUrl() throws Exception {
    Assume.assumeFalse(isVipr);/*from   w w w.j ava 2 s.  c  o  m*/
    // Create an object with content.
    String str = "Four score and twenty years ago";
    ObjectId id = this.api.createObject(str.getBytes("UTF-8"), "text/plain");
    Assert.assertNotNull("null ID returned", id);
    cleanup.add(id);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, 4);
    Date expiration = c.getTime();
    URL u = api.getShareableUrl(id, expiration);

    l4j.debug("Sharable URL: " + u);

    InputStream stream = (InputStream) u.getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(stream));
    String content = br.readLine();
    l4j.debug("Content: " + content);
    Assert.assertEquals("URL does not contain proper content", str, content);
}

From source file:com.emc.atmos.api.test.AtmosApiClientTest.java

@Test
public void testGetShareableUrlWithPath() throws Exception {
    Assume.assumeFalse(isVipr);/*from w ww . jav a2 s. c  om*/
    // Create an object with content.
    String str = "Four score and twenty years ago";
    ObjectPath op = new ObjectPath("/" + rand8char() + ".txt");
    ObjectId id = this.api.createObject(op, str.getBytes("UTF-8"), "text/plain");
    Assert.assertNotNull("null ID returned", id);
    cleanup.add(op);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, 4);
    Date expiration = c.getTime();
    URL u = api.getShareableUrl(op, expiration);

    l4j.debug("Sharable URL: " + u);

    InputStream stream = (InputStream) u.getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(stream));
    String content = br.readLine();
    l4j.debug("Content: " + content);
    Assert.assertEquals("URL does not contain proper content", str, content);
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java

public static Calendar convertTimestampString(String val) {
    if ((val == null) || (val.length() == 0)) {
        return (null);
    } else if (val.length() != 19) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class,
                "convertTimestampString",
                "Value must be in YYYY-MM-DDTHH24:MI:SS format \"" + val + "\" is invalid");
    } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9'))
            && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9'))
            && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9'))
            && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-')
            && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1'))
            && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-')
            && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3'))
            && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9')) && (val.charAt(10) == 'T')
            && ((val.charAt(11) >= '0') && (val.charAt(11) <= '2'))
            && ((val.charAt(12) >= '0') && (val.charAt(12) <= '9')) && (val.charAt(13) == ':')
            && ((val.charAt(14) >= '0') && (val.charAt(14) <= '5'))
            && ((val.charAt(15) >= '0') && (val.charAt(15) <= '9')) && (val.charAt(16) == ':')
            && ((val.charAt(17) >= '0') && (val.charAt(17) <= '5'))
            && ((val.charAt(18) >= '0') && (val.charAt(18) <= '9'))) {
        /*//  w w w  .  j a va 2s  .  co m
         *   NOTE:
         *      .Net uses substring( startcol, lengthOfSubstring )
         *      Java uses substring( startcol, endcol ) and does not
         *         include charAt( endcol );
         */
        int year = Integer.parseInt(val.substring(0, 4));
        int month = Integer.parseInt(val.substring(5, 7));
        int day = Integer.parseInt(val.substring(8, 10));
        int hour = Integer.parseInt(val.substring(11, 13));
        int minute = Integer.parseInt(val.substring(14, 16));
        int second = Integer.parseInt(val.substring(17, 19));
        Calendar retval = new GregorianCalendar(getServerTimeZone());
        retval.set(Calendar.YEAR, year);
        retval.set(Calendar.MONTH, month - 1);
        retval.set(Calendar.DAY_OF_MONTH, day);
        retval.set(Calendar.HOUR, hour);
        retval.set(Calendar.MINUTE, minute);
        retval.set(Calendar.SECOND, second);
        retval.getTimeInMillis(); // Force update calculations
        return (retval);
    } else {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class,
                "convertTimestampString",
                "Value must be in YYYY-MM-DDTHH24:MI:SS format \"" + val + "\" is invalid");
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseSchema.java

public static Calendar convertTimeString(String val) {
    if ((val == null) || (val.length() == 0)) {
        return (null);
    } else if (val.length() != 8) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskSybaseSchema.class,
                "convertTimeString", "Value must be in HH24:MI:SS format, \"" + val + "\" is invalid");
    } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '2'))
            && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && (val.charAt(2) == ':')
            && ((val.charAt(3) >= '0') && (val.charAt(3) <= '5'))
            && ((val.charAt(4) >= '0') && (val.charAt(4) <= '9')) && (val.charAt(5) == ':')
            && ((val.charAt(6) >= '0') && (val.charAt(6) <= '5'))
            && ((val.charAt(7) >= '0') && (val.charAt(7) <= '9'))) {
        /*//from w  ww .j  ava2  s  .  c  om
         *   NOTE:
         *      .Net uses substring( startcol, lengthOfSubstring )
         *      Java uses substring( startcol, endcol ) and does not
         *         include charAt( endcol );
         */
        int hour = Integer.parseInt(val.substring(0, 2));
        int minute = Integer.parseInt(val.substring(3, 5));
        int second = Integer.parseInt(val.substring(6, 8));
        Calendar retval = new GregorianCalendar(getServerTimeZone());
        retval.set(Calendar.YEAR, 1);
        retval.set(Calendar.MONTH, 0);
        retval.set(Calendar.DAY_OF_MONTH, 1);
        retval.set(Calendar.HOUR, hour);
        retval.set(Calendar.MINUTE, minute);
        retval.set(Calendar.SECOND, second);
        retval.getTimeInMillis(); // Force update calculations
        return (retval);
    } else {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskSybaseSchema.class,
                "convertTimeString", "Value must be in HH24:MI:SS format \"" + val + "\" is invalid");
    }
}

From source file:com.emc.atmos.api.test.AtmosApiClientTest.java

@Test
public void testExpiredSharableUrl() throws Exception {
    Assume.assumeFalse(isVipr);//from  w  ww  . ja v  a 2  s .  c  o m
    // Create an object with content.
    String str = "Four score and twenty years ago";
    ObjectId id = this.api.createObject(str.getBytes("UTF-8"), "text/plain");
    Assert.assertNotNull("null ID returned", id);
    cleanup.add(id);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, -4);
    Date expiration = c.getTime();
    URL u = api.getShareableUrl(id, expiration);

    l4j.debug("Sharable URL: " + u);

    try {
        InputStream stream = (InputStream) u.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(stream));
        String content = br.readLine();
        l4j.debug("Content: " + content);
        Assert.fail("Request should have failed");
    } catch (Exception e) {
        l4j.debug("Error (expected): " + e);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java

public static Calendar convertTZDateString(String val) {
    if ((val == null) || (val.length() == 0)) {
        return (null);
    } else if (val.length() != 19) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class,
                "convertTZDateString",
                "Value must be in YYYY-MM-DDTHH24:MI:SS format \"" + val + "\" is invalid");
    } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9'))
            && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9'))
            && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9'))
            && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-')
            && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1'))
            && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-')
            && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3'))
            && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9')) && (val.charAt(10) == 'T')
            && ((val.charAt(11) >= '0') && (val.charAt(11) <= '2'))
            && ((val.charAt(12) >= '0') && (val.charAt(12) <= '9')) && (val.charAt(13) == ':')
            && ((val.charAt(14) >= '0') && (val.charAt(14) <= '5'))
            && ((val.charAt(15) >= '0') && (val.charAt(15) <= '9')) && (val.charAt(16) == ':')
            && ((val.charAt(17) >= '0') && (val.charAt(17) <= '5'))
            && ((val.charAt(18) >= '0') && (val.charAt(18) <= '9'))) {
        /*//from   www .  j a  v  a  2 s.  c o m
         *   NOTE:
         *      .Net uses substring( startcol, lengthOfSubstring )
         *      Java uses substring( startcol, endcol ) and does not
         *         include charAt( endcol );
         */
        int year = Integer.parseInt(val.substring(0, 4));
        int month = Integer.parseInt(val.substring(5, 7));
        int day = Integer.parseInt(val.substring(8, 10));
        int hour = Integer.parseInt(val.substring(11, 13));
        int minute = Integer.parseInt(val.substring(14, 16));
        int second = Integer.parseInt(val.substring(17, 19));
        Calendar retval = new GregorianCalendar(getServerTimeZone());
        retval.set(Calendar.YEAR, year);
        retval.set(Calendar.MONTH, month - 1);
        retval.set(Calendar.DAY_OF_MONTH, day);
        retval.set(Calendar.HOUR, hour);
        retval.set(Calendar.MINUTE, minute);
        retval.set(Calendar.SECOND, second);
        retval.getTimeInMillis(); // Force update calculations
        return (retval);
    } else {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAstSybaseSchema.class,
                "convertTZDateString",
                "Value must be in YYYY-MM-DDTHH24:MI:SS format \"" + val + "\" is invalid");
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseSchema.java

public static Calendar convertTimestampString(String val) {
    if ((val == null) || (val.length() == 0)) {
        return (null);
    } else if (val.length() != 19) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskSybaseSchema.class,
                "convertTimestampString",
                "Value must be in YYYY-MM-DDTHH24:MI:SS format \"" + val + "\" is invalid");
    } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9'))
            && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9'))
            && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9'))
            && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-')
            && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1'))
            && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-')
            && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3'))
            && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9')) && (val.charAt(10) == 'T')
            && ((val.charAt(11) >= '0') && (val.charAt(11) <= '2'))
            && ((val.charAt(12) >= '0') && (val.charAt(12) <= '9')) && (val.charAt(13) == ':')
            && ((val.charAt(14) >= '0') && (val.charAt(14) <= '5'))
            && ((val.charAt(15) >= '0') && (val.charAt(15) <= '9')) && (val.charAt(16) == ':')
            && ((val.charAt(17) >= '0') && (val.charAt(17) <= '5'))
            && ((val.charAt(18) >= '0') && (val.charAt(18) <= '9'))) {
        /*/*  ww w . j av a 2  s.co m*/
         *   NOTE:
         *      .Net uses substring( startcol, lengthOfSubstring )
         *      Java uses substring( startcol, endcol ) and does not
         *         include charAt( endcol );
         */
        int year = Integer.parseInt(val.substring(0, 4));
        int month = Integer.parseInt(val.substring(5, 7));
        int day = Integer.parseInt(val.substring(8, 10));
        int hour = Integer.parseInt(val.substring(11, 13));
        int minute = Integer.parseInt(val.substring(14, 16));
        int second = Integer.parseInt(val.substring(17, 19));
        Calendar retval = new GregorianCalendar(getServerTimeZone());
        retval.set(Calendar.YEAR, year);
        retval.set(Calendar.MONTH, month - 1);
        retval.set(Calendar.DAY_OF_MONTH, day);
        retval.set(Calendar.HOUR, hour);
        retval.set(Calendar.MINUTE, minute);
        retval.set(Calendar.SECOND, second);
        retval.getTimeInMillis(); // Force update calculations
        return (retval);
    } else {
        throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskSybaseSchema.class,
                "convertTimestampString",
                "Value must be in YYYY-MM-DDTHH24:MI:SS format \"" + val + "\" is invalid");
    }
}

From source file:com.emc.esu.test.EsuApiTest.java

@Test
public void testGetShareableUrl() throws Exception {
    Assume.assumeFalse(isVipr);//from www.  j a  va  2  s. c  o  m
    // Create an object with content.
    String str = "Four score and twenty years ago";
    ObjectId id = this.esu.createObject(null, null, str.getBytes("UTF-8"), "text/plain");
    Assert.assertNotNull("null ID returned", id);
    cleanup.add(id);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, 4);
    Date expiration = c.getTime();
    URL u = esu.getShareableUrl(id, expiration);

    l4j.debug("Sharable URL: " + u);

    InputStream stream = (InputStream) u.getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(stream));
    String content = br.readLine();
    l4j.debug("Content: " + content);
    Assert.assertEquals("URL does not contain proper content", str, content.toString());
}

From source file:com.emc.esu.test.EsuApiTest.java

@Test
public void testGetShareableUrlWithPath() throws Exception {
    Assume.assumeFalse(isVipr);/*from  w  ww. java  2s  .c  o  m*/
    // Create an object with content.
    String str = "Four score and twenty years ago";
    ObjectPath op = new ObjectPath("/" + rand8char() + ".txt");
    ObjectId id = this.esu.createObjectOnPath(op, null, null, str.getBytes("UTF-8"), "text/plain");
    Assert.assertNotNull("null ID returned", id);
    cleanup.add(op);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, 4);
    Date expiration = c.getTime();
    URL u = esu.getShareableUrl(op, expiration);

    l4j.debug("Sharable URL: " + u);

    InputStream stream = (InputStream) u.getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(stream));
    String content = br.readLine();
    l4j.debug("Content: " + content);
    Assert.assertEquals("URL does not contain proper content", str, content.toString());
}

From source file:com.emc.esu.test.EsuApiTest.java

@Test
public void testExpiredSharableUrl() throws Exception {
    Assume.assumeFalse(isVipr);/*from w  w  w.  ja  v a2 s.  c om*/
    // Create an object with content.
    String str = "Four score and twenty years ago";
    ObjectId id = this.esu.createObject(null, null, str.getBytes("UTF-8"), "text/plain");
    Assert.assertNotNull("null ID returned", id);
    cleanup.add(id);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, -4);
    Date expiration = c.getTime();
    URL u = esu.getShareableUrl(id, expiration);

    l4j.debug("Sharable URL: " + u);

    try {
        InputStream stream = (InputStream) u.getContent();
        BufferedReader br = new BufferedReader(new InputStreamReader(stream));
        String content = br.readLine();
        l4j.debug("Content: " + content);
        Assert.fail("Request should have failed");
    } catch (Exception e) {
        l4j.debug("Error (expected): " + e);
    }
}