Example usage for java.util Date setTime

List of usage examples for java.util Date setTime

Introduction

In this page you can find the example usage for java.util Date setTime.

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.ScanManager.java

public void newPassiveGpsLocation() {
    if (mPassiveModeBatteryState == PassiveModeBatteryState.LOW) {
        return;//w  w  w. j a va  2  s .com
    }

    if (AppGlobals.isDebug) {
        ClientLog.d(LOG_TAG, "New passive location");
    }

    mWifiScanner.start(ActiveOrPassiveStumbling.PASSIVE_STUMBLING);
    mCellScanner.start(ActiveOrPassiveStumbling.PASSIVE_STUMBLING);

    // how often to flush a leftover bundle to the reports table
    // If there is a bundle, and nothing happens for 10sec, then flush it
    final int flushRate_ms = 10000;

    if (mPassiveModeFlushTimer != null) {
        mPassiveModeFlushTimer.cancel();
    }

    Date when = new Date();
    when.setTime(when.getTime() + flushRate_ms);
    mPassiveModeFlushTimer = new Timer();
    mPassiveModeFlushTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            Intent flush = new Intent(Reporter.ACTION_FLUSH_TO_BUNDLE);
            if (mAppContext == null) {
                return;
            }
            LocalBroadcastManager.getInstance(mAppContext).sendBroadcastSync(flush);
        }
    }, when);
}

From source file:org.nuxeo.sheridan.S3TempSignedURLBuilder.java

/**
 * Return an url as string. This url is a temporary signed url giving access to the object for
 * <code>expireInSeconds</expireInSeconds> seconds. After this time, the object cannot be accessed anymore with this URL.
 * <p>// w  w  w  . j  a  v  a  2s.  c om
 * Some default values apply:
 * <p>
 * <ul>
 * <li>If <code>bucket</code> is empty (null, "", " ", ....), the bucket defined in the configuration is used.</li>
 * <li>If <code>expireInSeconds</code> is less than 1, the default
 * <code>S3TempSignedURLBuilder.DEFAULT_EXPIRE</code> is used</li> <li><code>contentType</code> and
 * <code>contentDisposition</code> can be null or "", but it is recommended to set them to make sure the is no
 * ambiguity when the URL is used (a key without a file extension for example)</li> </ul>
 * <p>
 * 
 * @param bucket
 * @param objectKey
 * @param expireInSeconds
 * @param contentType
 * @param contentDisposition
 * @return the temporary signed Url
 * @throws IOException
 * @since 7.10
 */
public String build(String bucket, String objectKey, int expireInSeconds, String contentType,
        String contentDisposition) throws IOException {

    if (StringUtils.isBlank(bucket)) {
        bucket = awsBucket;
    }
    if (StringUtils.isBlank(bucket)) {
        throw new NuxeoException(
                "No bucket provided, and configuration key " + CONF_KEY_NAME_BUCKET + " is missing.");
    }

    Date expiration = new Date();
    if (expireInSeconds < 1) {
        expireInSeconds = DEFAULT_EXPIRE;
    }
    expiration.setTime(expiration.getTime() + (expireInSeconds * 1000));

    GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, objectKey, HttpMethod.GET);

    // Do we need these?
    if (StringUtils.isNotBlank(contentType)) {
        request.addRequestParameter("response-content-type", contentType);
    }
    if (StringUtils.isNotBlank(contentDisposition)) {
        request.addRequestParameter("response-content-disposition", contentDisposition);
    }

    request.setExpiration(expiration);
    URL url = s3.generatePresignedUrl(request);

    try {
        URI uri = url.toURI();
        return uri.toString();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }

}

From source file:org.lunci.dumbthing.account.LinkFacebook.java

