Skip to content

Commit

Permalink
Throw error if file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed May 6, 2023
1 parent 201eb41 commit a8378de
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
Expand Down Expand Up @@ -101,6 +102,7 @@ public ImmutableImage fromBytes(byte[] bytes) throws IOException {
}

public ImmutableImage fromFile(File file) throws IOException {
if (!file.exists()) throw new FileNotFoundException(file.toString());
return load(new FileImageSource(file));
}

Expand All @@ -109,7 +111,7 @@ public ImmutableImage fromFile(String file) throws IOException {
}

public ImmutableImage fromPath(Path path) throws IOException {
return load(new FileImageSource(path));
return fromFile(path.toFile());
}

public ImmutableImage fromResource(String resource) throws IOException {
Expand Down

0 comments on commit a8378de

Please sign in to comment.