2929import com .google .auth .oauth2 .UserCredentials ;
3030import com .google .cloud .bigquery .exception .BigQueryJdbcRuntimeException ;
3131import java .io .IOException ;
32+ import java .io .InputStream ;
3233import java .net .URI ;
3334import java .net .URISyntaxException ;
3435import java .net .URL ;
35- import java .nio .file .Files ;
36- import java .nio .file .Paths ;
3736import java .security .PrivateKey ;
3837import java .util .Collections ;
3938import java .util .HashMap ;
@@ -503,11 +502,12 @@ public void testPrivateKeyFromPkcs8_wrong() {
503502 // -keypass notasecret -storetype pkcs12 -keystore ./fake.p12
504503 @ Test
505504 public void testPrivateKeyFromP12Bytes () {
506- URL resource = BigQueryJdbcOAuthUtilityTest .class .getResource ("/fake.p12" );
505+ InputStream stream = BigQueryJdbcOAuthUtilityTest .class .getResourceAsStream ("/fake.p12" );
507506 try {
508- PrivateKey pk =
509- BigQueryJdbcOAuthUtility .privateKeyFromP12Bytes (
510- Files .readAllBytes (Paths .get (resource .toURI ())), "notasecret" );
507+ int size = 16 * 1024 ;
508+ byte [] data = new byte [size ];
509+ stream .read (data , 0 , data .length );
510+ PrivateKey pk = BigQueryJdbcOAuthUtility .privateKeyFromP12Bytes (data , "notasecret" );
511511 assertNotNull (pk );
512512 } catch (Exception e ) {
513513 assertTrue (false );
@@ -516,11 +516,12 @@ public void testPrivateKeyFromP12Bytes() {
516516
517517 @ Test
518518 public void testPrivateKeyFromP12Bytes_wrong_password () {
519- URL resource = BigQueryJdbcOAuthUtilityTest .class .getResource ("/fake.p12" );
519+ InputStream stream = BigQueryJdbcOAuthUtilityTest .class .getResourceAsStream ("/fake.p12" );
520520 try {
521- PrivateKey pk =
522- BigQueryJdbcOAuthUtility .privateKeyFromP12Bytes (
523- Files .readAllBytes (Paths .get (resource .toURI ())), "fake" );
521+ int size = 16 * 1024 ;
522+ byte [] data = new byte [size ];
523+ stream .read (data , 0 , data .length );
524+ PrivateKey pk = BigQueryJdbcOAuthUtility .privateKeyFromP12Bytes (data , "fake" );
524525 assertNull (pk );
525526 } catch (Exception e ) {
526527 assertTrue (false );
0 commit comments