1414import com .azure .storage .blob .implementation .models .BlobsDownloadHeaders ;
1515import com .azure .storage .blob .implementation .util .ModelHelper ;
1616import com .azure .core .util .logging .ClientLogger ;
17- import com .azure .storage .common .policy .DecoderState ;
1817import reactor .core .publisher .Flux ;
1918import reactor .core .publisher .Mono ;
2019
2120import java .io .Closeable ;
2221import java .io .IOException ;
2322import java .nio .ByteBuffer ;
24- import java .nio .ByteOrder ;
2523import java .nio .channels .AsynchronousByteChannel ;
2624import java .util .Objects ;
27- import java .util .concurrent .atomic .AtomicReference ;
2825import java .util .function .BiFunction ;
2926
3027/**
@@ -40,15 +37,9 @@ public final class BlobDownloadAsyncResponse extends ResponseBase<BlobDownloadHe
4037 .setAccessor (new BlobDownloadAsyncResponseConstructorProxy .BlobDownloadAsyncResponseConstructorAccessor () {
4138 @ Override
4239 public BlobDownloadAsyncResponse create (StreamResponse sourceResponse ,
43- BiFunction <Throwable , Long , Mono <StreamResponse >> onErrorResume , DownloadRetryOptions retryOptions ,
44- AtomicReference <DecoderState > decoderStateRef ) {
45- return new BlobDownloadAsyncResponse (sourceResponse , onErrorResume , retryOptions , decoderStateRef );
46- }
47-
48- @ Override
49- public DecoderState getDecoderState (BlobDownloadAsyncResponse response ) {
50- AtomicReference <DecoderState > ref = response .decoderStateRef ;
51- return ref == null ? null : ref .get ();
40+ BiFunction <Throwable , Long , Mono <StreamResponse >> onErrorResume ,
41+ DownloadRetryOptions retryOptions ) {
42+ return new BlobDownloadAsyncResponse (sourceResponse , onErrorResume , retryOptions );
5243 }
5344 });
5445 }
@@ -58,7 +49,6 @@ public DecoderState getDecoderState(BlobDownloadAsyncResponse response) {
5849 private final StreamResponse sourceResponse ;
5950 private final BiFunction <Throwable , Long , Mono <StreamResponse >> onErrorResume ;
6051 private final DownloadRetryOptions retryOptions ;
61- private final AtomicReference <DecoderState > decoderStateRef ;
6252
6353 /**
6454 * Constructs a {@link BlobDownloadAsyncResponse}.
@@ -75,38 +65,15 @@ public BlobDownloadAsyncResponse(HttpRequest request, int statusCode, HttpHeader
7565 this .sourceResponse = null ;
7666 this .onErrorResume = null ;
7767 this .retryOptions = null ;
78- this .decoderStateRef = null ;
7968 }
8069
81- /**
82- * Constructs a {@link BlobDownloadAsyncResponse}.
83- *
84- * @param sourceResponse The initial Stream Response
85- * @param onErrorResume Function used to resume.
86- * @param retryOptions Retry options.
87- */
8870 BlobDownloadAsyncResponse (StreamResponse sourceResponse ,
8971 BiFunction <Throwable , Long , Mono <StreamResponse >> onErrorResume , DownloadRetryOptions retryOptions ) {
90- this (sourceResponse , onErrorResume , retryOptions , null );
91- }
92-
93- BlobDownloadAsyncResponse (StreamResponse sourceResponse ,
94- BiFunction <Throwable , Long , Mono <StreamResponse >> onErrorResume , DownloadRetryOptions retryOptions ,
95- AtomicReference <DecoderState > decoderStateRef ) {
96- this (sourceResponse , onErrorResume , retryOptions , decoderStateRef , extractHeaders (sourceResponse ));
97- }
98-
99- private BlobDownloadAsyncResponse (StreamResponse sourceResponse ,
100- BiFunction <Throwable , Long , Mono <StreamResponse >> onErrorResume , DownloadRetryOptions retryOptions ,
101- AtomicReference <DecoderState > decoderStateRef , BlobDownloadHeaders deserializedHeaders ) {
10272 super (sourceResponse .getRequest (), sourceResponse .getStatusCode (), sourceResponse .getHeaders (),
103- createResponseFluxWithContentCrc (sourceResponse , onErrorResume , retryOptions , decoderStateRef ,
104- deserializedHeaders ),
105- deserializedHeaders );
73+ createResponseFlux (sourceResponse , onErrorResume , retryOptions ), extractHeaders (sourceResponse ));
10674 this .sourceResponse = Objects .requireNonNull (sourceResponse , "'sourceResponse' must not be null" );
10775 this .onErrorResume = Objects .requireNonNull (onErrorResume , "'onErrorResume' must not be null" );
10876 this .retryOptions = Objects .requireNonNull (retryOptions , "'retryOptions' must not be null" );
109- this .decoderStateRef = decoderStateRef ;
11077 }
11178
11279 private static BlobDownloadHeaders extractHeaders (StreamResponse response ) {
@@ -124,28 +91,6 @@ private static Flux<ByteBuffer> createResponseFlux(StreamResponse sourceResponse
12491 .defaultIfEmpty (EMPTY_BUFFER );
12592 }
12693
127- /**
128- * Builds the response flux and populates ContentCrc64 on the deserialized headers when structured message
129- * decoding completes successfully.
130- */
131- private static Flux <ByteBuffer > createResponseFluxWithContentCrc (StreamResponse sourceResponse ,
132- BiFunction <Throwable , Long , Mono <StreamResponse >> onErrorResume , DownloadRetryOptions retryOptions ,
133- AtomicReference <DecoderState > decoderStateRef , BlobDownloadHeaders deserializedHeaders ) {
134- Flux <ByteBuffer > flux = createResponseFlux (sourceResponse , onErrorResume , retryOptions );
135- if (decoderStateRef != null && deserializedHeaders != null ) {
136- flux = flux .doOnComplete (() -> {
137- DecoderState state = decoderStateRef .get ();
138- if (state != null && state .isFinalized ()) {
139- long crc = state .getComposedCrc64 ();
140- byte [] crcBytes = new byte [8 ];
141- ByteBuffer .wrap (crcBytes ).order (ByteOrder .LITTLE_ENDIAN ).putLong (crc );
142- deserializedHeaders .setContentCrc64 (crcBytes );
143- }
144- });
145- }
146- return flux ;
147- }
148-
14994 /**
15095 * Transfers content bytes to the {@link AsynchronousByteChannel}.
15196 * @param channel The destination {@link AsynchronousByteChannel}.
0 commit comments