You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
2.5 KiB
115 lines
2.5 KiB
package com.fanruan.fs.s3.repository.core; |
|
|
|
import com.amazonaws.services.s3.AmazonS3; |
|
import com.fanruan.api.log.LogKit; |
|
import com.fr.io.repository.FineFileEntry; |
|
import com.fr.io.repository.base.BaseResourceRepository; |
|
import com.fr.stable.Filter; |
|
import com.fr.workspace.resource.ResourceIOException; |
|
|
|
import java.io.InputStream; |
|
import java.net.URL; |
|
|
|
/** |
|
* @author richie |
|
* @version 10.0 |
|
* Created by richie on 2020/6/15 |
|
*/ |
|
public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
private AmazonS3 s3; |
|
private String bucket; |
|
|
|
public S3ResourceRepository(String repoName, String workRoot, AmazonS3 s3, String bucket) { |
|
super(repoName, workRoot); |
|
this.s3 = s3; |
|
this.bucket = bucket; |
|
} |
|
|
|
|
|
@Override |
|
public String getSeparator() { |
|
return "/"; |
|
} |
|
|
|
@Override |
|
public FineFileEntry getEntry(String path) { |
|
return null; |
|
} |
|
|
|
@Override |
|
public FineFileEntry[] listEntry(String dir) { |
|
return new FineFileEntry[0]; |
|
} |
|
|
|
@Override |
|
public URL getResource(String path) { |
|
return null; |
|
} |
|
|
|
@Override |
|
public InputStream read(String filePath) throws ResourceIOException { |
|
return null; |
|
} |
|
|
|
@Override |
|
public void write(String path, byte[] data) { |
|
|
|
} |
|
|
|
@Override |
|
public boolean createFile(String path) { |
|
return false; |
|
} |
|
|
|
@Override |
|
public boolean createDirectory(String path) { |
|
return false; |
|
} |
|
|
|
@Override |
|
public boolean delete(String path) { |
|
try { |
|
s3.deleteObject(bucket, path); |
|
} catch (Exception e) { |
|
LogKit.error(e.getMessage(), e); |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
@Override |
|
public boolean exist(String path) { |
|
return s3.getObject(bucket, path) != null; |
|
} |
|
|
|
@Override |
|
public String[] list(String dir, final Filter<String> filter) { |
|
return new String[0]; |
|
} |
|
|
|
@Override |
|
public boolean isDirectory(String path) { |
|
return false; |
|
} |
|
|
|
@Override |
|
public long lastModified(String path) { |
|
return s3.getObject(bucket, path).getObjectMetadata().getLastModified().getTime(); |
|
} |
|
|
|
@Override |
|
public long length(String path) { |
|
return s3.getObject(bucket, path).getObjectMetadata().getContentLength(); |
|
} |
|
|
|
@Override |
|
public void shutDown() { |
|
s3.shutdown(); |
|
} |
|
|
|
@Override |
|
public String getIdentity() { |
|
return S3RepositoryFactory.IDENTITY; |
|
} |
|
}
|
|
|