本文整理汇总了Java中net.gsantner.opoc.util.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于net.gsantner.opoc.util包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBundledAssets
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
private void loadBundledAssets(List<MemeData.Font> fonts, List<MemeData.Image> images) {
AssetManager assetManager = _context.getAssets();
File config = new File(getBundledAssetsDir(_appSettings), MEMETASTIC_CONFIG_FILE);
config.delete();
try {
File cacheDir = getBundledAssetsDir(_appSettings);
if (cacheDir.exists() || cacheDir.mkdirs()) {
for (String assetFilename : assetManager.list("bundled")) {
InputStream is = assetManager.open("bundled/" + assetFilename);
byte[] data = FileUtils.readCloseBinaryStream(is);
FileUtils.writeFile(new File(cacheDir, assetFilename), data);
}
}
} catch (IOException ignored) {
}
}
示例2: setUpDialog
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
private AlertDialog.Builder setUpDialog(final File file, LayoutInflater inflater) {
View root;
AlertDialog.Builder dialogBuilder;
boolean darkTheme = AppSettings.get().isDarkThemeEnabled();
dialogBuilder = new AlertDialog.Builder(getActivity(), darkTheme ?
R.style.Theme_AppCompat_Dialog : R.style.Theme_AppCompat_Light_Dialog);
root = inflater.inflate(R.layout.ui__rename__dialog, (ViewGroup) null);
dialogBuilder.setTitle(getResources().getString(R.string.rename));
dialogBuilder.setView(root);
EditText editText = root.findViewById(R.id.new_name);
editText.setText(file.getName());
editText.setTextColor(ContextCompat.getColor(root.getContext(),
darkTheme ? R.color.dark__primary_text : R.color.light__primary_text));
dialogBuilder.setPositiveButton(getString(android.R.string.ok), (dialog, which) -> {
if (FileUtils.renameFileInSameFolder(file, _newNameField.getText().toString())) {
AppCast.VIEW_FOLDER_CHANGED.send(getContext(), file.getParent(), true);
}
});
dialogBuilder.setNegativeButton(getString(android.R.string.cancel), (dialog, which) -> dialog.dismiss());
return dialogBuilder;
}
示例3: saveDocument
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
public static synchronized boolean saveDocument(Document document, boolean argAllowRename, String currentText) {
boolean ret = false;
String filename = DocumentIO.normalizeTitleForFilename(document) + document.getFileExtension();
document.setDoHistory(true);
document.setFile(new File(document.getFile().getParentFile(), filename));
Document documentInitial = document.getInitialVersion();
if (argAllowRename) {
if (!document.getFile().equals(documentInitial.getFile())) {
if (documentInitial.getFile().exists()) {
if (FileUtils.renameFile(documentInitial.getFile(), document.getFile())) {
// Rename succeeded -> Rename everything in history too
for (Document hist : document.getHistory()) {
hist.setFile(document.getFile());
for (Document hist2 : hist.getHistory()) {
hist2.setFile(document.getFile());
}
}
}
}
}
} else {
document.setFile(documentInitial.getFile());
}
if (!currentText.equals(documentInitial.getContent())) {
document.forceAddNextChangeToHistory();
document.setContent(currentText);
ret = FileUtils.writeFile(document.getFile(), document.getContent());
} else {
ret = true;
}
return ret;
}
示例4: searchAndroidResources
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
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;
}
示例5: mayUseTranslationServices
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
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 "";
}
示例6: saveProgress
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
public boolean saveProgress(RepoProgress progress) {
try {
return FileUtils.writeFile(mProgressFile, progress.toJson().toString());
} catch (JSONException e) {
e.printStackTrace();
return false;
}
}
示例7: loadProgress
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
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;
}
示例8: importZip
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
public void importZip(InputStream inputStream) {
try {
// Get temporary import directory and delete any previous directory
File dir = getTempImportDir();
File backupDir = getTempImportBackupDir();
if (!FileUtils.deleteRecursive(dir) || !FileUtils.deleteRecursive(backupDir))
throw new IOException("Could not delete old temporary directories.");
// Unzip the given input stream
ZipUtils.unzip(inputStream, dir, false, null, -1f);
// Ensure it's a valid repository (only one parent directory, containing settings)
final File[] unzippedFiles = dir.listFiles();
if (unzippedFiles == null || unzippedFiles.length != 1)
throw new IOException("There should only be 1 unzipped file (the repository's root).");
final File root = unzippedFiles[0];
if (!RepoSettings.exists(root))
throw new IOException("The specified .zip file does not seem valid.");
// Nice, unzipping worked. Now try moving the current repository
// to yet another temporary location, because we don't want to lose
// it in case something goes wrong and we need to revert…
if (!mRoot.renameTo(backupDir))
throw new IOException("Could not move the current repository to its backup location.");
if (!root.renameTo(mRoot)) {
// Try reverting the state, hopefully no data was lost
String extra = backupDir.renameTo(mRoot) ? "" : " Failed to recover its previous state.";
throw new IOException("Could not move the temporary repository to its new location." + extra);
}
Messenger.notifyRepoAdded(this);
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: load
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
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();
}
示例10: getDefaultResourceXml
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
@Override
public String getDefaultResourceXml(String name) {
for (File file : mLocaleFiles.get(null))
if (getDefaultResourceName(file).equals(name))
return FileUtils.readTextFile(file);
throw new IllegalArgumentException("No XML was found with that name");
}
示例11: importFileToCurrentDirectory
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
private void importFileToCurrentDirectory(Context context, File sourceFile) {
FileUtils.copyFile(sourceFile, new File(getCurrentDir().getAbsolutePath(), sourceFile.getName()));
Toast.makeText(context, getString(R.string.import_) + ": " + sourceFile.getName(), Toast.LENGTH_LONG).show();
}
示例12: run
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
public void run() {
File cacheDirForFiles = new File(_context.getCacheDir(), AppSettings.get().getSaveDirectory().getAbsolutePath().substring(1));
FileUtils.deleteRecursive(cacheDirForFiles);
}
示例13: onActivityResult
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_LOAD_GALLERY_IMAGE) {
if (resultCode == RESULT_OK && data != null) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
String picturePath = null;
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
for (String column : filePathColumn) {
int curColIndex = cursor.getColumnIndex(column);
if (curColIndex == -1) {
continue;
}
picturePath = cursor.getString(curColIndex);
if (!TextUtils.isEmpty(picturePath)) {
break;
}
}
cursor.close();
}
// Retrieve image from file descriptor / Cloud, e.g.: Google Drive, Picasa
if (picturePath == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try {
ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(selectedImage, "r");
if (parcelFileDescriptor != null) {
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
FileInputStream input = new FileInputStream(fileDescriptor);
// Create temporary file in cache directory
picturePath = File.createTempFile("image", "tmp", getCacheDir()).getAbsolutePath();
FileUtils.writeFile(
new File(picturePath),
FileUtils.readCloseBinaryStream(input)
);
}
} catch (IOException e) {
// nothing we can do here, null value will be handled below
}
}
// Finally check if we got something
if (picturePath == null) {
ActivityUtils.get(this).showSnackBar(R.string.main__error_fail_retrieve_picture, false);
} else {
onImageTemplateWasChosen(picturePath);
}
}
}
if (requestCode == REQUEST_TAKE_CAMERA_PICTURE) {
if (resultCode == RESULT_OK) {
onImageTemplateWasChosen(cameraPictureFilepath);
} else {
ActivityUtils.get(this).showSnackBar(R.string.main__error_no_picture_selected, false);
}
}
if (requestCode == REQUEST_SHOW_IMAGE) {
selectTab(_tabLayout.getSelectedTabPosition(), _currentMainMode);
}
}
示例14: cleanXml
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
public static boolean cleanXml(final File inFile, final File outFile) {
return cleanXml(FileUtils.readTextFile(inFile), outFile);
}
示例15: applyTemplate
import net.gsantner.opoc.util.FileUtils; //导入依赖的package包/类
public static boolean applyTemplate(File template, Resources resources, OutputStream out) {
// The xml will be empty if we have no translation for this file.
String xml = cleanMissingStrings(FileUtils.readTextFile(template), resources);
return !xml.isEmpty() && writeReplaceStrings(xml, resources, out);
}