@Override public void dispose() { FileUtils.deleteRecursive(mWorkDir); mLocaleFiles.clear(); iconFile = null; } }
public static String mayUseTranslationServices(final RepositoryResources resources) { for (File file : resources.readme) { int i = FileUtils.fileContains(file, STR_TRANSLATION_SERVICES); if (i != -1) return STR_TRANSLATION_SERVICES[i]; } return ""; }
public static boolean isTextFile(File file) { return getMimeType(file).startsWith("text/"); }
public static boolean renameFile(File srcFile, File destFile) { if (srcFile.getAbsolutePath().equals(destFile.getAbsolutePath())) { return false; } // renameTo will fail in case of case-changed filename in same dir.Even on case-sensitive FS!!! if (srcFile.getParent().equals(destFile.getParent()) && srcFile.getName().toLowerCase(Locale.getDefault()).equals(destFile.getName().toLowerCase(Locale.getDefault()))) { File tmpFile = new File(destFile.getParent(), UUID.randomUUID().getLeastSignificantBits() + ".tmp"); if (!tmpFile.exists()) { renameFile(srcFile, tmpFile); srcFile = tmpFile; } } if (!srcFile.renameTo(destFile)) { if (copyFile(srcFile, destFile) && !srcFile.delete()) { if (!destFile.delete()) { return false; } return false; } } return true; }
private JSONObject load() { try { final String json = FileUtils.readTextFile(mSettingsFile); if (!json.isEmpty()) return new JSONObject(json); } catch (JSONException e) { e.printStackTrace(); } return new JSONObject(); }
if (!FileUtils.deleteRecursive(tmpWorkDir)) return false; if (FileUtils.copyFile(icon, newIcon)) settings.setIconFile(newIcon);
public static String readCloseTextStream(final InputStream stream) { return readCloseTextStream(stream, true).get(0); }
public boolean save() { return FileUtils.writeFile(mSettingsFile, mSettings.toString()); }
public static byte[] readBinaryFile(final File file) { try { return readCloseBinaryStream(new FileInputStream(file), (int) file.length()); } catch (FileNotFoundException e) { System.err.println("readBinaryFile: File " + file + " not found."); } return new byte[0]; }
@SuppressWarnings("ResultOfMethodCallIgnored") public static boolean renameFileInSameFolder(File srcFile, String destFilename) { return renameFile(srcFile, new File(srcFile.getParent(), destFilename)); }
public static boolean copyFile(final File src, final File dst) { // Just touch file if src is empty if (src.length() == 0) { return touch(dst); } InputStream is = null; FileOutputStream os = null; try { try { is = new FileInputStream(src); os = new FileOutputStream(dst); byte[] buf = new byte[BUFFER_SIZE]; int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); } return true; } finally { if (is != null) { is.close(); } if (os != null) { os.close(); } } } catch (IOException ex) { return false; } }
private JSONObject load() { try { final String json = FileUtils.readTextFile(mSettingsFile); if (!json.isEmpty()) return new JSONObject(json); } catch (JSONException e) { e.printStackTrace(); } return new JSONObject(); }
public static String readTextFile(final File file) { try { return readCloseTextStream(new FileInputStream(file)); } catch (FileNotFoundException e) { System.err.println("readTextFile: File " + file + " not found."); } return ""; }
public boolean save() { return FileUtils.writeFile(mSettingsFile, mSettings.toString()); }
public static String readTextFileFast(final File file) { try { return new String(readCloseBinaryStream(new FileInputStream(file))); } catch (FileNotFoundException e) { System.err.println("readTextFileFast: File " + file + " not found."); } return ""; }
public RepoProgress loadProgress() { try { final String json = FileUtils.readTextFile(mProgressFile); if (!json.isEmpty()) return RepoProgress.fromJson(new JSONObject(json)); } catch (JSONException e) { e.printStackTrace(); } return null; }
public static boolean deleteRecursive(final File file) { boolean ok = true; if (file.exists()) { if (file.isDirectory()) { for (File child : file.listFiles()) ok &= deleteRecursive(child); } ok &= file.delete(); } return ok; }
private static String performCall(final URL url, final String method, final String data, final HttpURLConnection existingConnection) { try { final HttpURLConnection connection = existingConnection != null ? existingConnection : (HttpURLConnection) url.openConnection(); connection.setRequestMethod(method); connection.setDoInput(true); if (data != null && !data.isEmpty()) { connection.setDoOutput(true); final OutputStream output = connection.getOutputStream(); output.write(data.getBytes(Charset.forName(UTF8))); output.flush(); output.close(); } InputStream input = connection.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST ? connection.getInputStream() : connection.getErrorStream(); return FileUtils.readCloseTextStream(connection.getInputStream()); } catch (Exception e) { e.printStackTrace(); } return ""; }
public boolean saveProgress(RepoProgress progress) { try { return FileUtils.writeFile(mProgressFile, progress.toJson().toString()); } catch (JSONException e) { e.printStackTrace(); return false; } }
public static ArrayList<File> searchAndroidResources(final RepositoryResources resources) { ArrayList<File> result = new ArrayList<>(); for (File file : resources.xml) if (FileUtils.fileContains(file, STR_STRING, STR_PLURALS) != -1) result.add(file); return result; }