List of usage examples for org.apache.commons.io Charsets UTF_8
Charset UTF_8
To view the source code for org.apache.commons.io Charsets UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:org.opendatakit.common.android.utilities.WebUtils.java
/** * Common method for returning a parsed xml document given a url and the http * context and client objects involved in the web connection. * * @param urlString/* w w w . ja v a 2 s . c o m*/ * @param localContext * @param httpclient * @return */ public DocumentFetchResult getXmlDocument(String appName, String urlString, HttpContext localContext, HttpClient httpclient, String auth) { URI u = null; try { URL url = new URL(URLDecoder.decode(urlString, CharEncoding.UTF_8)); u = url.toURI(); } catch (Exception e) { e.printStackTrace(); return new DocumentFetchResult(e.getLocalizedMessage() // + app.getString(R.string.while_accessing) + urlString); + ("while accessing") + urlString, 0); } // set up request... HttpGet req = createOpenRosaHttpGet(u, auth); HttpResponse response = null; try { response = httpclient.execute(req, localContext); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (statusCode != 200) { discardEntityBytes(response); String webError = response.getStatusLine().getReasonPhrase() + " (" + statusCode + ")"; return new DocumentFetchResult(u.toString() + " responded with: " + webError, statusCode); } if (entity == null) { String error = "No entity body returned from: " + u.toString(); WebLogger.getLogger(appName).e(t, error); return new DocumentFetchResult(error, 0); } if (!entity.getContentType().getValue().toLowerCase(Locale.ENGLISH) .contains(WebUtils.HTTP_CONTENT_TYPE_TEXT_XML)) { discardEntityBytes(response); String error = "ContentType: " + entity.getContentType().getValue() + " returned from: " + u.toString() + " is not text/xml. This is often caused a network proxy. Do you need to login to your network?"; WebLogger.getLogger(appName).e(t, error); return new DocumentFetchResult(error, 0); } // parse response Document doc = null; try { InputStream is = null; InputStreamReader isr = null; try { is = entity.getContent(); isr = new InputStreamReader(is, Charsets.UTF_8); doc = new Document(); KXmlParser parser = new KXmlParser(); parser.setInput(isr); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); doc.parse(parser); isr.close(); isr = null; } finally { if (isr != null) { try { // ensure stream is consumed... final long count = 1024L; while (isr.skip(count) == count) ; } catch (Exception e) { // no-op } try { isr.close(); } catch (Exception e) { // no-op } } if (is != null) { try { is.close(); } catch (Exception e) { // no-op } } } } catch (Exception e) { String error = "Parsing failed with " + e.getMessage() + "while accessing " + u.toString(); WebLogger.getLogger(appName).e(t, error); WebLogger.getLogger(appName).printStackTrace(e); return new DocumentFetchResult(error, 0); } boolean isOR = false; Header[] fields = response.getHeaders(WebUtils.OPEN_ROSA_VERSION_HEADER); if (fields != null && fields.length >= 1) { isOR = true; boolean versionMatch = false; boolean first = true; StringBuilder b = new StringBuilder(); for (Header h : fields) { if (WebUtils.OPEN_ROSA_VERSION.equals(h.getValue())) { versionMatch = true; break; } if (!first) { b.append("; "); } first = false; b.append(h.getValue()); } if (!versionMatch) { WebLogger.getLogger(appName).w(t, WebUtils.OPEN_ROSA_VERSION_HEADER + " unrecognized version(s): " + b.toString()); } } return new DocumentFetchResult(doc, isOR); } catch (Exception e) { ClientConnectionManagerFactory.get(appName).clearHttpConnectionManager(); WebLogger.getLogger(appName).printStackTrace(e); String cause; if (e.getCause() != null) { cause = e.getCause().getMessage(); } else { cause = e.getMessage(); } String error = "Error: " + cause + " while accessing " + u.toString(); WebLogger.getLogger(appName).w(t, error); return new DocumentFetchResult(error, 0); } }
From source file:org.opendatakit.services.legacy.utilities.WebUtils.java
/** * Common method for returning a parsed xml document given a url and the http * context and client objects involved in the web connection. * * @param urlString/*from w w w .j a v a 2 s . c o m*/ * @param localContext * @param httpclient * @return */ public DocumentFetchResult getXmlDocument(String appName, String urlString, HttpContext localContext, HttpClient httpclient, String auth) { URI u = null; try { URL url = new URL(URLDecoder.decode(urlString, CharEncoding.UTF_8)); u = url.toURI(); } catch (Exception e) { e.printStackTrace(); return new DocumentFetchResult(e.getLocalizedMessage() // + app.getString(R.string.while_accessing) + urlString); + ("while accessing") + urlString, 0); } // set up request... HttpGet req = createOpenRosaHttpGet(u, auth); HttpResponse response = null; try { response = httpclient.execute(req, localContext); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (statusCode != 200) { discardEntityBytes(response); String webError = response.getStatusLine().getReasonPhrase() + " (" + statusCode + ")"; return new DocumentFetchResult(u.toString() + " responded with: " + webError, statusCode); } if (entity == null) { String error = "No entity body returned from: " + u.toString(); WebLogger.getLogger(appName).e(t, error); return new DocumentFetchResult(error, 0); } if (!entity.getContentType().getValue().toLowerCase(Locale.ENGLISH) .contains(WebUtils.HTTP_CONTENT_TYPE_TEXT_XML)) { discardEntityBytes(response); String error = "ContentType: " + entity.getContentType().getValue() + " returned from: " + u.toString() + " is not text/xml. This is often caused a network proxy. Do you need to login to your network?"; WebLogger.getLogger(appName).e(t, error); return new DocumentFetchResult(error, 0); } // parse response Document doc = null; try { InputStream is = null; InputStreamReader isr = null; InputSource iss = null; try { is = entity.getContent(); isr = new InputStreamReader(is, Charsets.UTF_8); iss = new InputSource(isr); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(iss); isr.close(); isr = null; } catch (Exception e) { WebLogger.getLogger(appName).printStackTrace(e); throw e; } finally { if (isr != null) { try { // ensure stream is consumed... final long count = 1024L; while (isr.skip(count) == count) ; } catch (Exception e) { // no-op } try { isr.close(); } catch (Exception e) { // no-op } } if (is != null) { try { is.close(); } catch (Exception e) { // no-op } } } } catch (Exception e) { String error = "Parsing failed with " + e.getMessage() + "while accessing " + u.toString(); WebLogger.getLogger(appName).e(t, error); WebLogger.getLogger(appName).printStackTrace(e); return new DocumentFetchResult(error, 0); } boolean isOR = false; Header[] fields = response.getHeaders(WebUtils.OPEN_ROSA_VERSION_HEADER); if (fields != null && fields.length >= 1) { isOR = true; boolean versionMatch = false; boolean first = true; StringBuilder b = new StringBuilder(); for (Header h : fields) { if (WebUtils.OPEN_ROSA_VERSION.equals(h.getValue())) { versionMatch = true; break; } if (!first) { b.append("; "); } first = false; b.append(h.getValue()); } if (!versionMatch) { WebLogger.getLogger(appName).w(t, WebUtils.OPEN_ROSA_VERSION_HEADER + " unrecognized version(s): " + b.toString()); } } return new DocumentFetchResult(doc, isOR); } catch (Exception e) { WebLogger.getLogger(appName).printStackTrace(e); String cause; if (e.getCause() != null) { cause = e.getCause().getMessage(); } else { cause = e.getMessage(); } String error = "Error: " + cause + " while accessing " + u.toString(); WebLogger.getLogger(appName).w(t, error); return new DocumentFetchResult(error, 0); } }
From source file:org.opendatakit.utilities.LocalizationUtils.java
private static synchronized void loadTranslations(String appName, String tableId) throws IOException { if (savedAppName != null && !savedAppName.equals(appName)) { clearTranslations();//from w w w .jav a2 s . co m } savedAppName = appName; TypeReference<HashMap<String, Object>> ref = new TypeReference<HashMap<String, Object>>() { }; if (commonDefinitions == null) { File commonFile = new File(ODKFileUtils.getCommonDefinitionsFile(appName)); if (commonFile.exists() && commonFile.isFile()) { InputStream stream = null; BufferedReader reader = null; String value; try { stream = new FileInputStream(commonFile); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); } else { reader = new BufferedReader(new InputStreamReader(stream, Charsets.UTF_8)); } int ch = reader.read(); while (ch != -1 && ch != '{') { ch = reader.read(); } StringBuilder b = new StringBuilder(); b.append((char) ch); ch = reader.read(); while (ch != -1) { b.append((char) ch); ch = reader.read(); } reader.close(); stream.close(); value = b.toString().trim(); if (value.endsWith(";")) { value = value.substring(0, value.length() - 1).trim(); } } finally { if (reader != null) { reader.close(); } else if (stream != null) { stream.close(); } } try { commonDefinitions = ODKFileUtils.mapper.readValue(value, ref); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); throw new IllegalStateException("Unable to read commonDefinitions.js file"); } } } if (tableId != null) { File tableFile = new File(ODKFileUtils.getTableSpecificDefinitionsFile(appName, tableId)); if (!tableFile.exists()) { tableSpecificDefinitionsMap.remove(tableId); } else { // assume it is current if it exists if (tableSpecificDefinitionsMap.containsKey(tableId)) { return; } InputStream stream = null; BufferedReader reader = null; try { stream = new FileInputStream(tableFile); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); } else { reader = new BufferedReader(new InputStreamReader(stream, Charsets.UTF_8)); } reader.mark(1); int ch = reader.read(); while (ch != -1 && ch != '{') { reader.mark(1); ch = reader.read(); } reader.reset(); Map<String, Object> tableSpecificTranslations = ODKFileUtils.mapper.readValue(reader, ref); if (tableSpecificTranslations != null) { tableSpecificDefinitionsMap.put(tableId, tableSpecificTranslations); } } finally { if (reader != null) { reader.close(); } else if (stream != null) { stream.close(); } } } } }
From source file:org.opendatakit.utilities.ODKFileUtils.java
/** * TODO this is almost identical to checkOdkAppVersion * * @param appName the app name * @param odkAppVersionFile the file that contains the installed version * @param apkVersion the version to overwrite odkAppVerisonFile with *///from w ww.j av a 2s. c om private static void writeConfiguredOdkAppVersion(String appName, String odkAppVersionFile, String apkVersion) { File versionFile = new File(getDataFolder(appName), odkAppVersionFile); if (!versionFile.exists()) { if (!versionFile.getParentFile().mkdirs()) { //throw new RuntimeException("Failed mkdirs on " + versionFile.getPath()); WebLogger.getLogger(appName).e(TAG, "Failed mkdirs on " + versionFile.getParentFile().getPath()); } } FileOutputStream fs = null; OutputStreamWriter w = null; BufferedWriter bw = null; try { fs = new FileOutputStream(versionFile, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { w = new OutputStreamWriter(fs, StandardCharsets.UTF_8); } else { //noinspection deprecation w = new OutputStreamWriter(fs, Charsets.UTF_8); } bw = new BufferedWriter(w); bw.write(apkVersion); bw.write("\n"); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); } finally { if (bw != null) { try { bw.flush(); bw.close(); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); } } if (w != null) { try { w.close(); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); } } if (fs != null) { try { fs.close(); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); } } } }
From source file:org.opendatakit.utilities.ODKFileUtils.java
/** * TODO this is almost identical to writeConfiguredOdkAppVersion * * @param appName the app name * @param odkAppVersionFile the file that contains the installed app version * @param apkVersion the version to match against * @return whether the passed apk version matches the version in the file *///from www.j a v a2 s . c o m private static boolean checkOdkAppVersion(String appName, String odkAppVersionFile, String apkVersion) { File versionFile = new File(getDataFolder(appName), odkAppVersionFile); if (!versionFile.exists()) { return false; } String versionLine = null; FileInputStream fs = null; InputStreamReader r = null; BufferedReader br = null; try { fs = new FileInputStream(versionFile); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { r = new InputStreamReader(fs, StandardCharsets.UTF_8); } else { //noinspection deprecation r = new InputStreamReader(fs, Charsets.UTF_8); } br = new BufferedReader(r); versionLine = br.readLine(); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); return false; } finally { if (br != null) { try { br.close(); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); } } if (r != null) { try { r.close(); } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); } } try { if (fs != null) { fs.close(); } } catch (IOException e) { WebLogger.getLogger(appName).printStackTrace(e); } } String[] versionRange = versionLine.split(";"); for (String version : versionRange) { if (version.trim().equals(apkVersion)) { return true; } } return false; }
From source file:org.protelis.test.TestLanguage.java
private static void testFile(final String file, final int runs) { final Object execResult = runProgram(file, runs); final InputStream is = TestLanguage.class.getResourceAsStream(file); try {/*from w ww . ja v a2 s. c o m*/ final String test = IOUtils.toString(is, Charsets.UTF_8); final Matcher extractor = EXTRACT_RESULT.matcher(test); if (extractor.find()) { String result = extractor.group(ML_NAME); if (result == null) { result = extractor.group(SL_NAME); } final String toCheck = CYCLE.matcher(result).replaceAll(Integer.toString(runs)); final ProtelisVM vm = new ProtelisVM(ProtelisLoader.parse(toCheck), new DummyContext()); vm.runCycle(); assertEquals(vm.getCurrentValue(), execResult instanceof Number ? ((Number) execResult).doubleValue() : execResult); } else { fail("Your test does not include the expected result"); } } catch (IOException e) { fail(LangUtils.stackTraceToString(e)); } }
From source file:org.runbuddy.libtomahawk.infosystem.hatchet.HatchetInfoPlugin.java
/** * Start the JSONSendTask to send the given InfoRequestData's json string *///from ww w . j a va 2 s .c o m @Override public void send(final InfoRequestData infoRequestData, AuthenticatorUtils authenticatorUtils) { mHatchetAuthenticatorUtils = (HatchetAuthenticatorUtils) authenticatorUtils; TomahawkRunnable runnable = new TomahawkRunnable(TomahawkRunnable.PRIORITY_IS_INFOSYSTEM_MEDIUM) { @Override public void run() { ArrayList<String> doneRequestsIds = new ArrayList<>(); doneRequestsIds.add(infoRequestData.getRequestId()); Hatchet hatchet = mStore.getImplementation(infoRequestData.isBackgroundRequest()); // Before we do anything, get the accesstoken boolean success = false; boolean discard = false; String accessToken = mHatchetAuthenticatorUtils.ensureAccessTokens(); if (accessToken != null) { String data = infoRequestData.getJsonStringToSend(); try { if (infoRequestData.getType() == InfoRequestData.INFOREQUESTDATA_TYPE_PLAYBACKLOGENTRIES) { hatchet.postPlaybackLogEntries(accessToken, new TypedByteArray( "application/json; charset=utf-8", data.getBytes(Charsets.UTF_8))); } else if (infoRequestData.getType() == InfoRequestData.INFOREQUESTDATA_TYPE_PLAYLISTS) { if (infoRequestData.getHttpType() == InfoRequestData.HTTPTYPE_POST) { HatchetPlaylistEntries entries = hatchet.postPlaylists(accessToken, new TypedByteArray("application/json; charset=utf-8", data.getBytes(Charsets.UTF_8))); List<HatchetPlaylistEntries> results = new ArrayList<>(); results.add(entries); infoRequestData.setResultList(results); } else if (infoRequestData.getHttpType() == InfoRequestData.HTTPTYPE_DELETE) { hatchet.deletePlaylists(accessToken, infoRequestData.getQueryParams().playlist_id); } else if (infoRequestData.getHttpType() == InfoRequestData.HTTPTYPE_PUT) { hatchet.putPlaylists(accessToken, infoRequestData.getQueryParams().playlist_id, new TypedByteArray("application/json; charset=utf-8", data.getBytes(Charsets.UTF_8))); } } else if (infoRequestData .getType() == InfoRequestData.INFOREQUESTDATA_TYPE_PLAYLISTS_PLAYLISTENTRIES) { if (infoRequestData.getHttpType() == InfoRequestData.HTTPTYPE_POST) { hatchet.postPlaylistsPlaylistEntries(accessToken, new TypedByteArray( "application/json; charset=utf-8", data.getBytes(Charsets.UTF_8))); } else if (infoRequestData.getHttpType() == InfoRequestData.HTTPTYPE_DELETE) { hatchet.deletePlaylistsPlaylistEntries(accessToken, infoRequestData.getQueryParams().entry_id, infoRequestData.getQueryParams().playlist_id); } } else if (infoRequestData .getType() == InfoRequestData.INFOREQUESTDATA_TYPE_RELATIONSHIPS) { if (infoRequestData.getHttpType() == InfoRequestData.HTTPTYPE_POST) { hatchet.postRelationship(accessToken, new TypedByteArray( "application/json; charset=utf-8", data.getBytes(Charsets.UTF_8))); } else if (infoRequestData.getHttpType() == InfoRequestData.HTTPTYPE_DELETE) { hatchet.deleteRelationShip(accessToken, infoRequestData.getQueryParams().relationship_id); } } success = true; discard = true; } catch (RetrofitError e) { Log.e(TAG, "send: Request to " + e.getUrl() + " failed: " + e.getClass() + ": " + e.getLocalizedMessage()); if (e.getResponse() != null && e.getResponse().getStatus() == 500) { Log.e(TAG, "send: discarding oplog that has failed to be sent to " + e.getUrl()); discard = true; } } } InfoSystem.get().onLoggedOpsSent(doneRequestsIds, discard); InfoSystem.get().reportResults(infoRequestData, success); } }; ThreadManager.get().execute(runnable); }
From source file:org.runbuddy.libtomahawk.resolver.ScriptAccount.java
@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" }) public ScriptAccount(String path, boolean manuallyInstalled) { String prefix = manuallyInstalled ? "file://" : "file:///android_asset"; mPath = prefix + path;/*from ww w. j ava 2 s . co m*/ mManuallyInstalled = manuallyInstalled; String[] parts = mPath.split("/"); mName = parts[parts.length - 1]; InputStream inputStream = null; try { if (mManuallyInstalled) { File metadataFile = new File(path + File.separator + "content" + File.separator + "metadata.json"); inputStream = new FileInputStream(metadataFile); } else { inputStream = TomahawkApp.getContext().getAssets() .open(path.substring(1) + "/content/metadata.json"); } String metadataString = IOUtils.toString(inputStream, Charsets.UTF_8); mMetaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class); if (mMetaData == null) { Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } } catch (IOException e) { Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage()); Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount."); return; } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage()); } } } CookieManager.setAcceptFileSchemeCookies(true); mWebView = new WebView(TomahawkApp.getContext()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true); } WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { //noinspection deprecation settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath()); } settings.setDomStorageEnabled(true); mWebView.setWebChromeClient(new TomahawkWebChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { //initalize WebView String data = "<!DOCTYPE html>" + "<html>" + "<head><title>" + mName + "</title></head>" + "<body>" + "<script src=\"file:///android_asset/js/rsvp-latest.min.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/cryptojs-core.js" + "\" type=\"text/javascript\"></script>"; if (mMetaData.manifest.scripts != null) { for (String scriptPath : mMetaData.manifest.scripts) { data += "<script src=\"" + mPath + "/content/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } try { String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs"); for (String scriptPath : cryptoJsScripts) { data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath + "\" type=\"text/javascript\"></script>"; } } catch (IOException e) { Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage()); } data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk-infosystem.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"file:///android_asset/js/tomahawk_android_post.js" + "\" type=\"text/javascript\"></script>" + "<script src=\"" + mPath + "/content/" + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>"; mWebView.setWebViewClient(new ScriptWebViewClient(ScriptAccount.this)); mWebView.addJavascriptInterface(new ScriptInterface(ScriptAccount.this), SCRIPT_INTERFACE_NAME); mWebView.loadDataWithBaseURL("file:///android_asset/test.html", data, "text/html", null, null); } }); }
From source file:org.runbuddy.tomahawk.dialogs.InstallPluginConfigDialog.java
@Override protected void onPositiveAction() { new Thread(new Runnable() { @Override/* w ww.ja v a 2 s .c o m*/ public void run() { String destDirPath = TomahawkApp.getContext().getFilesDir().getAbsolutePath() + File.separator + "manualresolvers" + File.separator + ".temp"; File destDir = new File(destDirPath); try { VariousUtils.deleteRecursive(destDir); } catch (FileNotFoundException e) { Log.d(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage()); } try { if (UnzipUtils.unzip(mPathToAxe, destDirPath)) { File metadataFile = new File( destDirPath + File.separator + "content" + File.separator + "metadata.json"); String metadataString = FileUtils.readFileToString(metadataFile, Charsets.UTF_8); ScriptResolverMetaData metaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class); final File renamedFile = new File(destDir.getParent() + File.separator + metaData.pluginName + "_" + System.currentTimeMillis()); boolean success = destDir.renameTo(renamedFile); if (!success) { Log.e(TAG, "onPositiveAction - Wasn't able to rename directory: " + renamedFile.getAbsolutePath()); } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { PipeLine.get().addScriptAccount(new ScriptAccount(renamedFile.getPath(), true)); } }); } } catch (IOException e) { Log.e(TAG, "onPositiveAction: " + e.getClass() + ": " + e.getLocalizedMessage()); } } }).start(); dismiss(); }
From source file:org.sakuli.starter.helper.SahiProxy.java
protected void injectCustomJavaScriptFiles() throws IOException { File injectFile = props.getSahiJSInjectConfigFile().toFile(); String injectFileString = FileUtils.readFileToString(injectFile, Charsets.UTF_8); if (!injectFileString.contains(SAKULI_INJECT_SCRIPT_TAG)) { injectFileString = StringUtils.replace(injectFileString, SAHI_INJECT_END, SAKULI_INJECT_SCRIPT_TAG + "\r\n" + SAHI_INJECT_END); FileUtils.writeStringToFile(injectFile, injectFileString, Charsets.UTF_8); logger.info("added '{}' to Sahi inject config file '{}'", SAKULI_INJECT_SCRIPT_TAG, props.getSahiJSInjectConfigFile().toString()); }// w ww .j a v a 2 s. c o m Path source = props.getSahiJSInjectSourceFile(); Path target = props.getSahiJSInjectTargetFile(); if (isNewer(source, target)) { FileUtils.copyFile(source.toFile(), target.toFile(), false); logger.info("copied file '{}' to target '{}'", source.toString(), target.toString()); } }