@Override
public void unlink() {
    if (BuildConfig.DEBUG) {
        Log.i(TAG, "unlinkFacebook");
    }//from w w  w  .ja va 2s  .  c o m
    callUnlinkConfirmDialog(R.string.unlink_facebook_warning, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
            try {
                Session session = Session.getActiveSession();
                if (session == null) {
                    final String token = pref.getString(Keys.Preference_Facebook_AccessToken, "");
                    final long expire = pref.getLong(Keys.Preference_Facebook_AccessToken_Expire, 0);
                    final Date expDate = new Date();
                    expDate.setTime(expire);
                    final long lastRefresh = pref.getLong(Keys.Preference_Facebook_Last_Refresh_Date, 0);
                    final Date lastDate = new Date();
                    lastDate.setTime(lastRefresh);
                    final Set<String> permissions = pref.getStringSet(Keys.Preference_Facebook_Permissions,
                            null);
                    final List<String> permissionList = new ArrayList<>();
                    permissionList.addAll(permissions);
                    //  final Set<String> declinedPermissions=pref.getStringSet(Keys.Preference_Facebook_Declined_Permissions, null);
                    final String source = pref.getString(Keys.Preference_Facebook_AccessToken_Source, "");
                    final AccessTokenSource tokenSource = AccessTokenSource.valueOf(source);
                    final AccessToken accessToken = AccessToken.createFromExistingAccessToken(token, expDate,
                            lastDate, tokenSource, permissionList);
                    session = Session.openActiveSessionWithAccessToken(getActivity(), accessToken, null);
                }
                if (session != null)
                    session.closeAndClearTokenInformation();
                else {
                    Log.w(TAG, "Unable to retrieve session");
                }
            } catch (NullPointerException ex) {
                ex.printStackTrace();
            } finally {
                final SharedPreferences.Editor editor = pref.edit();
                editor.putBoolean(Keys.Preference_Facebook_Linked, false).commit();
                mButtonContainer.updateLinked(false);
            }
        }
    });
}

From source file:org.exoplatform.addons.codefest.team_c.controller.KittenSaverController.java

@Resource
@Ajax//from w  w  w . j  av a  2 s  .c o m
@MimeType.JSON
public Response addMeeting(String title, String description, String participants, String options,
        SecurityContext securityContext) throws JSONException {
    List<String> pars = new LinkedList<String>(Arrays.asList(participants.split(",")));
    List<Long> opts = new LinkedList<Long>();
    for (String opt : options.split(",")) {
        String[] time = opt.split("/");
        Date startDate = new Date();
        startDate.setTime(Long.parseLong(time[0]));
        Date endDate = new Date();
        endDate.setTime(Long.parseLong(time[1]));
        Option o = new Option(new LinkedList<Long>(), startDate, endDate);
        kittenSaverService.createOption(o);
        opts.add(o.getId());
    }

    User user = kittenSaverService.getUserByUsername(securityContext.getRemoteUser());
    Meeting meeting = new Meeting(title, description, user, Meeting.STATUS_OPENED, pars, opts, null);
    kittenSaverService.createMeeting(meeting);

    JSONObject json = new JSONObject();
    json.put("url", KittenSaverController_.index());
    return Response.ok(json.toString()).withCharset(Tools.UTF_8);
}

From source file:org.nuxeo.s3utils.S3HandlerImpl.java

@Override
public String buildPresignedUrl(String inBucket, String inKey, int durationInSeconds, String contentType,
        String contentDisposition) throws NuxeoException {

    if (StringUtils.isBlank(inBucket)) {
        inBucket = currentBucket;//from  w  w w.  j  a va  2  s  .c  om
    }
    if (StringUtils.isBlank(inBucket)) {
        throw new NuxeoException("No bucket provided");
    }

    if (durationInSeconds <= 0) {
        durationInSeconds = signedUrlDuration;
    }
    if (durationInSeconds <= 0) {
        throw new IllegalArgumentException("duration of " + durationInSeconds + " is invalid.");
    }

    Date expiration = new Date();
    expiration.setTime(expiration.getTime() + (durationInSeconds * 1000));

    GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(currentBucket, inKey, HttpMethod.GET);

    if (StringUtils.isNotBlank(contentType)) {
        request.addRequestParameter("response-content-type", contentType);
    }
    if (StringUtils.isNotBlank(contentDisposition)) {
        request.addRequestParameter("response-content-disposition", contentDisposition);
    }

    request.setExpiration(expiration);
    URL url = s3.generatePresignedUrl(request);

    try {
        URI uri = url.toURI();
        return uri.toString();
    } catch (URISyntaxException e) {
        throw new NuxeoException(e);
    }

}

