examples/iot-nirvana/client/src/main/java/com/google/cloud/demo/iot/nirvana/client/IotDeviceMgr.java
/**
   * Read the device certificate and generate device credentials.
   *
   * @param rsaCertificateFilePath Path to the file containing the device certificate
   * @return Device credentials loaded from the certificate file, instance of {@link
   *     DeviceCredential}
   * @throws ClientException
   */
Read the device certificate and generate device credentials.
@param rsaCertificateFilePath Path to the file containing the device certificate
@return Device credentials loaded from the certificate file, instance of {@link
DeviceCredential}
@throws ClientException
Read the device certificate and generate device credentials . @param rsaCertificateFilePath Path to the file containing the device certificate @return Device credentials loaded from the certificate file instance of { @link DeviceCredential } @throws ClientException
private DeviceCredential loadCredentials(String rsaCertificateFilePath) throws ClientException {
    try {
      PublicKeyCredential publicKeyCredential = new PublicKeyCredential();
      String key = Files.toString(new File(rsaCertificateFilePath), Charsets.UTF_8);
      publicKeyCredential.setKey(key);
      publicKeyCredential.setFormat(KEY_FORMAT_RSA_X509_PEM);
      DeviceCredential deviceCredential = new DeviceCredential();
      deviceCredential.setPublicKey(publicKeyCredential);
      return deviceCredential;
    } catch (IOException e) {
      String message =
          String.format("Failed to load device credentials. Cause : %s", e.getMessage());
      LogUtils.logError(LOGGER, DEVICE_MGR_LOGGING_RESOURCE, getGcpProjectId(), message);
      throw new ClientException(message, e);
    }
  }
private DeviceCredential loadCredentials ( String rsaCertificateFilePath ) throws ClientException { try { PublicKeyCredential publicKeyCredential = new PublicKeyCredential ( ) ; String key = Files . toString ( new File ( rsaCertificateFilePath ) , Charsets . UTF_8 ) ; publicKeyCredential . setKey ( key ) ; publicKeyCredential . setFormat ( KEY_FORMAT_RSA_X509_PEM ) ; DeviceCredential deviceCredential = new DeviceCredential ( ) ; deviceCredential . setPublicKey ( publicKeyCredential ) ; return deviceCredential ; } catch ( IOException e ) { String message = String . format ( "Failed to load device credentials. Cause : %s" , e . getMessage ( ) ) ; LogUtils . logError ( LOGGER , DEVICE_MGR_LOGGING_RESOURCE , getGcpProjectId ( ) , message ) ; throw new ClientException ( message , e ) ; } }
Read the device certificate and generate device credentials.
Read the device certificate and generate device credentials .