mirror of https://github.com/apache/jclouds.git
Remove Strings2.replaceAll(String, char, String)
String.replace(String, String) serves this purpose better.
This commit is contained in:
parent
a1c09f8391
commit
64e9a4e4c6
|
@ -24,7 +24,6 @@ import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
|||
import static org.jclouds.util.Strings2.toInputStream;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -136,8 +135,6 @@ public class SignRequest implements HttpRequestFilter {
|
|||
toSign.append(request.getMethod()).append("\n");
|
||||
}
|
||||
|
||||
private static final Pattern TWO_SPACE_PATTERN = Pattern.compile(" ");
|
||||
|
||||
private void appendCanonicalizedHeaders(HttpRequest request, StringBuilder toSign) {
|
||||
// TreeSet == Sort the headers alphabetically.
|
||||
Set<String> headers = Sets.newTreeSet(request.getHeaders().keySet());
|
||||
|
@ -149,7 +146,7 @@ public class SignRequest implements HttpRequestFilter {
|
|||
// replacing any
|
||||
// newline characters and extra embedded white spaces in the value.
|
||||
for (String value : request.getHeaders().get(header)) {
|
||||
value = Strings2.replaceAll(value, TWO_SPACE_PATTERN, " ");
|
||||
value = value.replace(" ", " ");
|
||||
value = Strings2.replaceAll(value, NEWLINE_PATTERN, "");
|
||||
toSign.append(value).append(' ');
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.jclouds.s3.domain.ListBucketResponse;
|
|||
import org.jclouds.s3.domain.ObjectMetadata;
|
||||
import org.jclouds.s3.domain.ObjectMetadataBuilder;
|
||||
import org.jclouds.s3.domain.internal.ListBucketResponseImpl;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -102,7 +101,7 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
|
|||
} else if (qName.equals("ETag")) {
|
||||
String currentETag = currentOrNull(currentText);
|
||||
builder.eTag(currentETag);
|
||||
currentETag = Strings2.replaceAll(currentETag, '"', "");
|
||||
currentETag = currentETag.replace("\"", "");
|
||||
if (!MULTIPART_BLOB_ETAG.matcher(currentETag).matches()) {
|
||||
builder.contentMD5(base16().lowerCase().decode(currentETag));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.blobstore.options.GetOptions;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -49,14 +48,14 @@ public class HttpGetOptionsListToGetOptions implements
|
|||
org.jclouds.blobstore.options.GetOptions to = new org.jclouds.blobstore.options.GetOptions();
|
||||
if (from.length != 0) {
|
||||
if (from[0].getIfMatch() != null) {
|
||||
to.ifETagMatches(Strings2.replaceAll(from[0].getIfMatch(), '"', ""));
|
||||
to.ifETagMatches(from[0].getIfMatch().replace("\"", ""));
|
||||
}
|
||||
if (from[0].getIfModifiedSince() != null) {
|
||||
Date time = dateService.rfc822DateParse(from[0].getIfModifiedSince());
|
||||
to.ifModifiedSince(time);
|
||||
}
|
||||
if (from[0].getIfNoneMatch() != null) {
|
||||
to.ifETagDoesntMatch(Strings2.replaceAll(from[0].getIfNoneMatch(), '"', ""));
|
||||
to.ifETagDoesntMatch(from[0].getIfNoneMatch().replace("\"", ""));
|
||||
}
|
||||
if (from[0].getIfUnmodifiedSince() != null) {
|
||||
Date time = dateService.rfc822DateParse(from[0].getIfUnmodifiedSince());
|
||||
|
|
|
@ -119,25 +119,6 @@ public class Strings2 {
|
|||
return returnVal;
|
||||
}
|
||||
|
||||
public static String replaceAll(String input, char match, String replacement) {
|
||||
if (input.indexOf(match) != -1) {
|
||||
try {
|
||||
input = CHAR_TO_PATTERN.get(match).matcher(input).replaceAll(replacement);
|
||||
} catch (ExecutionException e) {
|
||||
throw new IllegalStateException("error creating pattern: " + match, e);
|
||||
}
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
private static final LoadingCache<Character, Pattern> CHAR_TO_PATTERN = CacheBuilder.newBuilder()
|
||||
.<Character, Pattern> build(new CacheLoader<Character, Pattern>() {
|
||||
@Override
|
||||
public Pattern load(Character plain) {
|
||||
return Pattern.compile(plain + "");
|
||||
}
|
||||
});
|
||||
|
||||
public static String toString(InputSupplier<? extends InputStream> supplier)
|
||||
throws IOException {
|
||||
return CharStreams.toString(CharStreams.newReaderSupplier(supplier,
|
||||
|
|
Loading…
Reference in New Issue