Skip to content

Commit

Permalink
add: fix jpg to png bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarrettluo committed Dec 28, 2023
1 parent 39044f9 commit 5c36d61
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/jiaruiblog/enums/DocType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jiaruiblog.enums;

import org.apache.commons.lang3.StringUtils;

/**
* @Author Jarrett Luo
* @Date 2022/10/24 11:39
Expand All @@ -25,6 +27,9 @@ public enum DocType {
UNKNOWN;

public static DocType getDocType(String suffixName) {
if (StringUtils.isNoneBlank(suffixName)) {
suffixName = StringUtils.toRootLowerCase(suffixName);
}
switch (suffixName) {
case ".pdf":
return PDF;
Expand All @@ -37,6 +42,9 @@ public static DocType getDocType(String suffixName) {
case ".md":
return MD;
case ".html":
case ".xhtml":
case ".xht":
case ".htm":
return HTML;
case ".txt":
return TXT;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/jiaruiblog/task/executor/PicExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;

/**
* @ClassName PicExecutor
Expand Down
37 changes: 17 additions & 20 deletions src/main/java/com/jiaruiblog/task/executor/TxtExecutor.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.jiaruiblog.task.executor;

import com.jiaruiblog.entity.FileDocument;
import com.jiaruiblog.entity.FileObj;
import com.jiaruiblog.task.data.TaskData;
import com.jiaruiblog.task.exception.TaskRunException;

import java.io.IOException;
import java.io.InputStream;
import java.io.*;

/**
* @ClassName TxtExecutor
Expand All @@ -19,7 +15,22 @@ public class TxtExecutor extends TaskExecutor{

@Override
protected void readText(InputStream is, String textFilePath) throws IOException {
// no action
InputStreamReader inputStreamReader = new InputStreamReader(is);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuffer stringBuffer = new StringBuffer();
String content;
while ((content = bufferedReader.readLine()) != null) {
stringBuffer.append(content);
}
bufferedReader.close();
inputStreamReader.close();
is.close();

File file = new File(textFilePath);
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));

bufferedWriter.write(stringBuffer.toString());
bufferedWriter.close();
}

@Override
Expand All @@ -31,18 +42,4 @@ protected void makeThumb(InputStream is, String picPath) throws IOException {
protected void makePreviewFile(InputStream is, TaskData taskData) {
// no action
}

@Override
public void uploadFileToEs(InputStream is, FileDocument fileDocument, TaskData taskData) {
try {
FileObj fileObj = new FileObj();
fileObj.setId(fileDocument.getMd5());
fileObj.setName(fileDocument.getName());
fileObj.setType(fileDocument.getContentType());
fileObj.readFile(is);
this.upload(fileObj);
} catch (IOException | TaskRunException e) {
throw new TaskRunException("存入es的过程中报错了", e);
}
}
}

0 comments on commit 5c36d61

Please sign in to comment.