return true;
}
- public static void CheckSwapDir() {
- File dir = new File(FilePathResources.getSwapPath());
-
- if (!dir.exists()) {
- dir.mkdir();
- }
-
- File dest = null;
- File src = null;
- dest = new File(FilePathResources.getSwapPath()
- + File.separator + StringResources.SWAP_IMAGE);
- if (!dest.exists()) {
- src = new File(FilePathResources.getbaseSwapPath()
- + File.separator + StringResources.SWAP_IMAGE);
- if (!src.exists()) {
- EMLogger.getLogger().log(Level.WARNING,
- "Failed to create swap image.!" + StringResources.NEW_LINE
- + "File does not exist :" + src.getPath());
- return;
- }
-
- try {
- dest.createNewFile();
- } catch (IOException e1) {
- EMLogger.getLogger().log(Level.WARNING,
- "Failed to create swap image!" + StringResources.NEW_LINE
- + e1.getMessage());
- return;
- }
-
- FileInputStream inputStream = null;
- FileOutputStream outputStream = null;
- FileChannel fcin = null;
- FileChannel fcout = null;
- try {
- inputStream = new FileInputStream(src);
- outputStream = new FileOutputStream(dest);
- fcin = inputStream.getChannel();
- fcout = outputStream.getChannel();
- long size = fcin.size();
- long transferredSize = fcin.transferTo(0, size, fcout);
- if(size != transferredSize) {
- EMLogger.getLogger().log(Level.WARNING, "Failed to create swap image!"
- + StringResources.NEW_LINE + "Copy failed.");
- dest.delete();
- }
- } catch (FileNotFoundException e) {
- EMLogger.getLogger().log(Level.WARNING, "Failed to create swap image!"
- + StringResources.NEW_LINE + e.getMessage());
- dest.delete();
- } catch (IOException e) {
- EMLogger.getLogger().log(Level.WARNING, "Failed to create swap image!"
- + StringResources.NEW_LINE + e.getMessage());
- dest.delete();
- }finally {
- try {
- if (fcout != null) {
- fcout.close();
- }
- if (fcin != null) {
- fcin.close();
- }
- if (outputStream != null) {
- outputStream.close();
- }
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (IOException e) {
- EMLogger.getLogger().log(Level.WARNING, e.getMessage());
- }
- }
- }
- }
-
public static void CheckSDCardDir() {
File dir = new File(FilePathResources.getSDCardPath());
import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
}
private void createSwapImageInternal(String basePath, String targetPath) throws VMCreatorException {
- String exe_path = getQemuImgPath();
-
- List<String> cmd = new ArrayList<String>();
- cmd.add(exe_path);
- cmd.add("create");
- cmd.add("-b");
- cmd.add(basePath);
- cmd.add("-f");
- cmd.add("qcow2");
- cmd.add(targetPath);
-
- if (!new QemuImgProc(cmd).Running()) {
- throw new VMCreatorException("Failed to create the VM because of failed qemu-img processing."
- + StringResources.NEW_LINE
+ // Swap images created by clone base image.
+ try {
+ Files.copy(Paths.get(basePath), Paths.get(targetPath), StandardCopyOption.COPY_ATTRIBUTES);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new VMCreatorException("Failed to copy swap image." + StringResources.NEW_LINE
+ "You can get more information in log file ("
+ FilePathResources.getTizenVmsPath() + File.separator + "emulator-manager)");
}