Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 9db3f68

Browse files
committed
Fix reading
1 parent e119f74 commit 9db3f68

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtility.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,20 @@ private static GoogleCredentials getGoogleServiceAccountCredentials(
369369
byte[] keyBytes = pvtKey != null ? pvtKey.getBytes() : null;
370370

371371
if (isFileExists(keyPath)) {
372-
InputStream stream = new FileInputStream(keyPath);
373-
keyBytes = stream.readNBytes(1024 * 1024);
374-
stream.close();
372+
try (InputStream stream = new FileInputStream(keyPath)) {
373+
int bufferSize = 1024 * 1024;
374+
byte[] buffer = new byte[bufferSize];
375+
stream.read(buffer, 0, bufferSize);
376+
keyBytes = buffer;
377+
}
375378
}
376379

377380
InputStream stream = null;
378381
if (isJson(keyBytes)) {
379382
stream = new ByteArrayInputStream(keyBytes);
380383
} else if (pvtKey != null) {
381384
key = privateKeyFromPkcs8(pvtKey);
382-
} else {
385+
} else if (keyBytes != null) {
383386
key = privateKeyFromP12Bytes(keyBytes, p12Password);
384387
}
385388

0 commit comments

Comments
 (0)