2016-04-01 13:09:40 +02:00
|
|
|
package org.gcube.dataanalysis.wps.statisticalmanager.synchserver.utils;
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
2017-05-05 10:08:44 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2016-04-01 13:09:40 +02:00
|
|
|
|
|
|
|
public class FileManager {
|
|
|
|
|
2017-05-05 10:08:44 +02:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FileManager.class);
|
|
|
|
|
|
|
|
public static boolean fileCopy(String origin, String destination) {
|
2016-04-01 13:09:40 +02:00
|
|
|
try {
|
2017-05-05 10:08:44 +02:00
|
|
|
//create FileInputStream object for source file
|
|
|
|
FileInputStream fin = new FileInputStream(origin);
|
|
|
|
|
|
|
|
//create FileOutputStream object for destination file
|
|
|
|
FileOutputStream fout = new FileOutputStream(destination);
|
|
|
|
|
|
|
|
byte[] b = new byte[1024];
|
|
|
|
int noOfBytes = 0;
|
|
|
|
|
|
|
|
logger.debug("Copying file using streams. O: "+origin+" D: "+destination);
|
|
|
|
|
|
|
|
//read bytes from source file and write to destination file
|
|
|
|
while( (noOfBytes = fin.read(b)) != -1 )
|
|
|
|
{
|
|
|
|
fout.write(b, 0, noOfBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.debug("File copied!");
|
|
|
|
//close the streams
|
|
|
|
fin.close();
|
|
|
|
fout.close();
|
|
|
|
return true;
|
2016-04-01 13:09:40 +02:00
|
|
|
} catch (Exception e) {
|
2017-05-05 10:08:44 +02:00
|
|
|
logger.error("error copying file {}",origin,e);
|
2016-04-01 13:09:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|