ClaireLytt commented on code in PR #12297:
URL: https://github.com/apache/seatunnel/pull/12297#discussion_r4052615432


##########
seatunnel-connectors-v2/connector-file/connector-file-smb/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/smb/system/SmbInputStream.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.file.smb.system;
+
+import org.apache.hadoop.fs.FSInputStream;
+import org.apache.hadoop.fs.FileSystem;
+
+import com.hierynomus.smbj.share.DiskShare;
+import com.hierynomus.smbj.share.File;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class SmbInputStream extends FSInputStream {
+
+    private InputStream wrappedStream;
+    private File smbFile;
+    private DiskShare diskShare;
+    private FileSystem.Statistics stats;
+    private boolean closed;
+    private long pos;
+
+    SmbInputStream(
+            InputStream stream, File smbFile, DiskShare diskShare, 
FileSystem.Statistics stats) {
+        if (stream == null) {
+            throw new IllegalArgumentException("Null InputStream");
+        }
+        this.wrappedStream = stream;
+        this.smbFile = smbFile;
+        this.diskShare = diskShare;
+        this.stats = stats;
+        this.pos = 0;
+        this.closed = false;
+    }
+
+    @Override
+    public void seek(long position) throws IOException {
+        throw new IOException("Seek not supported");

Review Comment:
   done



##########
seatunnel-connectors-v2/connector-file/connector-file-smb/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/smb/system/SmbFileSystem.java:
##########
@@ -0,0 +1,550 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.file.smb.system;
+
+import 
org.apache.seatunnel.connectors.seatunnel.file.hadoop.FileStatusListingSession;
+import 
org.apache.seatunnel.connectors.seatunnel.file.hadoop.StreamingFileSystem;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.hadoop.util.Progressable;
+
+import com.hierynomus.msdtyp.AccessMask;
+import com.hierynomus.msfscc.FileAttributes;
+import com.hierynomus.msfscc.fileinformation.FileAllInformation;
+import com.hierynomus.msfscc.fileinformation.FileIdBothDirectoryInformation;
+import com.hierynomus.mssmb2.SMB2CreateDisposition;
+import com.hierynomus.mssmb2.SMB2ShareAccess;
+import com.hierynomus.smbj.SMBClient;
+import com.hierynomus.smbj.SmbConfig;
+import com.hierynomus.smbj.auth.AuthenticationContext;
+import com.hierynomus.smbj.connection.Connection;
+import com.hierynomus.smbj.session.Session;
+import com.hierynomus.smbj.share.DiskShare;
+import com.hierynomus.smbj.share.File;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class SmbFileSystem extends FileSystem implements StreamingFileSystem {
+
+    public static final String FS_SMB_HOST = "fs.smb.host";
+    public static final String FS_SMB_PORT = "fs.smb.port";
+    public static final String FS_SMB_USER = "fs.smb.user";
+    public static final String FS_SMB_PASSWORD = "fs.smb.password";
+    public static final String FS_SMB_DOMAIN = "fs.smb.domain";
+    public static final String FS_SMB_SHARE = "fs.smb.share";
+
+    private static final int DEFAULT_SMB_PORT = 445;
+    private static final int DEFAULT_BLOCK_SIZE = 4 * 1024;
+
+    private URI uri;
+    private SMBClient client;
+    private String host;
+    private int port;
+    private String user;
+    private String password;
+    private String domain;
+    private String share;
+
+    @Override
+    public void initialize(URI uri, Configuration conf) throws IOException {
+        super.initialize(uri, conf);
+        this.uri = uri;
+
+        this.host = conf.get(FS_SMB_HOST, uri.getHost());
+        this.port =
+                conf.getInt(FS_SMB_PORT, uri.getPort() == -1 ? 
DEFAULT_SMB_PORT : uri.getPort());
+        this.user = conf.get(FS_SMB_USER);
+        this.password = conf.get(FS_SMB_PASSWORD, "");
+        this.domain = conf.get(FS_SMB_DOMAIN, "");
+        this.share = conf.get(FS_SMB_SHARE, "");
+
+        if (host == null || host.isEmpty()) {
+            throw new IOException("SMB host is not specified");
+        }
+        if (user == null || user.isEmpty()) {
+            throw new IOException("SMB user is not specified");
+        }
+        if (share == null || share.isEmpty()) {
+            throw new IOException("SMB share is not specified");
+        }
+
+        SmbConfig smbConfig = SmbConfig.builder().build();
+        this.client = new SMBClient(smbConfig);
+        setConf(conf);
+    }
+
+    @Override
+    public String getScheme() {
+        return "smb";
+    }
+
+    @Override
+    public URI getUri() {
+        return uri;
+    }
+
+    private DiskShare connectShare() throws IOException {
+        try {
+            Connection connection = client.connect(host, port);
+            AuthenticationContext ac =
+                    new AuthenticationContext(user, password.toCharArray(), 
domain);
+            Session session = connection.authenticate(ac);
+            return (DiskShare) session.connectShare(share);

Review Comment:
   done



-- 
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]

Reply via email to