Skip to content

Commit 09a1a88

Browse files
authored
Optimize ModelHelper and Use Class Wrapper instead of Copying (Azure#26008)
Optimize ModelHelper and Use Class Wrapper instead of Copying
1 parent 8c56c20 commit 09a1a88

File tree

15 files changed

+1738
-948
lines changed

15 files changed

+1738
-948
lines changed

eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@
755755
<Match>
756756
<Or>
757757
<Class name="com.azure.core.util.paging.PagedFluxCoreJavaDocCodeSnippets"/>
758+
<Class name="com.azure.storage.blob.implementation.models.BlobPropertiesInternalDownload"/>
758759
</Or>
759760
<Bug pattern="NP_LOAD_OF_KNOWN_NULL_VALUE,
760761
SIC_INNER_SHOULD_BE_STATIC_ANON,
@@ -1330,7 +1331,7 @@
13301331
<Method name="init"/>
13311332
<Bug pattern="REC_CATCH_EXCEPTION"/>
13321333
</Match>
1333-
1334+
13341335
<Match>
13351336
<Class name="com.azure.cosmos.encryption.EncryptionCosmosAsyncContainer"/>
13361337
<Method name="decryptResponseAsync"/>
@@ -1908,7 +1909,7 @@
19081909
<Method name="subscribe"/>
19091910
<Bug pattern="DE_MIGHT_IGNORE"/>
19101911
</Match>
1911-
1912+
19121913
<!-- Exception is ignored by design which indicate that non-parsable id -->
19131914
<Match>
19141915
<Class name="com.azure.cosmos.implementation.ResourceId"/>

sdk/storage/azure-storage-blob-nio/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ to guarantee that the data is available to be read.
194194
try (OutputStream os = Files.newOutputStream(filePath)) {
195195
os.write(0);
196196
}
197-
```
197+
```
198198

199199
### Copy a file
200200

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobUrlParts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private static void parseIpUrl(URL url, BlobUrlParts parts) {
407407
path = path.substring(1);
408408
}
409409

410-
String[] pathPieces = path.split("/", 3);
410+
String[] pathPieces = ModelHelper.FORWARD_SLASH.split(path, 3);
411411
parts.setAccountName(pathPieces[0]);
412412

413413
if (pathPieces.length >= 3) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.blob.implementation.accesshelpers;
5+
6+
import com.azure.storage.blob.implementation.models.BlobsDownloadHeaders;
7+
import com.azure.storage.blob.models.BlobDownloadHeaders;
8+
9+
/**
10+
* Helper class to access private values of {@link BlobDownloadHeaders} across package boundaries.
11+
*/
12+
public final class BlobDownloadHeadersConstructorProxy {
13+
private static BlobDownloadHeadersConstructorAccessor accessor;
14+
15+
private BlobDownloadHeadersConstructorProxy() { }
16+
17+
/**
18+
* Type defining the methods to set the non-public properties of a {@link BlobDownloadHeadersConstructorAccessor}
19+
* instance.
20+
*/
21+
public interface BlobDownloadHeadersConstructorAccessor {
22+
/**
23+
* Creates a new instance of {@link BlobDownloadHeaders} backed by an internal instance of
24+
* {@link BlobsDownloadHeaders}.
25+
*
26+
* @param internalHeaders The internal headers.
27+
* @return A new instance of {@link BlobDownloadHeaders}.
28+
*/
29+
BlobDownloadHeaders create(BlobsDownloadHeaders internalHeaders);
30+
}
31+
32+
/**
33+
* The method called from {@link BlobDownloadHeaders} to set it's accessor.
34+
*
35+
* @param accessor The accessor.
36+
*/
37+
public static void setAccessor(final BlobDownloadHeadersConstructorAccessor accessor) {
38+
BlobDownloadHeadersConstructorProxy.accessor = accessor;
39+
}
40+
41+
/**
42+
* Creates a new instance of {@link BlobDownloadHeaders} backed by an internal instance of
43+
* {@link BlobsDownloadHeaders}.
44+
*
45+
* @param internalHeaders The internal headers.
46+
* @return A new instance of {@link BlobDownloadHeaders}.
47+
*/
48+
public static BlobDownloadHeaders create(BlobsDownloadHeaders internalHeaders) {
49+
// This looks odd but is necessary, it is possible to engage the access helper before anywhere else in the
50+
// application accesses BlobDownloadHeaders which triggers the accessor to be configured. So, if the accessor
51+
// is null this effectively pokes the class to set up the accessor.
52+
if (accessor == null) {
53+
new BlobDownloadHeaders();
54+
}
55+
56+
assert accessor != null;
57+
return accessor.create(internalHeaders);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.blob.implementation.accesshelpers;
5+
6+
import com.azure.storage.blob.implementation.models.BlobPropertiesInternal;
7+
import com.azure.storage.blob.models.BlobProperties;
8+
9+
/**
10+
* Helper class to access private values of {@link BlobProperties} across package boundaries.
11+
*/
12+
public final class BlobPropertiesConstructorProxy {
13+
private static BlobPropertiesConstructorAccessor accessor;
14+
15+
private BlobPropertiesConstructorProxy() {
16+
}
17+
18+
/**
19+
* Interface defining the methods that access non-public APIs of a {@link BlobProperties} instance.
20+
*/
21+
public interface BlobPropertiesConstructorAccessor {
22+
/**
23+
* Creates a new instance of {@link BlobProperties} backed by an internal instance of
24+
* {@link BlobPropertiesInternal}.
25+
*
26+
* @param internalProperties The internal properties.
27+
* @return A new instance of {@link BlobProperties}.
28+
*/
29+
BlobProperties create(BlobPropertiesInternal internalProperties);
30+
}
31+
32+
/**
33+
* The method called from the static initializer of {@link BlobProperties} to set it's accessor.
34+
*
35+
* @param accessor The {@link BlobProperties} accessor.
36+
*/
37+
public static void setAccessor(final BlobPropertiesConstructorAccessor accessor) {
38+
BlobPropertiesConstructorProxy.accessor = accessor;
39+
}
40+
41+
/**
42+
* Creates a new instance of {@link BlobProperties} backed by an internal instance of
43+
* {@link BlobPropertiesInternal}.
44+
*
45+
* @param internalProperties The internal properties.
46+
* @return A new instance of {@link BlobProperties}.
47+
*/
48+
public static BlobProperties create(BlobPropertiesInternal internalProperties) {
49+
// This looks odd but is necessary, it is possible to engage the access helper before anywhere else in the
50+
// application accesses BlobDownloadHeaders which triggers the accessor to be configured. So, if the accessor
51+
// is null this effectively pokes the class to set up the accessor.
52+
if (accessor == null) {
53+
new BlobProperties(null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null,
54+
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
55+
}
56+
57+
assert accessor != null;
58+
return accessor.create(internalProperties);
59+
}
60+
}

0 commit comments

Comments
 (0)