当前位置: 首页>>代码示例>>Java>>正文


Java Optional.of方法代码示例

本文整理汇总了Java中org.whispersystems.libsignal.util.guava.Optional.of方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.of方法的具体用法?Java Optional.of怎么用?Java Optional.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.whispersystems.libsignal.util.guava.Optional的用法示例。


在下文中一共展示了Optional.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNotification

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public Optional<Pair<NotificationInd, Integer>> getNotification(long messageId) {
  Cursor cursor = null;

  try {
    cursor = rawQuery(RAW_ID_WHERE, new String[] {String.valueOf(messageId)});

    if (cursor != null && cursor.moveToNext()) {
      PduHeaders        headers = new PduHeaders();
      PduHeadersBuilder builder = new PduHeadersBuilder(headers, cursor);
      builder.addText(CONTENT_LOCATION, PduHeaders.CONTENT_LOCATION);
      builder.addLong(NORMALIZED_DATE_SENT, PduHeaders.DATE);
      builder.addLong(EXPIRY, PduHeaders.EXPIRY);
      builder.addLong(MESSAGE_SIZE, PduHeaders.MESSAGE_SIZE);
      builder.addText(TRANSACTION_ID, PduHeaders.TRANSACTION_ID);

      return Optional.of(new Pair<>(new NotificationInd(headers),
                                    cursor.getInt(cursor.getColumnIndexOrThrow(SUBSCRIPTION_ID))));
    } else {
      return Optional.absent();
    }
  } finally {
    if (cursor != null)
      cursor.close();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:26,代码来源:MmsDatabase.java

示例2: onRun

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@Override
public void onRun() throws NoSuchMessageException {

  if (!IdentityKeyUtil.hasIdentityKey(context)) {
    Log.w(TAG, "Skipping job, waiting for migration...");
    return;
  }

  MasterSecret          masterSecret         = KeyCachingService.getMasterSecret(context);
  PushDatabase          database             = DatabaseFactory.getPushDatabase(context);
  SignalServiceEnvelope envelope             = database.get(messageId);
  Optional<Long>        optionalSmsMessageId = smsMessageId > 0 ? Optional.of(smsMessageId) :
                                                               Optional.<Long>absent();

  MasterSecretUnion masterSecretUnion;

  if (masterSecret == null) masterSecretUnion = new MasterSecretUnion(MasterSecretUtil.getAsymmetricMasterSecret(context, null));
  else                      masterSecretUnion = new MasterSecretUnion(masterSecret);

  handleMessage(masterSecretUnion, envelope, optionalSmsMessageId);
  database.delete(messageId);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:23,代码来源:PushDecryptJob.java

示例3: getSignedPreKeyIndex

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private static synchronized Optional<SignedPreKeyIndex> getSignedPreKeyIndex(Context context) {
  File indexFile = new File(getSignedPreKeysDirectory(context), SignedPreKeyIndex.FILE_NAME);

  if (!indexFile.exists()) {
    return Optional.absent();
  }

  try {
    InputStreamReader reader = new InputStreamReader(new FileInputStream(indexFile));
    SignedPreKeyIndex index  = JsonUtils.fromJson(reader, SignedPreKeyIndex.class);
    reader.close();

    return Optional.of(index);
  } catch (IOException e) {
    Log.w(TAG, e);
    return Optional.absent();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:19,代码来源:PreKeyUtil.java

示例4: find

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<Long> find(SignalServiceEnvelope envelope) {
  SQLiteDatabase database = databaseHelper.getReadableDatabase();
  Cursor         cursor   = null;

  try {
    cursor = database.query(TABLE_NAME, null, TYPE + " = ? AND " + SOURCE + " = ? AND " +
                                              DEVICE_ID + " = ? AND " + LEGACY_MSG + " = ? AND " +
                                              CONTENT + " = ? AND " + TIMESTAMP + " = ?" ,
                            new String[] {String.valueOf(envelope.getType()),
                                          envelope.getSource(),
                                          String.valueOf(envelope.getSourceDevice()),
                                          envelope.hasLegacyMessage() ? Base64.encodeBytes(envelope.getLegacyMessage()) : "",
                                          envelope.hasContent() ? Base64.encodeBytes(envelope.getContent()) : "",
                                          String.valueOf(envelope.getTimestamp())},
                            null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
      return Optional.of(cursor.getLong(cursor.getColumnIndexOrThrow(ID)));
    } else {
      return Optional.absent();
    }
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:26,代码来源:PushDatabase.java

示例5: onRun

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@Override
public void onRun() throws NoSuchMessageException {

  if (!IdentityKeyUtil.hasIdentityKey(context)) {
    Log.w(TAG, "Skipping job, waiting for migration...");
    MessageNotifier.updateNotification(context, null, true, -2);
    return;
  }

  MasterSecret          masterSecret         = KeyCachingService.getMasterSecret(context);
  PushDatabase          database             = DatabaseFactory.getPushDatabase(context);
  SignalServiceEnvelope envelope             = database.get(messageId);
  Optional<Long>        optionalSmsMessageId = smsMessageId > 0 ? Optional.of(smsMessageId) :
                                                               Optional.<Long>absent();

  MasterSecretUnion masterSecretUnion;

  if (masterSecret == null) masterSecretUnion = new MasterSecretUnion(MasterSecretUtil.getAsymmetricMasterSecret(context, null));
  else                      masterSecretUnion = new MasterSecretUnion(masterSecret);

  handleMessage(masterSecretUnion, envelope, optionalSmsMessageId);
  database.delete(messageId);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:24,代码来源:PushDecryptJob.java

示例6: forHangup

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public static SignalServiceCallMessage forHangup(HangupMessage hangupMessage) {
  return new SignalServiceCallMessage(Optional.<OfferMessage>absent(),
                                      Optional.<AnswerMessage>absent(),
                                      Optional.<List<IceUpdateMessage>>absent(),
                                      Optional.of(hangupMessage),
                                      Optional.<BusyMessage>absent());
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:8,代码来源:SignalServiceCallMessage.java

示例7: createContactAvatarAttachment

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<SignalServiceAttachmentStream> createContactAvatarAttachment(String number) throws IOException {
    File file = getContactAvatarFile(number);
    if (!file.exists()) {
        return Optional.absent();
    }

    return Optional.of(createAttachment(file));
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:9,代码来源:Manager.java

示例8: forIceUpdate

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public static SignalServiceCallMessage forIceUpdate(final IceUpdateMessage iceUpdateMessage) {
  List<IceUpdateMessage> iceUpdateMessages = new LinkedList<>();
  iceUpdateMessages.add(iceUpdateMessage);

  return new SignalServiceCallMessage(Optional.<OfferMessage>absent(),
                                      Optional.<AnswerMessage>absent(),
                                      Optional.of(iceUpdateMessages),
                                      Optional.<HangupMessage>absent(),
                                      Optional.<BusyMessage>absent());
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:11,代码来源:SignalServiceCallMessage.java

示例9: getAvatar

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<SignalServiceAttachmentStream> getAvatar(@Nullable byte[] avatar) {
  if (avatar == null) return Optional.absent();

  return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                            .withStream(new ByteArrayInputStream(avatar))
                                            .withContentType("image/*")
                                            .withLength(avatar.length)
                                            .build());
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:10,代码来源:MultiDeviceGroupUpdateJob.java

示例10: forBlocked

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public static SignalServiceSyncMessage forBlocked(BlockedListMessage blocked) {
  return new SignalServiceSyncMessage(Optional.<SentTranscriptMessage>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.<SignalServiceAttachment>absent(),
                                      Optional.of(blocked),
                                      Optional.<RequestMessage>absent(),
                                      Optional.<List<ReadMessage>>absent());
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:9,代码来源:SignalServiceSyncMessage.java

示例11: setSlide

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private void setSlide(@NonNull Slide slide) {
  if (getSlideUri() != null)                                    cleanup(getSlideUri());
  if (captureUri != null && !captureUri.equals(slide.getUri())) cleanup(captureUri);

  this.captureUri = null;
  this.slide      = Optional.of(slide);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:8,代码来源:AttachmentManager.java

示例12: getSystemContactInfo

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<SystemContactInfo> getSystemContactInfo(@NonNull String e164number,
                                                         @NonNull String localNumber)
{
  Uri      uri          = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(e164number));
  String[] projection   = {ContactsContract.PhoneLookup.NUMBER,
                           ContactsContract.PhoneLookup._ID,
                           ContactsContract.PhoneLookup.DISPLAY_NAME};
  Cursor   numberCursor = null;
  Cursor   idCursor     = null;

  try {
    numberCursor = context.getContentResolver().query(uri, projection, null, null, null);

    while (numberCursor != null && numberCursor.moveToNext()) {
      try {
        String systemNumber              = numberCursor.getString(0);
        String canonicalizedSystemNumber = PhoneNumberFormatter.formatNumber(systemNumber, localNumber);

        if (canonicalizedSystemNumber.equals(e164number)) {
          idCursor = context.getContentResolver().query(RawContacts.CONTENT_URI,
                                                        new String[] {RawContacts._ID},
                                                        RawContacts.CONTACT_ID + " = ? ",
                                                        new String[] {String.valueOf(numberCursor.getLong(1))},
                                                        null);

          if (idCursor != null && idCursor.moveToNext()) {
            return Optional.of(new SystemContactInfo(numberCursor.getString(2),
                                                     numberCursor.getString(0),
                                                     idCursor.getLong(0)));
          }
        }
      } catch (InvalidNumberException e) {
        Log.w(TAG, e);
      }
    }
  } finally {
    if (numberCursor != null) numberCursor.close();
    if (idCursor     != null) idCursor.close();
  }

  return Optional.absent();
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:43,代码来源:ContactsDatabase.java

示例13: getAvatar

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<SignalServiceAttachmentStream> getAvatar(@Nullable Uri uri) throws IOException {
  if (uri == null) {
    return Optional.absent();
  }
  
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    try {
      Uri                 displayPhotoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
      AssetFileDescriptor fd              = context.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");

      return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                                .withStream(fd.createInputStream())
                                                .withContentType("image/*")
                                                .withLength(fd.getLength())
                                                .build());
    } catch (IOException e) {
      Log.w(TAG, e);
    }
  }

  Uri photoUri = Uri.withAppendedPath(uri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);

  if (photoUri == null) {
    return Optional.absent();
  }

  Cursor cursor = context.getContentResolver().query(photoUri,
                                                     new String[] {
                                                         ContactsContract.CommonDataKinds.Photo.PHOTO,
                                                         ContactsContract.CommonDataKinds.Phone.MIMETYPE
                                                     }, null, null, null);

  try {
    if (cursor != null && cursor.moveToNext()) {
      byte[] data = cursor.getBlob(0);

      if (data != null) {
        return Optional.of(SignalServiceAttachment.newStreamBuilder()
                                                  .withStream(new ByteArrayInputStream(data))
                                                  .withContentType("image/*")
                                                  .withLength(data.length)
                                                  .build());
      }
    }

    return Optional.absent();
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:53,代码来源:MultiDeviceContactUpdateJob.java

示例14: getRecipientsPreferences

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public Optional<RecipientsPreferences> getRecipientsPreferences(@NonNull long[] recipients) {
  Arrays.sort(recipients);

  SQLiteDatabase database = databaseHelper.getReadableDatabase();
  Cursor         cursor   = null;

  try {
    cursor = database.query(TABLE_NAME, null, RECIPIENT_IDS + " = ?",
                            new String[] {Util.join(recipients, " ")},
                            null, null, null);

    if (cursor != null && cursor.moveToNext()) {
      boolean blocked               = cursor.getInt(cursor.getColumnIndexOrThrow(BLOCK))                == 1;
      String  notification          = cursor.getString(cursor.getColumnIndexOrThrow(NOTIFICATION));
      int     vibrateState          = cursor.getInt(cursor.getColumnIndexOrThrow(VIBRATE));
      long    muteUntil             = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
      String  serializedColor       = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
      Uri     notificationUri       = notification == null ? null : Uri.parse(notification);
      boolean seenInviteReminder    = cursor.getInt(cursor.getColumnIndexOrThrow(SEEN_INVITE_REMINDER)) == 1;
      int     defaultSubscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(DEFAULT_SUBSCRIPTION_ID));
      int     expireMessages        = cursor.getInt(cursor.getColumnIndexOrThrow(EXPIRE_MESSAGES));

      MaterialColor color;

      try {
        color = serializedColor == null ? null : MaterialColor.fromSerialized(serializedColor);
      } catch (MaterialColor.UnknownColorException e) {
        Log.w(TAG, e);
        color = null;
      }

      Log.w(TAG, "Muted until: " + muteUntil);

      return Optional.of(new RecipientsPreferences(blocked, muteUntil,
                                                   VibrateState.fromId(vibrateState),
                                                   notificationUri, color, seenInviteReminder,
                                                   defaultSubscriptionId, expireMessages));
    }

    return Optional.absent();
  } finally {
    if (cursor != null) cursor.close();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:45,代码来源:RecipientPreferenceDatabase.java

示例15: SignalServiceContent

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public SignalServiceContent(SignalServiceCallMessage callMessage) {
  this.message            = Optional.absent();
  this.synchronizeMessage = Optional.absent();
  this.callMessage        = Optional.of(callMessage);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:6,代码来源:SignalServiceContent.java


注:本文中的org.whispersystems.libsignal.util.guava.Optional.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。