From source file:org.webical.test.dao.impl.EventDaoWebDavHibernateBufferedImplTest.java

public void testUpdateConflict() {

    Calendar calendar = getCalendarForWebicalUser();

    Event event = getEvent(TestUtils.USERID_WEBICAL);
    event.setCalendar(calendar);/*from   w  w w. ja  v  a 2 s .  c o  m*/
    //Is there is a last mod date the synchronization expect the
    //event to occur in the ics. If the lastmod is before the found lastmod date
    // there is an updateconflict
    Date d = new Date();
    d.setTime(10000);
    event.setLastMod(d);
    event.setUid("uuid:1159123236869");
    try {
        eventDao.storeEvent(event);
        fail("No UpdateConflict found");
    } catch (DaoException e) {
        log.debug(e);
    }
}

From source file:org.silverpeas.components.resourcesmanager.model.Reservation.java

public Date getEndDate() {
    if (StringUtil.isLong(endDate)) {
        Date end = new Date();
        end.setTime(Long.parseLong(endDate));
        return end;
    }//from  w w  w . j  av  a 2 s  .c o  m
    return null;
}

From source file:org.silverpeas.components.resourcesmanager.model.Reservation.java

public Date getBeginDate() {
    if (StringUtil.isLong(beginDate)) {
        Date begin = new Date();
        begin.setTime(Long.parseLong(beginDate));
        return begin;
    }/*from   w  w  w.  j  a va 2  s .co m*/
    return null;
}

From source file:fr.cph.stock.android.entity.EntityBuilder.java

@SuppressLint("SimpleDateFormat")
private String extractDate(JSONObject jsonDate, String pattern) throws JSONException {
    BigInteger time = new BigInteger(jsonDate.getString("time"));
    Date date = new Date();
    date.setTime(time.longValue());
    DateFormat formatter = new SimpleDateFormat(pattern);
    String formattedDate = formatter.format(date);
    return formattedDate;
}

From source file:org.apache.synapse.mediators.deprecation.DeprecationMediator.java

private boolean isDeprecated(SynapseObject service) {

    try {//from   w  w w . j  a  va 2s  .c om
        if (service.getBoolean("enabled").booleanValue()) {
            Calendar current = Calendar.getInstance();
            TimeZone tz = current.getTimeZone();
            int offset = tz.getRawOffset();
            Calendar calendar = new GregorianCalendar(tz);

            DateFormat df = new SimpleDateFormat("d/M/y:H:m");
            df.setTimeZone(tz);
            Date d1 = service.getDate(DeprecationConstants.CFG_DEPRECATION_FROM_DATE);
            Calendar fromCalendar = new GregorianCalendar(tz);
            d1.setTime(d1.getTime() + offset);
            fromCalendar.setTime(d1);
            String toDate = service.getDate(DeprecationConstants.CFG_DEPRECATION_TO_DATE).toString();
            if (toDate == null || (toDate.length() == 0)) {
                return calendar.before(fromCalendar);
            }

            Date d2 = service.getDate("toDate");
            Calendar toCalendar = new GregorianCalendar(tz);
            d2.setTime(d2.getTime() + offset);
            toCalendar.setTime(d2);
            return (calendar.after(fromCalendar) && calendar.before(toCalendar));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return false;
}