38
38
import java .net .HttpURLConnection ;
39
39
import java .net .ServerSocket ;
40
40
import java .net .URL ;
41
+ import java .net .URLConnection ;
41
42
import java .nio .channels .Channels ;
42
43
import java .nio .channels .ReadableByteChannel ;
43
44
import java .nio .file .Files ;
@@ -316,6 +317,7 @@ protected static class DownloadableEmulatorRunner implements EmulatorRunner {
316
317
private final String md5CheckSum ;
317
318
private final URL downloadUrl ;
318
319
private final String fileName ;
320
+ private String accessToken ;
319
321
private Process process ;
320
322
private static final Logger log = Logger .getLogger (DownloadableEmulatorRunner .class .getName ());
321
323
@@ -328,6 +330,12 @@ public DownloadableEmulatorRunner(
328
330
this .fileName = splitUrl [splitUrl .length - 1 ];
329
331
}
330
332
333
+ public DownloadableEmulatorRunner (
334
+ List <String > commandText , URL downloadUrl , String md5CheckSum , String accessToken ) {
335
+ this (commandText , downloadUrl , md5CheckSum );
336
+ this .accessToken = accessToken ;
337
+ }
338
+
331
339
@ Override
332
340
public boolean isAvailable () {
333
341
try {
@@ -420,7 +428,11 @@ private File downloadZipFile() throws IOException {
420
428
if (log .isLoggable (Level .FINE )) {
421
429
log .fine ("Fetching emulator" );
422
430
}
423
- ReadableByteChannel rbc = Channels .newChannel (downloadUrl .openStream ());
431
+ URLConnection urlConnection = downloadUrl .openConnection ();
432
+ if (accessToken != null ) {
433
+ urlConnection .setRequestProperty ("Authorization" , "Bearer " + accessToken );
434
+ }
435
+ ReadableByteChannel rbc = Channels .newChannel (urlConnection .getInputStream ());
424
436
try (FileOutputStream fos = new FileOutputStream (zipFile )) {
425
437
fos .getChannel ().transferFrom (rbc , 0 , Long .MAX_VALUE );
426
438
}
0 commit comments