private void loadTokens()

in src/main/java/org/apache/sling/auth/oauth_client/impl/TokenStore.java [306:345]


    private void loadTokens() {
        if (tokenFile.isFile() && tokenFile.canRead()) {
            try (DataInputStream keyInputStream = new DataInputStream(new FileInputStream(tokenFile))) {
                int newCurrentToken = keyInputStream.readInt();
                long newNextUpdate = keyInputStream.readLong();
                AtomicReferenceArray<SecretKey> newKeys = new AtomicReferenceArray<>(TOKEN_BUFFER_SIZE);
                for (int i = 0; i < newKeys.length(); i++) {
                    int isNull = keyInputStream.readInt();
                    if (isNull == 1) {
                        int l = keyInputStream.readInt();
                        byte[] b = new byte[l];
                        int offset = 0;
                        int bytesRead;
                        do {
                            bytesRead = keyInputStream.read(b, offset, b.length - offset);
                            offset += bytesRead;
                        } while (bytesRead != -1 && offset < b.length);
                        newKeys.set(i, new SecretKeySpec(b, HMAC_SHA256));
                    } else {
                        newKeys.set(i, null);
                    }
                }

                // assign the tokes and schedule a next update
                nextUpdate = newNextUpdate;
                currentToken = newCurrentToken;
                currentTokens = newKeys;

            } catch (IOException e) {
                log.error("Failed to load cookie keys {}", e.getMessage());
            }
        }

        // if there was a failure to read the current tokens, create new ones
        if (currentTokens == null) {
            currentTokens = new AtomicReferenceArray<>(TOKEN_BUFFER_SIZE);
            nextUpdate = System.currentTimeMillis();
            currentToken = 0;
        }
    }