MCPcopy Create free account
hub / github.com/buggins/coolreader / moveFile

Method moveFile

android/src/org/coolreader/crengine/Engine.java:806–848  ·  view source on GitHub ↗
( File oldPlace, File newPlace )

Source from the content-addressed store, hash-verified

804 }
805
806 public static boolean moveFile( File oldPlace, File newPlace ) {
807 boolean removeNewFile = true;
808 log.i("Moving file " + oldPlace.getAbsolutePath() + " to " + newPlace.getAbsolutePath());
809 if ( !oldPlace.exists() ) {
810 log.e("File " + oldPlace.getAbsolutePath() + " does not exist!");
811 return false;
812 }
813 FileOutputStream os = null;
814 FileInputStream is = null;
815 try {
816 if ( !newPlace.createNewFile() )
817 return false; // cannot create file
818 os = new FileOutputStream(newPlace);
819 is = new FileInputStream(oldPlace);
820 byte[] buf = new byte[0x10000];
821 for (;;) {
822 int bytesRead = is.read(buf);
823 if ( bytesRead<=0 )
824 break;
825 os.write(buf, 0, bytesRead);
826 }
827 removeNewFile = false;
828 oldPlace.delete();
829 return true;
830 } catch ( IOException e ) {
831 return false;
832 } finally {
833 try {
834 if (os != null)
835 os.close();
836 } catch (IOException ee) {
837 // ignore
838 }
839 try {
840 if (is != null)
841 is.close();
842 } catch (IOException ee) {
843 // ignore
844 }
845 if ( removeNewFile )
846 newPlace.delete();
847 }
848 }
849
850 /**
851 * Checks whether file under old path exists, and moves it to better place when necessary.

Callers 1

checkOrMoveFileMethod · 0.95

Calls 6

existsMethod · 0.80
iMethod · 0.65
eMethod · 0.65
readMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected