Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.ScatteringByteChannel;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
Expand Down Expand Up @@ -318,7 +319,10 @@ private static String getHeaderValue(@NonNull HttpHeaders headers, @NonNull Stri
} else {
throw new IllegalStateException(
String.format(
"Unexpected header type '%s' for header %s", o.getClass().getName(), headerName));
Locale.US,
"Unexpected header type '%s' for header %s",
o.getClass().getName(),
headerName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -1441,7 +1442,7 @@ public String getMd5ToHexString() {
byte[] decodedMd5 = BaseEncoding.base64().decode(md5);
StringBuilder stringBuilder = new StringBuilder();
for (byte b : decodedMd5) {
stringBuilder.append(String.format("%02x", b & 0xff));
stringBuilder.append(String.format(Locale.US, "%02x", b & 0xff));
}
return stringBuilder.toString();
}
Expand Down Expand Up @@ -1473,7 +1474,7 @@ public String getCrc32cToHexString() {
byte[] decodeCrc32c = BaseEncoding.base64().decode(crc32c);
StringBuilder stringBuilder = new StringBuilder();
for (byte b : decodeCrc32c) {
stringBuilder.append(String.format("%02x", b & 0xff));
stringBuilder.append(String.format(Locale.US, "%02x", b & 0xff));
}
return stringBuilder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.storage.v2.ReadObjectRequest;
import java.io.Serializable;
import java.util.Locale;
import java.util.Objects;
import java.util.function.BiFunction;
import javax.annotation.concurrent.Immutable;
Expand Down Expand Up @@ -239,12 +240,12 @@ public ReadObjectRequest.Builder seekReadObjectRequest(ReadObjectRequest.Builder

@Override
protected String fmtAsHttpRangeHeader() throws ArithmeticException {
return String.format("bytes=%d-%d", beginOffset, endOffsetInclusive());
return String.format(Locale.US, "bytes=%d-%d", beginOffset, endOffsetInclusive());
}

@Override
protected ToStringHelper append(ToStringHelper tsh) {
return tsh.addValue(String.format("%d + %d", beginOffset, length));
return tsh.addValue(String.format(Locale.US, "%d + %d", beginOffset, length));
}
}

Expand Down Expand Up @@ -324,12 +325,12 @@ public ReadObjectRequest.Builder seekReadObjectRequest(ReadObjectRequest.Builder

@Override
protected String fmtAsHttpRangeHeader() throws ArithmeticException {
return String.format("bytes=%d-%d", beginOffset, endOffsetInclusive());
return String.format(Locale.US, "bytes=%d-%d", beginOffset, endOffsetInclusive());
}

@Override
protected ToStringHelper append(ToStringHelper tsh) {
return tsh.addValue(String.format("[%d, %d)", beginOffset, endOffsetExclusive));
return tsh.addValue(String.format(Locale.US, "[%d, %d)", beginOffset, endOffsetExclusive));
}
}

Expand Down Expand Up @@ -409,12 +410,12 @@ public ReadObjectRequest.Builder seekReadObjectRequest(ReadObjectRequest.Builder

@Override
protected String fmtAsHttpRangeHeader() throws ArithmeticException {
return String.format("bytes=%d-%d", beginOffset, endOffsetInclusive);
return String.format(Locale.US, "bytes=%d-%d", beginOffset, endOffsetInclusive);
}

@Override
protected ToStringHelper append(ToStringHelper tsh) {
return tsh.addValue(String.format("[%d, %d]", beginOffset, endOffsetInclusive));
return tsh.addValue(String.format(Locale.US, "[%d, %d]", beginOffset, endOffsetInclusive));
}
}

Expand Down Expand Up @@ -488,17 +489,17 @@ public ReadObjectRequest.Builder seekReadObjectRequest(ReadObjectRequest.Builder
@Override
protected String fmtAsHttpRangeHeader() throws ArithmeticException {
if (beginOffset > 0) {
return String.format("bytes=%d-", beginOffset);
return String.format(Locale.US, "bytes=%d-", beginOffset);
} else if (beginOffset < 0) {
return String.format("bytes=%d", beginOffset);
return String.format(Locale.US, "bytes=%d", beginOffset);
} else {
return null;
}
}

@Override
protected ToStringHelper append(ToStringHelper tsh) {
return tsh.addValue(String.format("[%d, +INF)", beginOffset));
return tsh.addValue(String.format(Locale.US, "[%d, +INF)", beginOffset));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.storage;

import java.util.Locale;
import java.util.Objects;

abstract class Crc32cValue<Res extends Crc32cValue<Res>> {
Expand Down Expand Up @@ -64,7 +65,7 @@ static Crc32cLengthKnown of(int value, long length) {
}

static String fmtCrc32cValue(int value1) {
return String.format("crc32c{0x%08x}", value1);
return String.format(Locale.US, "crc32c{0x%08x}", value1);
}

static final class Crc32cLengthUnknown extends Crc32cValue<Crc32cLengthUnknown> {
Expand Down Expand Up @@ -142,7 +143,7 @@ public Crc32cLengthKnown concat(Crc32cLengthKnown other) {

@Override
public String toString() {
return String.format("crc32c{0x%08x (length = %d)}", value, length);
return String.format(Locale.US, "crc32c{0x%08x (length = %d)}", value, length);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.cloud.storage.TransportCompatibility.Transport;
import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Collectors;

final class CrossTransportUtils {
Expand Down Expand Up @@ -49,12 +50,20 @@ static <T> T throwTransportOnly(Class<?> clazz, String methodName, Transport tra
break;
default:
throw new IllegalStateException(
String.format("Broken Java Enum: %s received value: '%s'", Transport.class, transport));
String.format(
Locale.US,
"Broken Java Enum: %s received value: '%s'",
Transport.class,
transport));
}
String message =
String.format(
Locale.US,
"%s#%s is only supported for %s transport. Please use %s to construct a compatible instance.",
clazz.getName(), methodName, transport, builder);
clazz.getName(),
methodName,
transport,
builder);
throw new UnsupportedOperationException(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ScatteringByteChannel;
import java.util.Locale;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -166,8 +167,10 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
} else if (metadata.getGeneration() != respMetadata.getGeneration()) {
throw closeWithError(
String.format(
Locale.US,
"Mismatch Generation between subsequent reads. Expected %d but received %d",
metadata.getGeneration(), respMetadata.getGeneration()));
metadata.getGeneration(),
respMetadata.getGeneration()));
}
}
ChecksummedData checksummedData = resp.getChecksummedData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand Down Expand Up @@ -210,10 +211,10 @@ private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throw
// unless for Direct Google Access try and strip here if we can
switch (scheme) {
case "http":
endpoint = String.format("%s:%s", uri.getHost(), port > 0 ? port : 80);
endpoint = String.format(Locale.US, "%s:%s", uri.getHost(), port > 0 ? port : 80);
break;
case "https":
endpoint = String.format("%s:%s", uri.getHost(), port > 0 ? port : 443);
endpoint = String.format(Locale.US, "%s:%s", uri.getHost(), port > 0 ? port : 443);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.api.gax.grpc.GrpcCallContext;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Locale;

final class GrpcUtils {

Expand All @@ -28,7 +29,8 @@ static GrpcCallContext contextWithBucketName(String bucketName, GrpcCallContext
if (bucketName != null && !bucketName.isEmpty()) {
return baseContext.withExtraHeaders(
ImmutableMap.of(
"x-goog-request-params", ImmutableList.of(String.format("bucket=%s", bucketName))));
"x-goog-request-params",
ImmutableList.of(String.format(Locale.US, "bucket=%s", bucketName))));
}
return baseContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Locale;
import java.util.function.Supplier;
import javax.annotation.concurrent.Immutable;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -98,8 +99,10 @@ public void validate(Crc32cValue<?> expected, List<ByteBuffer> b) throws IOExcep
if (!actual.eqValue(expected)) {
throw new IOException(
String.format(
Locale.US,
"Mismatch checksum value. Expected %s actual %s",
expected.debugString(), actual.debugString()));
expected.debugString(),
actual.debugString()));
}
}

Expand All @@ -109,8 +112,10 @@ public void validate(Crc32cValue<?> expected, Supplier<ByteBuffer> b) throws IOE
if (!actual.eqValue(expected)) {
throw new IOException(
String.format(
Locale.US,
"Mismatch checksum value. Expected %s actual %s",
expected.debugString(), actual.debugString()));
expected.debugString(),
actual.debugString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.base.MoreObjects;
import java.util.Locale;
import java.util.Objects;
import java.util.function.UnaryOperator;

Expand Down Expand Up @@ -91,7 +92,8 @@ private Incomplete(ByteRangeSpec spec) {

@Override
public String getHeaderValue() {
return String.format("bytes %d-%d/*", spec.beginOffset(), spec.endOffsetInclusive());
return String.format(
Locale.US, "bytes %d-%d/*", spec.beginOffset(), spec.endOffsetInclusive());
}

@Override
Expand Down Expand Up @@ -145,7 +147,8 @@ private Total(ByteRangeSpec spec, long size) {

@Override
public String getHeaderValue() {
return String.format("bytes %d-%d/%d", spec.beginOffset(), spec.endOffsetInclusive(), size);
return String.format(
Locale.US, "bytes %d-%d/%d", spec.beginOffset(), spec.endOffsetInclusive(), size);
}

@Override
Expand Down Expand Up @@ -202,7 +205,7 @@ private Size(long size) {

@Override
public String getHeaderValue() {
return String.format("bytes */%d", size);
return String.format(Locale.US, "bytes */%d", size);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
import com.google.cloud.storage.spi.v1.HttpRpcContext;
import com.google.cloud.storage.spi.v1.HttpStorageRpc;
import io.opencensus.trace.EndSpanOptions;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import org.checkerframework.checker.nullness.qual.Nullable;

final class JsonResumableSession {

static final String SPAN_NAME_WRITE =
String.format("Sent.%s.write", HttpStorageRpc.class.getName());
String.format(Locale.US, "Sent.%s.write", HttpStorageRpc.class.getName());
static final EndSpanOptions END_SPAN_OPTIONS =
EndSpanOptions.builder().setSampleToLocalSpanStore(true).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand Down Expand Up @@ -102,7 +103,7 @@ public long getEnd() {
}

String encode() {
return String.format("%04d-%04d", begin, end);
return String.format(Locale.US, "%04d-%04d", begin, end);
}

static PartRange decode(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public Blob get(String bucket, String blob, BlobGetOption... options) {
Span span =
tracer
.spanBuilder("get")
.setAttribute("gsutil.uri", String.format("gs://%s/%s", bucket, blob))
.setAttribute("gsutil.uri", String.format(Locale.US, "gs://%s/%s", bucket, blob))
.startSpan();
try (Scope ignore = span.makeCurrent()) {
return delegate.get(bucket, blob, options);
Expand Down Expand Up @@ -1477,7 +1477,7 @@ static Storage decorate(Storage delegate, OpenTelemetry otel, Transport transpor
}

private static @NonNull String fmtBucket(String bucket) {
return String.format("gs://%s/", bucket);
return String.format(Locale.US, "gs://%s/", bucket);
}

private static final class TracerDecorator implements Tracer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
Expand Down Expand Up @@ -245,8 +246,10 @@ public void close() throws IOException {
buildParallelCompositeUploadException(
ApiExceptionFactory.createException(
String.format(
Locale.US,
"CRC32C Checksum mismatch. expected: [%s] but was: [%s]",
expectedCrc32c, crc32c),
expectedCrc32c,
crc32c),
null,
GrpcStatusCode.of(Code.DATA_LOSS),
false),
Expand Down Expand Up @@ -477,6 +480,7 @@ private <R> ApiFuture<R> asyncCleanupAfterFailure(Throwable originalFailure) {

String message =
String.format(
Locale.US,
"Incomplete parallel composite upload cleanup after previous error. Unknown object ids: %s",
failedGsUris);
StorageException storageException = new StorageException(0, message, null);
Expand Down
Loading