public static boolean deleteDir(final File dir) throws IOException { return deleteDir(dir, 1, 0); }
public static boolean deleteDir(final File dir) throws IOException { return deleteDir(dir, 1, 0); }
protected void writeBusinessArchiveToFile(final BusinessArchive businessArchive, final File businessArchiveFile, List<BusinessArchiveContribution> contributions) throws IOException { final File tempFile = File.createTempFile("tempBarFolder", null); tempFile.delete(); tempFile.mkdir(); try { writeBusinessArchiveToFolder(businessArchive, tempFile); zipBarFolder(businessArchiveFile, tempFile); } finally { IOUtil.deleteDir(tempFile); } }
protected void writeBusinessArchiveToFile(final BusinessArchive businessArchive, final File businessArchiveFile, List<BusinessArchiveContribution> contributions) throws IOException { final File tempFile = File.createTempFile("tempBarFolder", null); tempFile.delete(); tempFile.mkdir(); try { writeBusinessArchiveToFolder(businessArchive, tempFile); zipBarFolder(businessArchiveFile, tempFile); } finally { IOUtil.deleteDir(tempFile); } }
public static boolean deleteDir(final File dir, final int attempts, final long sleepTime) throws IOException { if (dir != null) { boolean result = true; if (!dir.exists()) { return true; //already deleted } if (!dir.isDirectory()) { throw new IOException("Unable to delete directory: " + dir + ", it is not a directory"); } for (final File file : dir.listFiles()) { if (file.isDirectory()) { result &= deleteDir(file, attempts, sleepTime); } else { result &= deleteFile(file, attempts, sleepTime); } } return result && deleteFile(dir, attempts, sleepTime); } return false; }
public static boolean deleteDir(final File dir, final int attempts, final long sleepTime) throws IOException { if (dir != null) { boolean result = true; if (!dir.exists()) { return true; //already deleted } if (!dir.isDirectory()) { throw new IOException("Unable to delete directory: " + dir + ", it is not a directory"); } for (final File file : dir.listFiles()) { if (file.isDirectory()) { result &= deleteDir(file, attempts, sleepTime); } else { result &= deleteFile(file, attempts, sleepTime); } } return result && deleteFile(dir, attempts, sleepTime); } return false; }
protected BusinessArchive readBusinessArchive(final InputStream inputStream, List<BusinessArchiveContribution> contributions) throws IOException, InvalidBusinessArchiveFormatException { File barFolder = File.createTempFile("tempBarFolder", null); barFolder.delete(); barFolder.mkdir(); try { IOUtil.unzipToFolder(inputStream, barFolder); return getBusinessArchive(barFolder, contributions); } catch (final InvalidBusinessArchiveFormatException e) { throw e; } catch (final Exception e) { throw new InvalidBusinessArchiveFormatException("Invalid format, can't read the BAR file", e); } finally { IOUtil.deleteDir(barFolder); } }
protected BusinessArchive readBusinessArchive(final InputStream inputStream, List<BusinessArchiveContribution> contributions) throws IOException, InvalidBusinessArchiveFormatException { File barFolder = File.createTempFile("tempBarFolder", null); barFolder.delete(); barFolder.mkdir(); try { IOUtil.unzipToFolder(inputStream, barFolder); return getBusinessArchive(barFolder, contributions); } catch (final InvalidBusinessArchiveFormatException e) { throw e; } catch (final Exception e) { throw new InvalidBusinessArchiveFormatException("Invalid format, can't read the BAR file", e); } finally { IOUtil.deleteDir(barFolder); } }
public static File createTempDirectory(final URI directoryPath) { final File tmpDir = new File(directoryPath); tmpDir.setReadable(true); tmpDir.setWritable(true); mkdirs(tmpDir); try { // to initialize internal class FilenameUtils. Otherwise it cannot load the class as the shutdown is in progress: FileUtils.isSymlink(tmpDir); } catch (IOException ignored) { } try { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { final boolean deleted = deleteDir(tmpDir); if (!deleted) { System.err.println( "Unable to delete directory: " + tmpDir + ". Trying with an alternative force delete."); FileUtils.forceDelete(tmpDir); } } catch (final IOException e) { throw new BonitaRuntimeException(e); } })); } catch (IllegalStateException ignored) { // happen in case of hook already registered and when shutting down } return tmpDir; }
public static File createTempDirectory(final URI directoryPath) { final File tmpDir = new File(directoryPath); tmpDir.setReadable(true); tmpDir.setWritable(true); mkdirs(tmpDir); try { // to initialize internal class FilenameUtils. Otherwise it cannot load the class as the shutdown is in progress: FileUtils.isSymlink(tmpDir); } catch (IOException ignored) { } try { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { final boolean deleted = deleteDir(tmpDir); if (!deleted) { System.err.println( "Unable to delete directory: " + tmpDir + ". Trying with an alternative force delete."); FileUtils.forceDelete(tmpDir); } } catch (final IOException e) { throw new BonitaRuntimeException(e); } })); } catch (IllegalStateException ignored) { // happen in case of hook already registered and when shutting down } return tmpDir; }