Skip to content

Commit

Permalink
判断文件是否存在
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyuzai committed Jan 4, 2024
1 parent 36d984a commit 15e9cb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.linyuzai.download.core.source.file;

import com.github.linyuzai.download.core.context.DownloadContext;
import com.github.linyuzai.download.core.exception.DownloadException;
import com.github.linyuzai.download.core.options.DownloadOptions;
import com.github.linyuzai.download.core.source.Source;
import com.github.linyuzai.download.core.source.SourceFactory;
Expand All @@ -20,10 +21,14 @@ public boolean support(Object source, DownloadContext context) {

@Override
public Source create(Object source, DownloadContext context) {
File file = (File) source;
if (!file.exists()) {
throw new DownloadException("File not exists: '" + file.getAbsolutePath() + "'");
}
DownloadOptions options = DownloadOptions.get(context);
Charset charset = options.getCharset();
return new FileSource.Builder<>()
.file((File) source)
.file(file)
.charset(charset)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public void error() {

@Download
@GetMapping("/empty")
public void empty() {

public String empty() {
return "file:/empty";
}

@GetMapping("text")
Expand Down

0 comments on commit 15e9cb6

Please sign in to comment.