From 9c8be5897d3d19564cf7401b42414e49dcc816ae Mon Sep 17 00:00:00 2001 From: wisberg Date: Sun, 25 May 2003 19:24:06 +0000 Subject: [PATCH] delete, close, and isEmpty --- .../aspectj/internal/tools/build/Util.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/build/src/org/aspectj/internal/tools/build/Util.java b/build/src/org/aspectj/internal/tools/build/Util.java index 27ca9e1b4..a8d1d2681 100644 --- a/build/src/org/aspectj/internal/tools/build/Util.java +++ b/build/src/org/aspectj/internal/tools/build/Util.java @@ -14,6 +14,7 @@ package org.aspectj.internal.tools.build; +import java.io.*; import java.io.File; import java.io.FileFilter; import java.io.IOException; @@ -130,6 +131,15 @@ public class Util { return (null != file) && file.canRead() && file.isFile(); } + /** + * Delete file or directory. + * @param dir the File file or directory to delete. + * @return true if all contents of dir were deleted + */ + public static boolean delete(File dir) { + return deleteContents(dir) && dir.delete(); + } + /** * Delete contents of directory. * The directory itself is not deleted. @@ -169,6 +179,30 @@ public class Util { } return tempFile; } + /** + * Close stream with the usual checks. + * @param stream the InputStream to close - ignored if null + * @return null if closed without IOException, message otherwise + */ + public static String close(Writer stream) { + String result = null; + if (null != stream) { + try { + stream.close(); + } catch(IOException e) { + result = e.getMessage(); + } + } + return result; + } + + /** + * @param list the Object[] to test + * @return true if list is null or empty + */ + public static boolean isEmpty(Object[] list) { + return ((null == list) || (0 == list.length)); + } } -- 2.39.5