public void open()

in aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/subscription/mqtt/AppSyncMqttPersistence.java [79:134]


    public void open(String clientId, String theConnection) throws MqttPersistenceException {

        if (dataDir.exists() && !dataDir.isDirectory()) {
            throw new MqttPersistenceException();
        } else if (!dataDir.exists() ) {
            if (!dataDir.mkdirs()) {
                throw new MqttPersistenceException();
            }
        }
        if (!dataDir.canWrite()) {
            throw new MqttPersistenceException();
        }


        StringBuffer keyBuffer = new StringBuffer();
        for (int i=0;i<clientId.length();i++) {
            char c = clientId.charAt(i);
            if (isSafeChar(c)) {
                keyBuffer.append(c);
            }
        }
        keyBuffer.append("-");
        final int iotIndex = theConnection.indexOf("iot");
        final int theConnectionLengthTruncated = Math.min(theConnection.length(), 100);
        final int maxIndex = iotIndex > 0 ? iotIndex : theConnectionLengthTruncated;
        for (int i=0;i<maxIndex;i++) {
            char c = theConnection.charAt(i);
            if (isSafeChar(c)) {
                keyBuffer.append(c);
            }
        }

        synchronized (this) {
            if (clientDir == null) {
                String key = keyBuffer.toString();
                clientDir = new File(dataDir, key);

                if (!clientDir.exists()) {
                    clientDir.mkdir();
                }
            }

            try {
                fileLock = new FileLock(clientDir, LOCK_FILENAME);
            } catch (Exception e) {
                // TODO - This shouldn't be here according to the interface
                // See https://github.com/eclipse/paho.mqtt.java/issues/178
                //throw new MqttPersistenceException(MqttPersistenceException.REASON_CODE_PERSISTENCE_IN_USE);
            }

            // Scan the directory for .backup files. These will
            // still exist if the JVM exited during addMessage, before
            // the new message was written to disk and the backup removed.
            restoreBackups(clientDir);
        }
    }