Skip to content

Commit 84c8db4

Browse files
authoredJan 23, 2025··
AWS, Core, Delta: Remove redundant charset lookup (#12057)
1 parent be6e9da commit 84c8db4

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed
 

‎aws/src/integration/java/org/apache/iceberg/aws/lakeformation/LakeFormationTestBase.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import static org.assertj.core.api.Assertions.assertThat;
2222

23-
import java.io.UnsupportedEncodingException;
2423
import java.net.URLDecoder;
2524
import java.nio.charset.StandardCharsets;
2625
import java.time.Duration;
@@ -495,8 +494,7 @@ private static void createOrReplacePolicy(
495494
.versionId(DEFAULT_IAM_POLICY_VERSION)
496495
.build())
497496
.policyVersion();
498-
String currentDocument =
499-
URLDecoder.decode(existingPolicy.document(), StandardCharsets.UTF_8.name());
497+
String currentDocument = URLDecoder.decode(existingPolicy.document(), StandardCharsets.UTF_8);
500498
if (Objects.equals(currentDocument, policyDocument)) {
501499
LOG.info(
502500
"Policy {} already exists and policy content did not change. Nothing to do.",
@@ -511,8 +509,6 @@ private static void createOrReplacePolicy(
511509
}
512510
} catch (NoSuchEntityException e) {
513511
createPolicy(policyName, policyDocument);
514-
} catch (UnsupportedEncodingException e) {
515-
throw new RuntimeException(e);
516512
}
517513
}
518514

‎core/src/main/java/org/apache/iceberg/rest/RESTUtil.java

+2-14
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
package org.apache.iceberg.rest;
2020

21-
import java.io.UncheckedIOException;
22-
import java.io.UnsupportedEncodingException;
2321
import java.net.URLDecoder;
2422
import java.net.URLEncoder;
2523
import java.nio.charset.StandardCharsets;
@@ -146,12 +144,7 @@ public static Map<String, String> decodeFormData(String formString) {
146144
*/
147145
public static String encodeString(String toEncode) {
148146
Preconditions.checkArgument(toEncode != null, "Invalid string to encode: null");
149-
try {
150-
return URLEncoder.encode(toEncode, StandardCharsets.UTF_8.name());
151-
} catch (UnsupportedEncodingException e) {
152-
throw new UncheckedIOException(
153-
String.format("Failed to URL encode '%s': UTF-8 encoding is not supported", toEncode), e);
154-
}
147+
return URLEncoder.encode(toEncode, StandardCharsets.UTF_8);
155148
}
156149

157150
/**
@@ -164,12 +157,7 @@ public static String encodeString(String toEncode) {
164157
*/
165158
public static String decodeString(String encoded) {
166159
Preconditions.checkArgument(encoded != null, "Invalid string to decode: null");
167-
try {
168-
return URLDecoder.decode(encoded, StandardCharsets.UTF_8.name());
169-
} catch (UnsupportedEncodingException e) {
170-
throw new UncheckedIOException(
171-
String.format("Failed to URL decode '%s': UTF-8 encoding is not supported", encoded), e);
172-
}
160+
return URLDecoder.decode(encoded, StandardCharsets.UTF_8);
173161
}
174162

175163
/**

‎delta-lake/src/main/java/org/apache/iceberg/delta/BaseSnapshotDeltaLakeTableAction.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.delta.standalone.actions.RemoveFile;
2626
import io.delta.standalone.exceptions.DeltaStandaloneException;
2727
import java.io.File;
28-
import java.io.UnsupportedEncodingException;
2928
import java.net.URI;
3029
import java.net.URLDecoder;
3130
import java.nio.charset.StandardCharsets;
@@ -451,15 +450,11 @@ private void tagCurrentSnapshot(long deltaVersion, Transaction transaction) {
451450
*/
452451
private static String getFullFilePath(String path, String tableRoot) {
453452
URI dataFileUri = URI.create(path);
454-
try {
455-
String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8.name());
456-
if (dataFileUri.isAbsolute()) {
457-
return decodedPath;
458-
} else {
459-
return tableRoot + File.separator + decodedPath;
460-
}
461-
} catch (UnsupportedEncodingException e) {
462-
throw new IllegalArgumentException(String.format("Cannot decode path %s", path), e);
453+
String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8);
454+
if (dataFileUri.isAbsolute()) {
455+
return decodedPath;
456+
} else {
457+
return tableRoot + File.separator + decodedPath;
463458
}
464459
}
465460
}

0 commit comments

Comments
 (0)
Please sign in to comment.