src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/mimepull/WeakDataFile.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -31,10 +31,11 @@
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Removing files based on this
* <a href="http://java.sun.com/developer/technicalArticles/javase/finalization/">article</a>
@@ -51,20 +52,24 @@
private final RandomAccessFile raf;
private static boolean hasCleanUpExecutor = false;
static {
CleanUpExecutorFactory executorFactory = CleanUpExecutorFactory.newInstance();
if (executorFactory!=null) {
- LOGGER.fine("Initializing clean up executor for MIMEPULL: "
- + executorFactory.getClass().getName());
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.log(Level.FINE, "Initializing clean up executor for MIMEPULL: {0}", executorFactory.getClass().getName());
+ }
Executor executor = executorFactory.getExecutor();
executor.execute(new Runnable() {
+ @Override
public void run() {
- WeakDataFile weak = null;
+ WeakDataFile weak;
while (true) {
try {
weak = (WeakDataFile) refQueue.remove();
- LOGGER.fine("Cleaning file = "+weak.file+" from reference queue.");
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.log(Level.FINE, "Cleaning file = {0} from reference queue.", weak.file);
+ }
weak.close();
} catch (InterruptedException e) {
}
}
}
@@ -105,35 +110,51 @@
throw new MIMEParsingException(ioe);
}
}
void close() {
- LOGGER.fine("Deleting file = "+file.getName());
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.log(Level.FINE, "Deleting file = {0}", file.getName());
+ }
refList.remove(this);
try {
raf.close();
- file.delete();
+ boolean deleted = file.delete();
+ if (!deleted) {
+ if (LOGGER.isLoggable(Level.INFO)) {
+ LOGGER.log(Level.INFO, "File {0} was not deleted", file.getAbsolutePath());
+ }
+ }
} catch(IOException ioe) {
throw new MIMEParsingException(ioe);
}
}
void renameTo(File f) {
- LOGGER.fine("Moving file="+file+" to="+f);
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.log(Level.FINE, "Moving file={0} to={1}", new Object[]{file, f});
+ }
refList.remove(this);
try {
raf.close();
- file.renameTo(f);
+ boolean renamed = file.renameTo(f);
+ if (!renamed) {
+ if (LOGGER.isLoggable(Level.INFO)) {
+ LOGGER.log(Level.INFO, "File {0} was not moved to {1}", new Object[] {file.getAbsolutePath(), f.getAbsolutePath()});
+ }
+ }
} catch(IOException ioe) {
throw new MIMEParsingException(ioe);
}
}
static void drainRefQueueBounded() {
- WeakDataFile weak = null;
+ WeakDataFile weak;
while (( weak = (WeakDataFile) refQueue.poll()) != null ) {
- LOGGER.fine("Cleaning file = "+weak.file+" from reference queue.");
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.log(Level.FINE, "Cleaning file = {0} from reference queue.", weak.file);
+ }
weak.close();
}
}
}