feat():测试

yuan
yuan 2024-09-06 10:37:26 +08:00
parent 7df2263bb2
commit ee235e9f68
2 changed files with 9 additions and 29 deletions

View File

@ -39,21 +39,7 @@ public class FilesCompilerLoad {
System.out.println("编译失败"); System.out.println("编译失败");
} }
try { ALiYunUpload.uploadClassFiles(fileName,"/home/lib/com/muyu/generate/"+fileName+ MethodSuffix.CLASSSUFFIX);
String classContent = "";
BufferedReader bufferedReader = new BufferedReader(new FileReader("/home/lib/com/muyu/generate/"+fileName+ MethodSuffix.CLASSSUFFIX));
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
classContent += line;
}
bufferedReader.close();
log.info("文件存储:" + fileName + MethodSuffix.CLASSSUFFIX);
ALiYunUpload.uploadClassFiles(classContent,fileName);
} catch (IOException e) {
e.printStackTrace();
}
return Result.success(); return Result.success();
} }
@ -63,7 +49,7 @@ public class FilesCompilerLoad {
try { try {
// class文件路径 // class文件路径
String externalClassFilePath = "/home/lib/com/muyu/generate/"+fileName + MethodSuffix.CLASSSUFFIX; String externalClassFilePath = "/home/lib/com/muyu/generate/"+fileName + MethodSuffix.CLASSSUFFIX;
log.info(externalClassFilePath); log.info("class文件路径:[{}]",externalClassFilePath);
Path path = Paths.get(externalClassFilePath); Path path = Paths.get(externalClassFilePath);
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/')); String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));

View File

@ -7,8 +7,10 @@ import com.muyu.common.core.domain.Result;
import com.muyu.compile.FilesCompilerLoad; import com.muyu.compile.FilesCompilerLoad;
import com.muyu.constant.MethodSuffix; import com.muyu.constant.MethodSuffix;
import com.muyu.load.OSSFileLoad; import com.muyu.load.OSSFileLoad;
import lombok.extern.log4j.Log4j2;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** /**
@ -18,6 +20,7 @@ import java.nio.charset.StandardCharsets;
* @nameALiYunUpload * @nameALiYunUpload
* @Date2024/8/30 7:05 * @Date2024/8/30 7:05
*/ */
@Log4j2
public class ALiYunUpload { public class ALiYunUpload {
// Endpoint以华东1杭州为例其它Region请按实际情况填写 // Endpoint以华东1杭州为例其它Region请按实际情况填写
@ -65,9 +68,7 @@ public class ALiYunUpload {
} }
public static Result<Object> uploadClassFiles(String classContent, String fileName) { public static Result<Object> uploadClassFiles(String fileName,String filePath) {
System.out.println(classContent);
System.out.println(fileName+ MethodSuffix.CLASSSUFFIX); System.out.println(fileName+ MethodSuffix.CLASSSUFFIX);
@ -77,21 +78,14 @@ public class ALiYunUpload {
String objectName = "build/version/class/"+fileName+ MethodSuffix.CLASSSUFFIX; String objectName = "build/version/class/"+fileName+ MethodSuffix.CLASSSUFFIX;
try { try {
// 将内容转换为字节数组输入流
ByteArrayInputStream inputStream = new ByteArrayInputStream(classContent.getBytes(StandardCharsets.UTF_8));
// 构造上传请求 ossClient.putObject(bucketName, objectName, new File(filePath));
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
// 执行上传操作 log.info("文件[{}]存储成功",fileName+ MethodSuffix.CLASSSUFFIX);
ossClient.putObject(putObjectRequest);
OSSFileLoad.streamingClassDownload(fileName);
System.out.println(fileName+ MethodSuffix.CLASSSUFFIX);
return Result.success(null,"文件"+fileName+".class"+"存储成功"); return Result.success(null,"文件"+fileName+".class"+"存储成功");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.info("文件[{}]存储失败",fileName+ MethodSuffix.CLASSSUFFIX+"错误信息:[{}]"+e.getMessage());
return Result.error(null,"文件"+fileName+".class"+"存储失败"); return Result.error(null,"文件"+fileName+".class"+"存储失败");
} finally { } finally {
// 关闭OSSClient // 关闭OSSClient