List of usage examples for java.util Calendar setTimeZone
public void setTimeZone(TimeZone value)
From source file:com.haulmont.cuba.desktop.gui.components.DesktopDateField.java
protected Date constructDate() { final Date datePickerDate = datePicker.getDate(); if (datePickerDate == null) { return null; }//from w w w .jav a 2 s.c o m Calendar dateCalendar = Calendar.getInstance(userSession.getLocale()); if (timeZone != null) { dateCalendar.setTimeZone(timeZone); } dateCalendar.setTime(datePickerDate); if (timeField.getValue() == null) { dateCalendar.set(Calendar.HOUR_OF_DAY, 0); dateCalendar.set(Calendar.MINUTE, 0); dateCalendar.set(Calendar.SECOND, 0); } else { Calendar timeCalendar = Calendar.getInstance(userSession.getLocale()); timeCalendar.setTime(timeField.<Date>getValue()); dateCalendar.set(Calendar.HOUR_OF_DAY, timeCalendar.get(Calendar.HOUR_OF_DAY)); dateCalendar.set(Calendar.MINUTE, timeCalendar.get(Calendar.MINUTE)); dateCalendar.set(Calendar.SECOND, timeCalendar.get(Calendar.SECOND)); } //noinspection UnnecessaryLocalVariable return dateCalendar.getTime(); }
From source file:cn.com.incito.driver.fragments.infocenter.MyInfoFragment.java
private void initData() { locationCity = mShare.getString(Constants.LOCATION_CITY, "").split("")[0]; // // w w w . j ava2 s .c o m // initWeather();//???? // Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); cal.setTimeZone(TimeZone.getDefault()); // System.out.println(":"+sdf.format(cal.getTime())); mTime.setText(sdf.format(cal.getTime())); LunarUtil lunar = new LunarUtil(cal); mDate.setText(lunar.toString()); if (NetworkUtils.isNetworkAvaliable(getActivity())) { MyInfoCenterAPI myInfoCenterAPI = new MyInfoCenterAPI(GlobalModel.getInst().mLoginModel.getCarId(), locationCity); new WisdomCityHttpResponseHandler(myInfoCenterAPI, new APIFinishCallback() { @Override public void OnRemoteApiFinish(BasicResponse response) { if (response.status == BasicResponse.SUCCESS) { MyInfoCenterAPIResponse myInfoCenterAPIResponse = (MyInfoCenterAPIResponse) response; // initNotices(myInfoCenterAPIResponse.mNoticesList); // ? initTransport(myInfoCenterAPIResponse.mModelTransport); // ? initModelCar(myInfoCenterAPIResponse.mCar); // ? initGoods(myInfoCenterAPIResponse.mGoodsTotal); // ? initOrder(myInfoCenterAPIResponse.mMyOrdersTotal); // initAgentInfo(myInfoCenterAPIResponse.mAgentList); } else { } } }); WisdomCityRestClient.execute(myInfoCenterAPI); } else { Toast.makeText(getActivity(), R.string.errcode_network_unavailable, Toast.LENGTH_SHORT).show(); } }
From source file:ca.uhn.fhir.model.primitive.BaseDateTimeDt.java
@Override protected Date parse(String theValue) throws DataFormatException { Calendar cal = new GregorianCalendar(0, 0, 0); cal.setTimeZone(TimeZone.getDefault()); String value = theValue;/*from www.j a va 2s . co m*/ boolean fractionalSecondsSet = false; if (value.length() > 0 && (value.charAt(0) == ' ' || value.charAt(value.length() - 1) == ' ')) { value = value.trim(); } int length = value.length(); if (length == 0) { return null; } if (length < 4) { throwBadDateFormat(value); } TemporalPrecisionEnum precision = null; cal.set(Calendar.YEAR, parseInt(value, value.substring(0, 4), 0, 9999)); precision = TemporalPrecisionEnum.YEAR; if (length > 4) { validateCharAtIndexIs(value, 4, '-'); validateLengthIsAtLeast(value, 7); int monthVal = parseInt(value, value.substring(5, 7), 1, 12) - 1; cal.set(Calendar.MONTH, monthVal); precision = TemporalPrecisionEnum.MONTH; if (length > 7) { validateCharAtIndexIs(value, 7, '-'); validateLengthIsAtLeast(value, 10); cal.set(Calendar.DATE, 1); // for some reason getActualMaximum works incorrectly if date isn't set int actualMaximum = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum)); precision = TemporalPrecisionEnum.DAY; if (length > 10) { validateLengthIsAtLeast(value, 17); validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss int offsetIdx = getOffsetIndex(value); String time; if (offsetIdx == -1) { //throwBadDateFormat(theValue); // No offset - should this be an error? time = value.substring(11); } else { time = value.substring(11, offsetIdx); String offsetString = value.substring(offsetIdx); setTimeZone(value, offsetString); cal.setTimeZone(getTimeZone()); } int timeLength = time.length(); validateCharAtIndexIs(value, 13, ':'); cal.set(Calendar.HOUR_OF_DAY, parseInt(value, value.substring(11, 13), 0, 23)); cal.set(Calendar.MINUTE, parseInt(value, value.substring(14, 16), 0, 59)); precision = TemporalPrecisionEnum.MINUTE; if (timeLength > 5) { validateLengthIsAtLeast(value, 19); validateCharAtIndexIs(value, 16, ':'); // yyyy-mm-ddThh:mm:ss cal.set(Calendar.SECOND, parseInt(value, value.substring(17, 19), 0, 59)); precision = TemporalPrecisionEnum.SECOND; if (timeLength > 8) { validateCharAtIndexIs(value, 19, '.'); // yyyy-mm-ddThh:mm:ss.SSSS validateLengthIsAtLeast(value, 20); int endIndex = getOffsetIndex(value); if (endIndex == -1) { endIndex = value.length(); } int millis; String millisString; if (endIndex > 23) { myFractionalSeconds = value.substring(20, endIndex); fractionalSecondsSet = true; endIndex = 23; millisString = value.substring(20, endIndex); millis = parseInt(value, millisString, 0, 999); } else { millisString = value.substring(20, endIndex); millis = parseInt(value, millisString, 0, 999); myFractionalSeconds = millisString; fractionalSecondsSet = true; } if (millisString.length() == 1) { millis = millis * 100; } else if (millisString.length() == 2) { millis = millis * 10; } cal.set(Calendar.MILLISECOND, millis); precision = TemporalPrecisionEnum.MILLI; } } } } else { cal.set(Calendar.DATE, 1); } } else { cal.set(Calendar.DATE, 1); } if (fractionalSecondsSet == false) { myFractionalSeconds = ""; } setPrecision(precision); return cal.getTime(); }
From source file:com.knowbout.epg.processor.Parser.java
/** * Field # Field Name Min Max Field Description Field Example * 1 tf_station_num 1 10 Unique station ID number. 11259 * 2 tf_database_key[3] 12 12 Unique description identifier necessary to reference movies, shows, episodes, sports from description file. MV1234560000; SH0123450000 * 3 tf_air_date 8 8 Date the program airs based on a 12:00 AM start of day; yyyymmdd format. 19950721 * 4 tf_air_time 4 4 Time of day the program airs; hhmm military format. 0000 is midnight * 5 tf_duration 4 Calculated by subtracting the current program's air time from the subsequent program's air time; hhmm format. 0059 is fifty-nine minutes; 0125 is one hour and twenty five minutes * 6 tf_part_num 3 Designates which part, when a program is split into 2 or more viewings. 1 * 7 tf_num_of_parts 3 Designates when a program is split into 2 or more parts for viewing. 3 * 8 tf_cc 1 Closed Captioning: Spoken content of program is listed on screen for the hearing-impaired. Y or N * 9 tf_stereo 1 Value designates whether a show, episode, movie or sports event is being broadcast in stereo. Y or N * 10 tf_repeat 1 Designates a program which has aired previously. Y or N * 11 tf_live_tape_delay 5 Designates whether a sports event is being played live, same-day delay, or taped prior to the air date. Live * 12 tf_subtitled 1 Used for foreign movies and shows, if the audio is in a foreign language, the English translation appears on-screen. Y or N * 13 tf_premiere_finale 15 Designates a program's premiere or finale, if applicable. Season Premiere * 14 tf_joined_in_progress 1 Joined in progress identifies when a station begins airing a program after the official start time. Y or N * 15 tf_cable_in_the_classroom 1 Designates a show is available through the Cable in the Classroom program. Y or N * 16 tf_tv_rating 4 TV Parental Guidelines in text form. TV13 * 17 tf_sap 1 Designates whether the program is subject to Secondary Audio Program coding. Y or N * 18 tf_blackout 1 Designates whether the program is subject to blackout restrictions. Y or N * 19 tf_sex_rating 1 Indicates adult situations. Y or N * 20 tf_violence_rating 1 Indicates violent situations. Y or N * 21 tf_language_rating 1 Indicates strong language. Y or N * 22 tf_dialog_rating 1 Indicates strong dialogue. Y or N * 23 tf_fv_rating 1 Indicates fantasy violence. Y or N * 24 tf_enhanced 1 Designates enhanced program information. Y or N * 25 tf_three_d 1 Designates show is in 3-D. Y or N * 26 tf_letterbox 1 Designates program is a letterbox version. Y or N * 27 tf_hdtv 1 Designates whether a show is broadcast in High Definition TV. Y or N * 28 tf_dolby 5 Designates a program in Dolby or Dolby Digital. Dolby, DD * 29 tf_dvs 1 Designates a program with Descriptive Video Service. Y or N * 30 - 40 tf_user_data reserved/*ww w .ja va 2 s. com*/ * @param stream * @throws IOException */ private void parseSchedule(InputStream stream) throws IOException { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); //Even though we download it on the 27, the data is really from the 26 forward, so back //up one day as so not to have duplicate schedule entries. cal.add(Calendar.DATE, -1); log.debug("Deleting schedules after : " + cal.getTime()); int previousCount = Schedule.deleteAfter(cal.getTime()); log.debug("Deleted : " + previousCount + " schedules"); BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); String line = reader.readLine(); SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmm"); dateTimeFormat.setTimeZone(TimeZone.getTimeZone("GMT")); int count = 1; while (line != null) { // if (count++ % scheduleTransaction == 0) { // TransactionManager.commitTransaction(); // TransactionManager.beginTransaction(); // } String[] parts = line.split("\\|", -1); long stationId = Long.parseLong(parts[0]); Date airTime = null; try { airTime = dateTimeFormat.parse(parts[2] + parts[3]); } catch (ParseException e) { log.error("Error parsing airtime for :" + line); } Station station = Station.selectById(stationId); Program program = Program.selectById(parts[1]); if (station != null && airTime != null && program != null) { // Schedule schedule = Schedule.selectByTimeAndStation(airTime, stationId); // if (schedule != null) { // //There was a scheduled item already, so we should delete it // schedule.delete(); // } Schedule schedule = new Schedule(); // schedule.setId(station.getId()+":"+airTime); // schedule.setStation(station); schedule.setProgram(program); schedule.setAirTime(airTime); schedule.setLineupId("FOOBAR"); schedule.insert(); String duration = parts[4]; int durationInMinutes = 0; if (duration.length() == 4) { int hours = Integer.parseInt(duration.substring(0, 2)); int minutes = Integer.parseInt(duration.substring(2, 4)); durationInMinutes = hours * 60 + minutes; schedule.setDuration(durationInMinutes); } //End time is calculated, but we need it for searching Calendar calendar = Calendar.getInstance(); calendar.setTime(airTime); calendar.add(Calendar.MINUTE, durationInMinutes); schedule.setEndTime(calendar.getTime()); if (parts[5].length() > 0) { schedule.setPartNumber(Integer.parseInt(parts[5])); } if (parts[6].length() > 0) { schedule.setNumberOfParts(Integer.parseInt(parts[6])); } schedule.setCc(parts[7] == null ? false : parts[7].equalsIgnoreCase("Y")); schedule.setStereo(parts[8] == null ? false : parts[8].equalsIgnoreCase("Y")); //Repeat is gone, now has new // schedule.setRepeat(parts[9] == null ? false : parts[9].equalsIgnoreCase("Y")); schedule.setLiveTapeDelay(parts[10]); schedule.setSubtitled(parts[11] == null ? false : parts[11].equalsIgnoreCase("Y")); schedule.setPremiereFinale(parts[12]); schedule.setJoinedInProgress(parts[13] == null ? false : parts[13].equalsIgnoreCase("Y")); schedule.setCableInClassroom(parts[14] == null ? false : parts[14].equalsIgnoreCase("Y")); schedule.setTvRating(parts[15]); schedule.setSap(parts[16] == null ? false : parts[16].equalsIgnoreCase("Y")); //Blackout is gone // schedule.setBlackout(parts[17] == null ? false : parts[17].equalsIgnoreCase("Y")); schedule.setSexRating(parts[18] == null ? false : parts[18].equalsIgnoreCase("Y")); schedule.setViolenceRating(parts[19] == null ? false : parts[19].equalsIgnoreCase("Y")); schedule.setLanguageRating(parts[20] == null ? false : parts[20].equalsIgnoreCase("Y")); schedule.setDialogRating(parts[21] == null ? false : parts[21].equalsIgnoreCase("Y")); schedule.setFvRating(parts[22] == null ? false : parts[22].equalsIgnoreCase("Y")); schedule.setEnhanced(parts[23] == null ? false : parts[23].equalsIgnoreCase("Y")); schedule.setThreeD(parts[24] == null ? false : parts[24].equalsIgnoreCase("Y")); schedule.setLetterbox(parts[25] == null ? false : parts[25].equalsIgnoreCase("Y")); schedule.setHdtv(parts[26] == null ? false : parts[26].equalsIgnoreCase("Y")); schedule.setDolby(parts[27]); schedule.setDvs(parts[28] == null ? false : parts[28].equalsIgnoreCase("Y")); schedule.setNewEpisode(parts[30] == null ? false : parts[30].equalsIgnoreCase("New")); } line = reader.readLine(); } reader.close(); }
From source file:io.minio.MinioClientTest.java
@Test public void testGetObjectHeaders() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException { MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.setResponseCode(200);/* ww w . j a v a2s . co m*/ response.setHeader("Date", "Sun, 05 Jun 2015 22:01:10 GMT"); response.setHeader(CONTENT_LENGTH, "5080"); response.setHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM); response.setHeader("ETag", "\"a670520d9d36833b3e28d1e4b73cbe22\""); response.setHeader(LAST_MODIFIED, MON_04_MAY_2015_07_58_51_GMT); server.enqueue(response); server.start(); // build expected request Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("GMT")); expectedDate.set(2015, Calendar.MAY, 4, 7, 58, 51); ObjectStat expectedStatInfo = new ObjectStat(BUCKET, "key", expectedDate.getTime(), 5080, "a670520d9d36833b3e28d1e4b73cbe22", APPLICATION_OCTET_STREAM); // get request MinioClient client = new MinioClient(server.url("")); ObjectStat objectStatInfo = client.statObject(BUCKET, "key"); assertEquals(expectedStatInfo, objectStatInfo); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java
@Test public void testParseLongShort() throws ParseException { final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US); cal.clear();/*from w w w . j av a 2 s. c om*/ cal.set(2003, Calendar.FEBRUARY, 10, 15, 33, 20); cal.set(Calendar.MILLISECOND, 989); cal.setTimeZone(NEW_YORK); DateParser fdf = getInstance("yyyy GGGG MMMM dddd aaaa EEEE HHHH mmmm ssss SSSS ZZZZ", NEW_YORK, Locale.US); assertEquals(cal.getTime(), fdf.parse("2003 AD February 0010 PM Monday 0015 0033 0020 0989 GMT-05:00")); cal.set(Calendar.ERA, GregorianCalendar.BC); final Date parse = fdf.parse("2003 BC February 0010 PM Saturday 0015 0033 0020 0989 GMT-05:00"); assertEquals(cal.getTime(), parse); fdf = getInstance("y G M d a E H m s S Z", NEW_YORK, Locale.US); assertEquals(cal.getTime(), fdf.parse("03 BC 2 10 PM Sat 15 33 20 989 -0500")); cal.set(Calendar.ERA, GregorianCalendar.AD); assertEquals(cal.getTime(), fdf.parse("03 AD 2 10 PM Saturday 15 33 20 989 -0500")); }
From source file:io.minio.MinioClientTest.java
@Test public void testSigningKey() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException { MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.addHeader("Date", SUN_29_JUN_2015_22_01_10_GMT); response.addHeader(CONTENT_LENGTH, "5080"); response.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM); response.addHeader("ETag", "\"a670520d9d36833b3e28d1e4b73cbe22\""); response.addHeader(LAST_MODIFIED, MON_04_MAY_2015_07_58_51_UTC); response.setResponseCode(200);/* ww w .ja v a2 s . c o m*/ server.enqueue(response); server.start(); // build expected request Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("UTC")); expectedDate.set(2015, Calendar.MAY, 4, 7, 58, 51); String contentType = APPLICATION_OCTET_STREAM; ObjectStat expectedStatInfo = new ObjectStat(BUCKET, "key", expectedDate.getTime(), 5080, "a670520d9d36833b3e28d1e4b73cbe22", contentType); // get request MinioClient client = new MinioClient(server.url(""), "foo", "bar"); ObjectStat objectStatInfo = client.statObject(BUCKET, "key"); assertEquals(expectedStatInfo, objectStatInfo); }
From source file:io.minio.MinioClientTest.java
@Test public void testListObjects() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException { final String body = "<ListBucketResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Name>bucket</Name><Prefix></Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><Delimiter></Delimiter><IsTruncated>false</IsTruncated><Contents><Key>key</Key><LastModified>2015-05-05T02:21:15.716Z</LastModified><ETag>\"5eb63bbbe01eeed093cb22bb8f5acdc3\"</ETag><Size>11</Size><StorageClass>STANDARD</StorageClass><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></Contents><Contents><Key>key2</Key><LastModified>2015-05-05T20:36:17.498Z</LastModified><ETag>\"2a60eaffa7a82804bdc682ce1df6c2d4\"</ETag><Size>1661</Size><StorageClass>STANDARD</StorageClass><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></Contents></ListBucketResult>"; MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.addHeader("Date", SUN_29_JUN_2015_22_01_10_GMT); response.addHeader(CONTENT_LENGTH, "414"); response.addHeader(CONTENT_TYPE, "application/xml"); response.setBody(new Buffer().writeUtf8(body)); response.setResponseCode(200);//from w w w . j ava2 s . c o m server.enqueue(response); server.start(); MinioClient client = new MinioClient(server.url("")); Iterator<Result<Item>> objectsInBucket = client.listObjects(BUCKET).iterator(); Item item = objectsInBucket.next().get(); assertEquals("key", item.objectName()); assertEquals(11, item.objectSize()); assertEquals("STANDARD", item.storageClass()); Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("UTC")); expectedDate.set(2015, Calendar.MAY, 5, 2, 21, 15); expectedDate.set(Calendar.MILLISECOND, 716); assertEquals(expectedDate.getTime(), item.lastModified()); Owner owner = item.owner(); assertEquals("minio", owner.id()); assertEquals("minio", owner.displayName()); }
From source file:io.minio.MinioClientTest.java
@Test public void testListBuckets() throws NoSuchAlgorithmException, InvalidKeyException, IOException, XmlPullParserException, MinioException, ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); final String body = "<ListAllMyBucketsResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><Buckets><Bucket><Name>bucket</Name><CreationDate>2015-05-05T20:35:51.410Z</CreationDate></Bucket><Bucket><Name>foo</Name><CreationDate>2015-05-05T20:35:47.170Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>"; MockWebServer server = new MockWebServer(); MockResponse response = new MockResponse(); response.addHeader("Date", SUN_29_JUN_2015_22_01_10_GMT); response.addHeader(CONTENT_LENGTH, "351"); response.addHeader(CONTENT_TYPE, "application/xml"); response.setBody(new Buffer().writeUtf8(body)); response.setResponseCode(200);/*w w w .jav a 2s . c o m*/ server.enqueue(response); server.start(); MinioClient client = new MinioClient(server.url("")); Iterator<Bucket> buckets = client.listBuckets().iterator(); Bucket bucket = buckets.next(); assertEquals(BUCKET, bucket.name()); assertEquals(dateFormat.parse("2015-05-05T20:35:51.410Z"), bucket.creationDate()); bucket = buckets.next(); assertEquals("foo", bucket.name()); assertEquals(dateFormat.parse("2015-05-05T20:35:47.170Z"), bucket.creationDate()); Calendar expectedDate = Calendar.getInstance(); expectedDate.clear(); expectedDate.setTimeZone(TimeZone.getTimeZone("UTC")); expectedDate.set(2015, Calendar.MAY, 5, 20, 35, 47); expectedDate.set(Calendar.MILLISECOND, 170); assertEquals(expectedDate.getTime(), bucket.creationDate()); }
From source file:org.apache.hadoop.fs.azure.BlockBlobAppendStream.java
/** * Helper method to updated the Blob metadata during Append lease operations. * Blob metadata is updated to holdLease value only if the current lease * status is equal to testCondition and the last update on the blob metadata * is less that 30 secs old.//w w w. j a v a 2 s.co m * @param holdLease * @param testCondition * @return true if the updated lease operation was successful or false otherwise * @throws StorageException */ private boolean updateBlobAppendMetadata(boolean holdLease, boolean testCondition) throws StorageException { SelfRenewingLease lease = null; StorageException lastStorageException = null; int leaseRenewalRetryCount = 0; /* * Updating the Blob metadata honours following algorithm based on * 1) If the append lease metadata is present * 2) Last updated time of the append lease * 3) Previous value of the Append lease metadata. * * The algorithm: * 1) If append lease metadata is not part of the Blob. In this case * this is the first client to Append so we update the metadata. * 2) If append lease metadata is present and timeout has occurred. * In this case irrespective of what the value of the append lease is we update the metadata. * 3) If append lease metadata is present and is equal to testCondition value (passed as parameter) * and timeout has not occurred, we update the metadata. * 4) If append lease metadata is present and is not equal to testCondition value (passed as parameter) * and timeout has not occurred, we do not update metadata and return false. * */ while (leaseRenewalRetryCount < MAX_LEASE_RENEWAL_RETRY_COUNT) { lastStorageException = null; synchronized (this) { try { final Calendar currentCalendar = Calendar.getInstance(Locale.US); currentCalendar.setTimeZone(TimeZone.getTimeZone(UTC_STR)); long currentTime = currentCalendar.getTime().getTime(); // Acquire lease on the blob. lease = new SelfRenewingLease(blob); blob.downloadAttributes(opContext); HashMap<String, String> metadata = blob.getMetadata(); if (metadata.containsKey(APPEND_LEASE) && currentTime - Long.parseLong(metadata .get(APPEND_LEASE_LAST_MODIFIED)) <= BlockBlobAppendStream.APPEND_LEASE_TIMEOUT && !metadata.get(APPEND_LEASE).equals(Boolean.toString(testCondition))) { return false; } metadata.put(APPEND_LEASE, Boolean.toString(holdLease)); metadata.put(APPEND_LEASE_LAST_MODIFIED, Long.toString(currentTime)); blob.setMetadata(metadata); AccessCondition accessCondition = new AccessCondition(); accessCondition.setLeaseID(lease.getLeaseID()); blob.uploadMetadata(accessCondition, null, opContext); return true; } catch (StorageException ex) { lastStorageException = ex; LOG.debug("Lease renewal for Blob : {} encountered Storage Exception : {} " + "Error Code : {}", key, ex, ex.getErrorCode()); leaseRenewalRetryCount++; } finally { if (lease != null) { try { lease.free(); } catch (StorageException ex) { LOG.debug("Encountered Storage exception while releasing lease for Blob {} " + "during Append metadata operation. Storage Exception {} " + "Error Code : {} ", key, ex, ex.getErrorCode()); } finally { lease = null; } } } } if (leaseRenewalRetryCount == MAX_LEASE_RENEWAL_RETRY_COUNT) { throw lastStorageException; } else { try { Thread.sleep(LEASE_RENEWAL_RETRY_SLEEP_PERIOD); } catch (InterruptedException ex) { LOG.debug("Blob append metadata updated method interrupted"); Thread.currentThread().interrupt(); } } } // The code should not enter here because the while loop will // always be executed and if the while loop is executed we // would returning from the while loop. return false; }