123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package com.fdkankan.fyun.face;
- import com.fdkankan.fyun.config.FYunFileConfig;
- import com.fdkankan.fyun.constant.FYunConstants;
- import com.fdkankan.fyun.model.StreamGobbler;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URL;
- import java.util.List;
- import java.util.Map;
- @Component
- public abstract class AbstractFYunFileService implements FYunFileServiceInterface {
- private Logger log = LoggerFactory.getLogger(this.getClass().getName());
- @Autowired
- public FYunFileConfig fYunFileConfig;
- @Autowired
- public FYunConstants fYunConstants;
- public String getFyunType(){
- return fYunFileConfig.getFyunType();
- }
- @Override
- public String uploadFile(byte[] data, String remoteFilePath) {
- uploadFile(fYunFileConfig.getBucket(), data, remoteFilePath);
- return fYunFileConfig.getHost().concat(remoteFilePath);
- }
- @Override
- public String uploadFile(String filePath, String remoteFilePath) {
- uploadFile(fYunFileConfig.getBucket(), filePath, remoteFilePath);
- return fYunFileConfig.getHost().concat(remoteFilePath);
- }
- @Override
- public String uploadFile(String filePath, String remoteFilePath, Map<String, String> headers) {
- uploadFile(fYunFileConfig.getBucket(), filePath, remoteFilePath, headers);
- return fYunFileConfig.getHost().concat(remoteFilePath);
- }
- @Override
- public String uploadFile(InputStream inputStream, String remoteFilePath) {
- uploadFile(fYunFileConfig.getBucket(), inputStream, remoteFilePath);
- return fYunFileConfig.getHost().concat(remoteFilePath);
- }
- @Override
- public String uploadFileByCommand(String filePath, String remoteFilePath) {
- uploadFileByCommand(fYunFileConfig.getBucket(), filePath, remoteFilePath);
- return fYunFileConfig.getHost().concat(remoteFilePath);
- }
- @Override
- public void downloadFileByCommand(String filePath, String remoteFilePath) {
- downloadFileByCommand(fYunFileConfig.getBucket(),filePath,remoteFilePath);
- }
- @Override
- public void downloadByCommand(String filePath, String remoteFilePath, boolean isDir) {
- downloadByCommand(fYunFileConfig.getBucket(),filePath,remoteFilePath, isDir);
- }
- @Override
- public void deleteFile(String remoteFilePath) throws IOException {
- deleteFile(fYunFileConfig.getBucket(), remoteFilePath);
- }
- @Override
- public void deleteFolder(String remoteFolderPath) {
- deleteFolder(fYunFileConfig.getBucket(), remoteFolderPath);
- }
- @Override
- public void uploadMulFiles(Map<String, String> filepaths) {
- uploadMulFiles(fYunFileConfig.getBucket(), filepaths);
- }
- @Override
- public List<String> listRemoteFiles(String sourcePath) {
- return listRemoteFiles(fYunFileConfig.getBucket(), sourcePath);
- }
- public void copyFileInBucket(String sourcePath, String targetPath) {
- copyFileBetweenBucket(fYunFileConfig.getBucket(), sourcePath, fYunFileConfig.getBucket(), targetPath);
- }
- public void copyFileInBucketParallel(String sourcePath, String targetPath) {
- copyFileBetweenBucketParallel(fYunFileConfig.getBucket(), sourcePath, fYunFileConfig.getBucket(), targetPath);
- }
- @Override
- public void copyFileToArchive(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath) {
- copyFileToArchive(sourceBucketName, sourcePath, targetBucketName, targetPath);
- }
- public void copyFileInBucket(String bucket, String sourcePath, String targetPath) {
- copyFileBetweenBucket(bucket, sourcePath, bucket, targetPath);
- }
- @Override
- public void copyFileBetweenBucket(String sourcePath, String targetBucketName, String targetPath) {
- copyFileBetweenBucket(fYunFileConfig.getBucket(), sourcePath, targetBucketName, targetPath);
- }
- @Override
- public void copyFilesBetweenBucket(String targetBucketName, Map<String, String> pathMap) {
- copyFilesBetweenBucket(fYunFileConfig.getBucket(), targetBucketName, pathMap);
- }
- @Override
- public String getFileContent(String remoteFilePath) {
- return getFileContent(fYunFileConfig.getBucket(), remoteFilePath);
- }
- @Override
- public boolean fileExist(String objectName) {
- return fileExist(fYunFileConfig.getBucket(), objectName);
- }
- @Override
- public void downloadFile(String remoteFilePath, String localPath) {
- downloadFile(fYunFileConfig.getBucket(), remoteFilePath, localPath);
- }
- public void callshell(String command){
- try {
- Long start = System.currentTimeMillis();
- Process process = Runtime.getRuntime().exec(command);
- StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR");
- errorGobbler.start();
- StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");
- outGobbler.start();
- process.waitFor();
- log.info("脚本{}执行完毕,用时:{}ms",command,System.currentTimeMillis()-start);
- } catch (Exception e) {
- log.error("调用脚本文件上传下载失败, command : " + command, e);
- }
- }
- @Override
- public URL getPresignedUrl(String url) {
- return getPresignedUrl(fYunFileConfig.getBucket(), url);
- }
- @Override
- public long getSubFileNums(String url) {
- return getSubFileNums(fYunFileConfig.getBucket(), url);
- }
- }
|