Skip to content

Commit

Permalink
fixed imageResource processing on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Oct 3, 2023
1 parent 7ee44a9 commit ab9349d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -56,8 +57,8 @@ void initializer(Map<String, Object> root, TypeElement clientBundle, ExecutableE
definition.put("name", method.getSimpleName().toString());

URL resource = getResource(method, defaultExtensions.value());
Path imagePath = Paths.get(resource.getPath());
try {
Path imagePath = Paths.get(resource.toURI());
String mimeType = String.format("data:%s;base64,", Files.probeContentType(imagePath));
setSize(method, imagePath, definition);

Expand All @@ -76,7 +77,9 @@ void initializer(Map<String, Object> root, TypeElement clientBundle, ExecutableE
throw new GenerationException(e);
}
} catch (IOException e) {
throw new GenerationException("Unable to determine mime type for " + imagePath, e);
throw new GenerationException("Unable to determine mime type for " + resource, e);
} catch (URISyntaxException e) {
throw new GenerationException("Unable to determine mime type for " + resource, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Test;

Expand Down Expand Up @@ -56,11 +58,13 @@ public void testNoSource() {
}

private String readFileAsString(String fileName) {
String file = this.getClass().getResource(fileName).getPath();
try {
return new String(Files.readAllBytes(Paths.get(file)));
Path file = Paths.get(this.getClass().getResource(fileName).toURI());
return new String(Files.readAllBytes(file));
} catch (IOException e) {
throw new RuntimeException(e);
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit ab9349d

Please sign in to comment.