rdblue commented on a change in pull request #3288: URL: https://github.com/apache/iceberg/pull/3288#discussion_r731036945
########## File path: aliyun/src/main/java/org/apache/iceberg/aliyun/oss/OSSOutputStream.java ########## @@ -0,0 +1,167 @@ +/* + * 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.iceberg.aliyun.oss; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.model.ObjectMetadata; +import com.aliyun.oss.model.PutObjectRequest; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.UncheckedIOException; +import java.util.Arrays; +import org.apache.iceberg.aliyun.AliyunProperties; +import org.apache.iceberg.exceptions.NotFoundException; +import org.apache.iceberg.io.PositionOutputStream; +import org.apache.iceberg.relocated.com.google.common.base.Joiner; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OSSOutputStream extends PositionOutputStream { + private static final Logger LOG = LoggerFactory.getLogger(OSSOutputStream.class); + private final StackTraceElement[] createStack; + + private final OSS client; + private final OSSURI uri; + private final AliyunProperties aliyunProperties; + + private final File currentStagingFile; + private final OutputStream stream; + private long pos = 0; + private boolean closed = false; + + OSSOutputStream(OSS client, OSSURI uri, AliyunProperties aliyunProperties) { + this.client = client; + this.uri = uri; + this.aliyunProperties = aliyunProperties; + this.createStack = Thread.currentThread().getStackTrace(); + + this.currentStagingFile = newStagingFile(aliyunProperties.ossStagingDirectory()); + this.stream = newStream(currentStagingFile); + } + + private static File newStagingFile(String ossStagingDirectory) { + Preconditions.checkArgument(ossStagingDirectory != null, "Invalid staging directory: null"); Review comment: Minor: should this be moved into the config class so it is validated when properties are parsed instead of each time you get a new staging file? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
