当前位置: 首页>>代码示例>>Java>>正文


Java OpenForReadResult类代码示例

本文整理汇总了Java中org.apache.cordova.CordovaResourceApi.OpenForReadResult的典型用法代码示例。如果您正苦于以下问题:Java OpenForReadResult类的具体用法?Java OpenForReadResult怎么用?Java OpenForReadResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OpenForReadResult类属于org.apache.cordova.CordovaResourceApi包,在下文中一共展示了OpenForReadResult类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: remapChromeUri

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public Uri remapChromeUri(Uri uri) {
    Uri ret = Uri.parse(replacePatternsInLine(uri.toString()));
    if (ret.getPath().endsWith(".css") || uri.getPath().equals("manifest.json")) {
        Uri fileUri = Uri.parse("file:///android_asset/www" + uri.getPath());
        fileUri = webView.getResourceApi().remapUri(fileUri);
        try {
            OpenForReadResult readResult = webView.getResourceApi().openForRead(fileUri, true);
            try {
                byte[] newData = replaceI18nPlaceholders(readResult.inputStream);
                return Uri.parse("data:text/css;charset=utf-8;base64," + Base64.encode(newData));
            } finally {
                if (readResult != null) {
                    readResult.inputStream.close();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return ret;
}
 
开发者ID:ZachMoreno,项目名称:krakn,代码行数:23,代码来源:ChromeI18n.java

示例2: getStorage

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
private JSONObject getStorage(String namespace) throws IOException, JSONException {
    JSONObject oldMap = new JSONObject();
    CordovaResourceApi resourceApi = webView.getResourceApi();
    try {
        OpenForReadResult readResult = resourceApi.openForRead(getStorageFile(namespace));
        ByteArrayOutputStream readBytes = new ByteArrayOutputStream((int)readResult.length);
        resourceApi.copyResource(readResult, readBytes);
        byte[] bytes = readBytes.toByteArray();
        String content = (new String(bytes)).trim();
        if (content.length() > 0) {
            oldMap = new JSONObject(content);
        }
    } catch (FileNotFoundException e) {
        //Suppress the file not found exception
    }
    return oldMap;
}
 
开发者ID:ZachMoreno,项目名称:krakn,代码行数:18,代码来源:ChromeStorage.java

示例3: shouldInterceptRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (isUrlHarmful(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);
        
        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:31,代码来源:IceCreamCordovaWebViewClient.java

示例4: shouldInterceptLoadRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
    try {
        // Check the against the white-list.
        if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = parentEngine.resourceApi;
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:infil00p,项目名称:cordova-plugin-crosswalk-webview,代码行数:30,代码来源:XWalkCordovaResourceClient.java

示例5: shouldInterceptRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public AmazonWebResourceResponse shouldInterceptRequest(AmazonWebView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (isUrlHarmful(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new AmazonWebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept AmazonWebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);
        
        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new AmazonWebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new AmazonWebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:chrisuehlinger,项目名称:smart-mirror-app,代码行数:31,代码来源:IceCreamCordovaWebViewClient.java

示例6: shouldInterceptLoadRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
    try {
        // Check the against the white-list.
        if ((url.startsWith("http:") || url.startsWith("https:")) && !appView.getWhitelist().isUrlWhiteListed(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:ZachMoreno,项目名称:krakn,代码行数:30,代码来源:XWalkCordovaResourceClient.java

示例7: shouldInterceptLoadRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
    try {
        // Check the against the white-list.
        if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);

        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:ZachMoreno,项目名称:krakn,代码行数:30,代码来源:XWalkCordovaWebViewClient.java

示例8: shouldInterceptRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the white-list.
        if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);
        
        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:ZachMoreno,项目名称:krakn,代码行数:30,代码来源:IceCreamCordovaWebViewClient.java

示例9: shouldInterceptRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
    try {
        // Check the against the white-list.
        if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);
        
        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:Zimtronic,项目名称:posjs2,代码行数:30,代码来源:IceCreamCordovaWebViewClient.java

示例10: shouldInterceptLoadRequest

import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
    try {
        // Check the against the whitelist and lock out access to the WebView directory
        // Changing this will cause problems for your application
        if (isUrlHarmful(url)) {
            LOG.w(TAG, "URL blocked by whitelist: " + url);
            // Results in a 404.
            return new WebResourceResponse("text/plain", "UTF-8", null);
        }

        CordovaResourceApi resourceApi = appView.getResourceApi();
        Uri origUri = Uri.parse(url);
        // Allow plugins to intercept WebView requests.
        Uri remappedUri = resourceApi.remapUri(origUri);
        
        if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
            OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
            return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
        }
        // If we don't need to special-case the request, let the browser load it.
        return null;
    } catch (IOException e) {
        if (!(e instanceof FileNotFoundException)) {
            LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
        }
        // Results in a 404.
        return new WebResourceResponse("text/plain", "UTF-8", null);
    }
}
 
开发者ID:Hanul,项目名称:Wetube,代码行数:31,代码来源:IceCreamCordovaWebViewClient.java


注:本文中的org.apache.cordova.CordovaResourceApi.OpenForReadResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。