5.1 File Locking/Unlocking

5.1.1 Lock File

The lockFile method of BayunCore class locks a file with default encryption-policy dictated by server settings.

  • Parameters
    • String filePath - Path of the file to be locked.
    • Callback success - Success block to be executed after file is successfully locked.
    • Callback failure - Failure block to be executed if locking fails, returns BayunError.

The file at the given file path is overwritten with the locked file. If file locking fails original file is not changed.

String fileURL = file.getAbsolutePath(); bayunCore.lockFile(fileURL, success, failure); // Callbacks for locking a file success = new Handler.Callback() { @Override public boolean handleMessage(Message message) { Log.d(TAG, "File locked successfully."); return false; } } failure = new Handler.Callback() { @Override public boolean handleMessage(Message message) { String error = message.getData().getString("BayunError", ""); if (response.equalsIgnoreCase(BayunError.ERROR_INTERNET_CONNECTION)) { } else if (response.equalsIgnoreCase(BayunError.ERROR_ENCRYPTION_FAILED)) { } return false; } };

5.1.2 Lock File with encryption-policy

The lockFile method with encryption-policy as an optional parameter locks file with the encryption key dictated by the policy.

  • Parameters
    • String filePath - Path of the file to be locked.
    • int encryptionPolicy - BayunEncryptionPolicy determines the key for locking.
    • int keyGenerationPolicy - BayunKeyGenerationPolicy determines the policy to generate the data encryption key.
    • String groupId - GroupId is required if encryptionPolicy is BayunEncryptionPolicyGroup.
    • Callback success - Success block to be executed after file is successfully locked.
    • Callback failure - Failure block to be executed if locking fails, returns BayunError.
String fileURL = file.getAbsolutePath(); int encryptionPolicy = BayunCore.ENCRYPTION_POLICY_COMPANY; int keyGenerationPolicy = BayunCore.KEY_GENERATION_POLICY_ENVELOPE; String groupId; bayunCore.lockFile(fileURL, encryptionPolicy, keyGenerationPolicy, groupId, success, failure); // Callbacks for locking a file success = new Handler.Callback() { @Override public boolean handleMessage(Message message) { Log.d(TAG, "File locked successfully."); return false; } } failure = new Handler.Callback() { @Override public boolean handleMessage(Message message) { String error = message.getData().getString("BayunError", ""); if (response.equalsIgnoreCase(BayunError.ERROR_INTERNET_CONNECTION)) { } else if (response.equalsIgnoreCase(BayunError.ERROR_ENCRYPTION_FAILED)) { } return false; } };
Note : If encryption-policy is other than BayunEncryptionPolicyGroup then groupId should be nil.

5.1.3 Unlock File

The unlockFile method of BayunCore class unlocks a locked file.

  • Parameters
    • String filePath - Path of the file to be unlocked.
    • Callback success - Success block to be executed after file is successfully unlocked.
    • Callback failure - Failure block to be executed if unlocking fails, returns BayunError.

The file at the given file path is overwritten with the unlocked file.

String fileURL = file.getAbsolutePath(); bayunCore.unlockFile(fileURL, success, failure); // Callbacks for unlocking a file success = new Handler.Callback() { @Override public boolean handleMessage(Message message) { Log.d(TAG, "File unlocked successfully."); return false; } } failure = new Handler.Callback() { @Override public boolean handleMessage(Message message) { String error = message.getData().getString("BayunError", ""); if (response.equalsIgnoreCase(BayunError.ERROR_INTERNET_CONNECTION)) { } else if (response.equalsIgnoreCase(BayunError.ERROR_DECRYPTION_FAILED)) { } return false; } };

results matching ""

    No results matching ""