@ -20,6 +20,7 @@ import com.teamdev.jxbrowser.net.callback.InterceptUrlRequestCallback;
import org.jetbrains.annotations.NotNull ;
import java.io.InputStream ;
import java.io.UnsupportedEncodingException ;
import java.net.URLDecoder ;
import java.nio.charset.StandardCharsets ;
import java.util.Map ;
@ -80,8 +81,9 @@ public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
protected Optional < UrlRequestJob > generateFileProtocolUrlRequestJob ( Params params , String path ) {
try {
InputStream inputStream = getResourceStream ( path ) ;
String mimeType = MimeType . parseMimeType ( path ) ;
String resourcePath = getResourcePath ( path ) ;
InputStream inputStream = getResourceStream ( resourcePath ) ;
String mimeType = MimeType . parseMimeType ( resourcePath ) ;
byte [ ] bytes ;
if ( isHtml ( mimeType ) ) {
String text = IOUtils . inputStream2String ( inputStream , EncodeConstants . ENCODING_UTF_8 ) ;
@ -104,7 +106,11 @@ public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
* @return 输入流
* @throws Exception IO异常
* /
private InputStream getResourceStream ( String path ) throws Exception {
private InputStream getResourceStream ( String path ) {
return IOUtils . readResource ( path ) ;
}
private static String getResourcePath ( String path ) throws UnsupportedEncodingException {
int index = path . indexOf ( "=" ) ;
if ( index > 0 ) {
path = path . substring ( index + 1 ) ;
@ -115,7 +121,7 @@ public class NxInterceptRequestCallback implements InterceptUrlRequestCallback {
// 通过自定义协议之后的url会自动encode一些中文字符,这里做一个decode,否则会导致路径访问失败
path = URLDecoder . decode ( path , StandardCharsets . UTF_8 . name ( ) ) ;
}
return IOUtils . readResource ( path ) ;
return path ;
}
private boolean isHtml ( String mimeType ) {