You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2006/09/26 10:08:23 UTC
svn commit: r449941 - in
/incubator/harmony/enhanced/classlib/trunk/modules/logging:
META-INF/MANIFEST.MF src/main/java/java/util/logging/FileHandler.java
src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java
Author: pyang
Date: Tue Sep 26 01:08:16 2006
New Revision: 449941
URL: http://svn.apache.org/viewvc?view=rev&rev=449941
Log:
FileHandler locks a temp .lck file instead of the log file itself, so that other process can display the log file during the usage.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/logging/META-INF/MANIFEST.MF
incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/META-INF/MANIFEST.MF?view=diff&rev=449941&r1=449940&r2=449941
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/META-INF/MANIFEST.MF (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/META-INF/MANIFEST.MF Tue Sep 26 01:08:16 2006
@@ -11,11 +11,12 @@
java.net,
java.nio;resolution:=optional,
java.nio.channels,
+ java.nio.channels.spi,
java.nio.charset,
java.security,
java.text,
java.util,
org.apache.harmony.kernel.vm,
- tests.util;hy_usage=test;resolution:=optional,
- org.apache.harmony.testframework.serialization;hy_usage=test;resolution:=optional
+ org.apache.harmony.testframework.serialization;hy_usage=test;resolution:=optional,
+ tests.util;hy_usage=test;resolution:=optional
Export-Package: java.util.logging
Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java?view=diff&rev=449941&r1=449940&r2=449941
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java Tue Sep 26 01:08:16 2006
@@ -101,6 +101,8 @@
*/
public class FileHandler extends StreamHandler {
+ private static final String LCK_EXT = ".lck";
+
/*
* ---------------------------------------------
* constants
@@ -191,8 +193,6 @@
}
private void initOutputFiles() throws FileNotFoundException, IOException {
- FileOutputStream fileStream = null;
- FileChannel channel = null;
while (true) {
//try to find a unique file which is not locked by other process
uniqueID++;
@@ -216,8 +216,8 @@
files[i - 1].renameTo(files[i]);
}
}
- fileStream = new FileOutputStream(fileName, append);
- channel = fileStream.getChannel();
+ FileOutputStream fileStream = new FileOutputStream(fileName+LCK_EXT);
+ FileChannel channel = fileStream.getChannel();
/*
* if lock is unsupported and IOException thrown, just let the
* IOException throws out and exit otherwise it will go into an
@@ -236,7 +236,7 @@
break;
}
}
- output = new MeasureOutputStream(new BufferedOutputStream(fileStream),
+ output = new MeasureOutputStream(new BufferedOutputStream(new FileOutputStream(fileName, append)),
files[0].length());
setOutputStream(output);
}
@@ -565,7 +565,11 @@
super.close();
allLocks.remove(fileName);
try {
+ FileChannel channel = lock.channel();
lock.release();
+ channel.close();
+ File file = new File(fileName+LCK_EXT);
+ file.delete();
} catch (IOException e) {
//ignore
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java?view=diff&rev=449941&r1=449940&r2=449941
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java Tue Sep 26 01:08:16 2006
@@ -27,6 +27,7 @@
import java.io.PrintStream;
import java.io.Reader;
import java.io.StringWriter;
+import java.nio.channels.FileChannel;
import java.security.Permission;
import java.util.Properties;
import java.util.logging.FileHandler;
@@ -396,7 +397,12 @@
try {
System.setSecurityManager(new MockFileSecurityManager());
handler.publish(new LogRecord(Level.SEVERE, "msg"));
- handler.close();
+ try {
+ handler.close();
+ fail("should throw security exception");
+ } catch (SecurityException e) {
+ }
+
try {
handler = new FileHandler();
fail("should throw security exception");
@@ -672,5 +678,4 @@
super.setOutputStream(stream);
}
}
-
}