Skip to content

Commit

Permalink
AWS, Core, Delta: Remove redundant charset lookup (#12057)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr authored Jan 23, 2025
1 parent be6e9da commit 84c8db4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

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

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
Expand Down Expand Up @@ -495,8 +494,7 @@ private static void createOrReplacePolicy(
.versionId(DEFAULT_IAM_POLICY_VERSION)
.build())
.policyVersion();
String currentDocument =
URLDecoder.decode(existingPolicy.document(), StandardCharsets.UTF_8.name());
String currentDocument = URLDecoder.decode(existingPolicy.document(), StandardCharsets.UTF_8);
if (Objects.equals(currentDocument, policyDocument)) {
LOG.info(
"Policy {} already exists and policy content did not change. Nothing to do.",
Expand All @@ -511,8 +509,6 @@ private static void createOrReplacePolicy(
}
} catch (NoSuchEntityException e) {
createPolicy(policyName, policyDocument);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

Expand Down
16 changes: 2 additions & 14 deletions core/src/main/java/org/apache/iceberg/rest/RESTUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.iceberg.rest;

import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -146,12 +144,7 @@ public static Map<String, String> decodeFormData(String formString) {
*/
public static String encodeString(String toEncode) {
Preconditions.checkArgument(toEncode != null, "Invalid string to encode: null");
try {
return URLEncoder.encode(toEncode, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new UncheckedIOException(
String.format("Failed to URL encode '%s': UTF-8 encoding is not supported", toEncode), e);
}
return URLEncoder.encode(toEncode, StandardCharsets.UTF_8);
}

/**
Expand All @@ -164,12 +157,7 @@ public static String encodeString(String toEncode) {
*/
public static String decodeString(String encoded) {
Preconditions.checkArgument(encoded != null, "Invalid string to decode: null");
try {
return URLDecoder.decode(encoded, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new UncheckedIOException(
String.format("Failed to URL decode '%s': UTF-8 encoding is not supported", encoded), e);
}
return URLDecoder.decode(encoded, StandardCharsets.UTF_8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.delta.standalone.actions.RemoveFile;
import io.delta.standalone.exceptions.DeltaStandaloneException;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -451,15 +450,11 @@ private void tagCurrentSnapshot(long deltaVersion, Transaction transaction) {
*/
private static String getFullFilePath(String path, String tableRoot) {
URI dataFileUri = URI.create(path);
try {
String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8.name());
if (dataFileUri.isAbsolute()) {
return decodedPath;
} else {
return tableRoot + File.separator + decodedPath;
}
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(String.format("Cannot decode path %s", path), e);
String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8);
if (dataFileUri.isAbsolute()) {
return decodedPath;
} else {
return tableRoot + File.separator + decodedPath;
}
}
}

0 comments on commit 84c8db4

Please sign in to comment.