return new BufferedOutputStream(new FileOutputStream(file));
}
+ /**
+ * Sleep until after the last last-modified stamp from the files.
+ * @param files the File[] of files to inspect for last modified times
+ * (this ignores null or empty files array
+ * and null or non-existing components of files array)
+ * @return true if succeeded without 100 interrupts
+ */
+ public static boolean sleepPastFinalModifiedTime(File[] files) {
+ if ((null == files) || (0 == files.length)) {
+ return true;
+ }
+ long delayUntil = System.currentTimeMillis();
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+ if ((null == file) || !file.exists()) {
+ continue;
+ }
+ long nextModTime = file.lastModified();
+ if (nextModTime > delayUntil) {
+ delayUntil = nextModTime;
+ }
+ }
+ return LangUtil.sleepUntil(++delayUntil);
+ }
+
/** map name to result, removing any fromSuffix and adding any toSuffix */
private static String map(String name, String fromSuffix, String toSuffix) {
if (null != name) {
protected void completing(long totalWritten, Throwable thrown) {
}
}
+
}
}
}
return result;
+ }
+
+ /**
+ * Sleep for a particular period (in milliseconds).
+ * @param time the long time in milliseconds to sleep
+ * @return true if delay succeeded, false if interrupted 100 times
+ */
+ public static boolean sleep(long milliseconds) {
+ if (milliseconds == 0) {
+ return true;
+ } else if (milliseconds < 0) {
+ throw new IllegalArgumentException("negative: " + milliseconds);
+ }
+ return sleepUntil(milliseconds + System.currentTimeMillis());
+ }
+
+ /**
+ * Sleep until a particular time.
+ * @param time the long time in milliseconds to sleep until
+ * @return true if delay succeeded, false if interrupted 100 times
+ */
+ public static boolean sleepUntil(long time) {
+ if (time == 0) {
+ return true;
+ } else if (time < 0) {
+ throw new IllegalArgumentException("negative: " + time);
+ }
+ final Thread thread = Thread.currentThread();
+ long curTime = System.currentTimeMillis();
+ for (int i = 0; (i < 100) && (curTime < time); i++) {
+ try {
+ thread.sleep(time-curTime);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ curTime = System.currentTimeMillis();
+ }
+ return (curTime >= time);
}
/**
}
}
} // class Thrown
- } // class ProcessController
+ }
+
}