Samrat002 commented on code in PR #29127: URL: https://github.com/apache/flink/pull/29127#discussion_r3971463515
########## flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3UriUtils.java: ########## @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.fs.s3native; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.core.fs.Path; + +/** Shared S3 URI handling utilities. */ +@Internal +public final class S3UriUtils { + + private S3UriUtils() {} + + private static final String S3 = "s3://"; + private static final String S3A = "s3a://"; + + /** Extracts the S3 object key from a Flink {@link Path}. */ + public static String extractKey(Path path) { + String pathStr = path.toUri().getPath(); + if (pathStr.startsWith("/")) { + pathStr = pathStr.substring(1); + } + return pathStr; + } + + /** Extracts the S3 bucket name from a Flink {@link Path}. */ + public static String extractBucketName(Path path) { + return path.toUri().getHost(); + } + + /** + * Extracts the bucket name from a raw S3 URI string. + * + * <p>Supports both s3:// and s3a:// schemes. + */ + public static String extractBucket(String s3Uri) { + String uri = s3Uri.replaceFirst(S3A, S3); + int bucketStart = uri.indexOf("://") + 3; Review Comment: addressed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
