MCPcopy Index your code
hub / github.com/benfry/processing4 / copyFile

Method copyFile

app/src/processing/app/Sketch.java:1134–1168  ·  view source on GitHub ↗

Overloaded copyFile that is called whenever a Save As is being done, so that the ProgressBar is updated for very large files as well.

(File sourceFile, File targetFile,
                      long progress, long totalSize)

Source from the content-addressed store, hash-verified

1132 * so that the ProgressBar is updated for very large files as well.
1133 */
1134 void copyFile(File sourceFile, File targetFile,
1135 long progress, long totalSize) throws IOException {
1136 BufferedInputStream from =
1137 new BufferedInputStream(new FileInputStream(sourceFile));
1138 BufferedOutputStream to =
1139 new BufferedOutputStream(new FileOutputStream(targetFile));
1140 byte[] buffer = new byte[16 * 1024];
1141 int bytesRead;
1142 int progRead = 0;
1143 while ((bytesRead = from.read(buffer)) != -1) {
1144 to.write(buffer, 0, bytesRead);
1145 progRead += bytesRead;
1146 if (progRead >= 512 * 1024) { // to update progress bar every 0.5MB
1147 progress += progRead;
1148 //progressBar.setValue((int) Math.min(Math.ceil(progress * 100.0 / totalSize), 100));
1149 setProgress((int) (100L * progress / totalSize));
1150 progRead = 0;
1151 }
1152 }
1153 // Final update to progress bar
1154 setProgress((int) (100L * progress / totalSize));
1155
1156 from.close();
1157 to.flush();
1158 to.close();
1159
1160 if (!targetFile.setLastModified(sourceFile.lastModified())) {
1161 System.err.println("Warning: Could not set modification date/time for " + targetFile);
1162 }
1163 if (!targetFile.setExecutable(sourceFile.canExecute())) {
1164 if (!Platform.isWindows()) { // more of a UNIX thing
1165 System.err.println("Warning: Could not set permissions for " + targetFile);
1166 }
1167 }
1168 }
1169
1170
1171 long copyDir(File sourceDir, File targetDir,

Callers 2

doInBackgroundMethod · 0.95
copyDirMethod · 0.95

Calls 8

isWindowsMethod · 0.95
setProgressMethod · 0.80
setLastModifiedMethod · 0.80
writeMethod · 0.65
readMethod · 0.45
closeMethod · 0.45
flushMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected