|
21 | 21 |
|
22 | 22 | import org.elasticsearch.ElasticsearchException;
|
23 | 23 | import org.elasticsearch.cloud.azure.AzureStorageService;
|
24 |
| -import org.elasticsearch.common.Strings; |
25 | 24 | import org.elasticsearch.common.blobstore.BlobMetaData;
|
26 | 25 | import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
|
27 | 26 | import org.elasticsearch.common.collect.ImmutableMap;
|
|
33 | 32 | import java.io.ByteArrayOutputStream;
|
34 | 33 | import java.io.IOException;
|
35 | 34 | import java.io.InputStream;
|
| 35 | +import java.util.Locale; |
36 | 36 | import java.util.Map;
|
37 | 37 | import java.util.concurrent.ConcurrentHashMap;
|
38 | 38 |
|
@@ -85,7 +85,7 @@ public InputStream getInputStream(String container, String blob) {
|
85 | 85 | public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) {
|
86 | 86 | ImmutableMap.Builder<String, BlobMetaData> blobsBuilder = ImmutableMap.builder();
|
87 | 87 | for (String blobName : blobs.keySet()) {
|
88 |
| - if (Strings.startsWithIgnoreCase(blobName, prefix)) { |
| 88 | + if (startsWithIgnoreCase(blobName, prefix)) { |
89 | 89 | blobsBuilder.put(blobName, new PlainBlobMetaData(blobName, blobs.get(blobName).length));
|
90 | 90 | }
|
91 | 91 | }
|
@@ -123,4 +123,27 @@ protected void doStop() throws ElasticsearchException {
|
123 | 123 | @Override
|
124 | 124 | protected void doClose() throws ElasticsearchException {
|
125 | 125 | }
|
| 126 | + |
| 127 | + /** |
| 128 | + * Test if the given String starts with the specified prefix, |
| 129 | + * ignoring upper/lower case. |
| 130 | + * |
| 131 | + * @param str the String to check |
| 132 | + * @param prefix the prefix to look for |
| 133 | + * @see java.lang.String#startsWith |
| 134 | + */ |
| 135 | + public static boolean startsWithIgnoreCase(String str, String prefix) { |
| 136 | + if (str == null || prefix == null) { |
| 137 | + return false; |
| 138 | + } |
| 139 | + if (str.startsWith(prefix)) { |
| 140 | + return true; |
| 141 | + } |
| 142 | + if (str.length() < prefix.length()) { |
| 143 | + return false; |
| 144 | + } |
| 145 | + String lcStr = str.substring(0, prefix.length()).toLowerCase(Locale.ROOT); |
| 146 | + String lcPrefix = prefix.toLowerCase(Locale.ROOT); |
| 147 | + return lcStr.equals(lcPrefix); |
| 148 | + } |
126 | 149 | }
|
0 commit comments