diff --git a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java index 0f1f4435c..ec6152af2 100644 --- a/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java +++ b/src/main/java/org/openmicroscopy/shoola/agents/fsimporter/view/ImporterModel.java @@ -24,6 +24,7 @@ import java.io.File; import java.text.SimpleDateFormat; +import java.nio.file.Files; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -62,8 +63,6 @@ import org.openmicroscopy.shoola.util.CommonsLangUtils; import org.openmicroscopy.shoola.util.roi.io.ROIReader; -import com.google.common.io.Files; - import omero.gateway.model.DataObject; import omero.gateway.model.ExperimenterData; import omero.gateway.model.FileAnnotationData; @@ -731,22 +730,23 @@ component, ctx, new FileAnnotationData(f), */ private File createFile(String imageName) { - File dir = Files.createTempDir(); - String name; - String fileName = null; - if (object != null) { - fileName = object.getTableName(); - } - if (CommonsLangUtils.isBlank(fileName)) { - name = "ImageJ-"+FilenameUtils.getBaseName( + try { + final String prefix = "ome_"; + File dir = Files.createTempDirectory(prefix).toFile(); + String name; + String fileName = null; + if (object != null) { + fileName = object.getTableName(); + } + if (CommonsLangUtils.isBlank(fileName)) { + name = "ImageJ-"+FilenameUtils.getBaseName( FilenameUtils.removeExtension(imageName))+"-Results-"; - name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); - } else { - name = FilenameUtils.removeExtension(fileName); - } + name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + } else { + name = FilenameUtils.removeExtension(fileName); + } - name += ".csv"; - try { + name += ".csv"; File f = new File(dir, name); //read data ROIReader reader = new ROIReader(); diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java index 7debb655d..7c659ee40 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ArchivedImageLoader.java @@ -30,7 +30,9 @@ import java.util.List; import java.util.Map; -import com.google.common.io.Files; +import java.nio.file.Files; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; @@ -158,8 +160,8 @@ public void doCall() throws Exception File tmpFolder = null; try { - if(zip) - tmpFolder = Files.createTempDir(); + if (zip) + tmpFolder = Files.createTempDirectory("ome_").toFile(); else tmpFolder = folder; @@ -173,7 +175,7 @@ public void doCall() throws Exception result = new HashMap>(); - if(CollectionUtils.isEmpty(files)) + if (CollectionUtils.isEmpty(files)) return; if (zip) { @@ -185,7 +187,7 @@ public void doCall() throws Exception File to = new File(f.getParentFile(), baseName + "." + FilenameUtils.getExtension(f.getName())); - Files.move(f, to); + Files.move(f.toPath(), to.toPath(), REPLACE_EXISTING); f = copyFile(to, folder.getParentFile()); ((Map>)result).put(Boolean.TRUE, Arrays.asList(f)); } diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java index 984ae0ee3..12c5cec0c 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/FileUploader.java @@ -30,7 +30,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; -import com.google.common.io.Files; +import java.nio.file.Files; import org.openmicroscopy.shoola.env.LookupNames; import org.openmicroscopy.shoola.env.data.OmeroMetadataService; @@ -126,7 +126,7 @@ private void uploadFile(ImportErrorObject object) } } if (b || id > 0) { - directory = Files.createTempDir(); + directory = Files.createTempDirectory("ome_").toFile(); //Add the file to the directory. if (f != null) { directory = new File(directory.getParentFile(), diff --git a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java index 4284f165d..962478740 100644 --- a/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java +++ b/src/main/java/org/openmicroscopy/shoola/env/data/views/calls/ResultsSaver.java @@ -24,6 +24,7 @@ import ij.ImagePlus; import java.io.File; +import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; @@ -41,7 +42,7 @@ import org.openmicroscopy.shoola.util.CommonsLangUtils; import org.openmicroscopy.shoola.util.roi.io.ROIReader; -import com.google.common.io.Files; + import omero.gateway.model.ExperimenterData; import omero.gateway.model.FileAnnotationData; @@ -83,17 +84,17 @@ public class ResultsSaver */ private File createFile(ImagePlus img, String fileName) { - File dir = Files.createTempDir(); - String name; - if (CommonsLangUtils.isBlank(fileName)) { - name = "ImageJ-"+FilenameUtils.getBaseName( - FilenameUtils.removeExtension(img.getTitle()))+"-Results-"; - name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); - } else { - name = FilenameUtils.removeExtension(fileName); - } - name += ".csv"; try { + File dir = Files.createTempDirectory("ome_").toFile(); + String name; + if (CommonsLangUtils.isBlank(fileName)) { + name = "ImageJ-"+FilenameUtils.getBaseName( + FilenameUtils.removeExtension(img.getTitle()))+"-Results-"; + name += new SimpleDateFormat("yyyy-MM-dd").format(new Date()); + } else { + name = FilenameUtils.removeExtension(fileName); + } + name += ".csv"; File f = new File(dir, name); //read data ROIReader reader = new ROIReader(); diff --git a/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java b/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java index 2c0584fd7..69dc37421 100644 --- a/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java +++ b/src/test/java/org/openmicroscopy/shoola/util/file/TestIOUtil.java @@ -26,6 +26,7 @@ import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.zip.ZipEntry; @@ -34,8 +35,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; -import com.google.common.io.Files; - import junit.framework.TestCase; @@ -136,11 +135,12 @@ private void clean(File f) public void testZipDirectory() { try { - File dir = Files.createTempDir(); + final String prefix = "test_ome"; + File dir = Files.createTempDirectory(prefix).toFile(); File f = File.createTempFile("testZipDirectory", ".tmp", dir); File zip = IOUtil.zipDirectory(dir); assertEquals(FilenameUtils.getExtension(zip.getName()), "zip"); - File destDir = Files.createTempDir(); + File destDir = Files.createTempDirectory(prefix).toFile(); boolean b = unzip(zip, destDir); assertEquals(true, b); File[] files = destDir.listFiles(); @@ -159,15 +159,16 @@ public void testZipDirectory() public void testZipDirectoryWithSubfolder() { try { - File dir = Files.createTempDir(); + final String prefix = "test_ome"; + File dir = Files.createTempDirectory(prefix).toFile(); File f = File.createTempFile("testZipDirectoryWithSubfolder", ".tmp", dir); - File subfolder = Files.createTempDir(); + File subfolder = Files.createTempDirectory(prefix).toFile(); File f1 = File.createTempFile("sub_testZipDirectoryWithSubfolder", ".tmp", subfolder); FileUtils.moveDirectoryToDirectory(subfolder, dir, false); File zip = IOUtil.zipDirectory(dir); - File destDir = Files.createTempDir(); + File destDir = Files.createTempDirectory(prefix).toFile(); boolean b = unzip(zip, destDir); assertEquals(true, b); File[] files = destDir.listFiles();