+
+ public void copyLocalFile(OCFile file, String targetPath) {
+
+ if (file != null && file.fileExists() && !OCFile.ROOT_PATH.equals(file.getFileName())) {
+ String localPath = FileStorageUtils.getDefaultSavePathFor(mAccount.name, file);
+ File localFile = new File(localPath);
+ boolean copied = false;
+ String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
+ if (localFile.exists()) {
+ File targetFile = new File(defaultSavePath + targetPath);
+ File targetFolder = targetFile.getParentFile();
+ if (!targetFolder.exists()) {
+ targetFolder.mkdirs();
+ }
+ copied = copyFile(localFile, targetFile);
+ }
+ Log_OC.d(TAG, "Local file COPIED : " + copied);
+ }
+ }
+
+ private boolean copyFile(File src, File target) {
+ boolean ret = true;
+
+ InputStream in = null;
+ OutputStream out = null;
+
+ try {
+ in = new FileInputStream(src);
+ out = new FileOutputStream(target);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ } catch (IOException ex) {
+ ret = false;
+ } finally {
+ if (in != null) try {
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace(System.err);
+ }
+ if (out != null) try {
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ return ret;
+ }
+