From 195503565003989345370d88dcd4eb83ff8a2733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20T=C3=A1rraga=20Gim=C3=A9nez?= Date: Mon, 3 Jun 2024 10:22:22 +0200 Subject: [PATCH] utils: add the method FileUtils.copyFile, #TASK-6297, #TASK-6255 On branch TASK-6255 Changes to be committed: modified: commons-lib/pom.xml modified: commons-lib/src/main/java/org/opencb/commons/utils/FileUtils.java --- commons-lib/pom.xml | 6 +++++ .../org/opencb/commons/utils/FileUtils.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/commons-lib/pom.xml b/commons-lib/pom.xml index dccbe7ec9..0e057979e 100644 --- a/commons-lib/pom.xml +++ b/commons-lib/pom.xml @@ -68,5 +68,11 @@ com.fasterxml.jackson.core jackson-databind + + commons-io + commons-io + 2.8.0 + compile + diff --git a/commons-lib/src/main/java/org/opencb/commons/utils/FileUtils.java b/commons-lib/src/main/java/org/opencb/commons/utils/FileUtils.java index 93fba0f0d..1ae5ba87d 100644 --- a/commons-lib/src/main/java/org/opencb/commons/utils/FileUtils.java +++ b/commons-lib/src/main/java/org/opencb/commons/utils/FileUtils.java @@ -18,6 +18,7 @@ import org.apache.commons.lang3.StringUtils; import org.opencb.commons.exec.Command; +import org.slf4j.LoggerFactory; import java.io.*; import java.nio.charset.Charset; @@ -188,6 +189,27 @@ public static String[] getUserAndGroup(Path path, boolean numericId) throws IOEx return new String[]{split[2], split[3]}; } + + public static void copyFile(File src, File dest) throws IOException { + try { + org.apache.commons.io.FileUtils.copyFile(src, dest); + } catch (IOException e) { + try { + if (src.length() == dest.length()) { + LoggerFactory.getLogger(FileUtils.class).warn(e.getMessage()); + return; + } + throw e; + } catch (Exception e1) { + throw e; + } + } + } + + //------------------------------------------------------------------------- + // P R I V A T E M E T H O D S + //------------------------------------------------------------------------- + private static String getLsOutput(Path path, boolean numericId) throws IOException { FileUtils.checkPath(path);