You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2010/06/14 18:06:04 UTC
svn commit: r954531 - in
/harmony/enhanced/java/trunk/classlib/modules/imageio/src:
main/java/javax/imageio/ImageIO.java test/java/javax/imageio/ImageIOTest.java
Author: tellison
Date: Mon Jun 14 16:06:03 2010
New Revision: 954531
URL: http://svn.apache.org/viewvc?rev=954531&view=rev
Log:
Apply patch HARMONY-6549 (Implementation of methods: setUseCache, getUseCache, setCacheDirectory and getCacheDirectory )
Modified:
harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java
harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java
Modified: harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java?rev=954531&r1=954530&r2=954531&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageIO.java Mon Jun 14 16:06:03 2010
@@ -39,7 +39,8 @@ import org.apache.harmony.x.imageio.inte
public final class ImageIO {
private static final IIORegistry registry = IIORegistry.getDefaultInstance();
-
+ private static final Cache cacheInfo = new Cache();
+
private ImageIO() {}
@@ -48,24 +49,20 @@ public final class ImageIO {
throw new NotImplementedException();
}
- public static void setUseCache(boolean useCache) throws NotImplementedException {
- // TODO: implement
+ public static void setUseCache(boolean useCache) {
+ cacheInfo.setUseCache(useCache);
}
- public static boolean getUseCache() throws NotImplementedException {
- // TODO: implement
- return false;
+ public static boolean getUseCache() {
+ return cacheInfo.getUseCache();
}
- public static void setCacheDirectory(File cacheDirectory) throws NotImplementedException {
- // TODO: implement
- throw new NotImplementedException();
+ public static void setCacheDirectory(File cacheDirectory) {
+ cacheInfo.setCacheDirectory(cacheDirectory);
}
- public static File getCacheDirectory() throws NotImplementedException {
- // TODO: implement
- //-- null indicates system-dep default temporary directory
- return null;
+ public static File getCacheDirectory() {
+ return cacheInfo.getCacheDirectory();
}
public static ImageInputStream createImageInputStream(Object input)
@@ -414,6 +411,46 @@ public final class ImageIO {
return rt;
}
+ private static class Cache {
+ private boolean useCache = true;
+ private File cacheDirectory = null;
+
+ public Cache() {
+ }
+
+ public File getCacheDirectory() {
+ return cacheDirectory;
+ }
+
+ public void setCacheDirectory(File cacheDirectory) {
+ if ((cacheDirectory != null) && (!cacheDirectory.isDirectory())) {
+ throw new IllegalArgumentException(Messages.getString("imageio.0B"));
+ }
+
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ String filepath;
+
+ if (cacheDirectory == null) {
+ filepath = System.getProperty("java.io.tmpdir");
+ } else {
+ filepath = cacheDirectory.getPath();
+ }
+
+ security.checkWrite(filepath);
+ }
+
+ this.cacheDirectory = cacheDirectory;
+ }
+
+ public boolean getUseCache() {
+ return useCache;
+ }
+
+ public void setUseCache(boolean useCache) {
+ this.useCache = useCache;
+ }
+ }
/**
* Filter to match spi by format name
Modified: harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java?rev=954531&r1=954530&r2=954531&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageIOTest.java Mon Jun 14 16:06:03 2010
@@ -17,6 +17,7 @@
package javax.imageio;
+import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
@@ -50,6 +51,24 @@ public class ImageIOTest extends TestCas
return img;
}
+
+ public void testCache() throws Exception {
+ ImageIO.setUseCache(true);
+ assertTrue("Failed to enable cache", ImageIO.getUseCache());
+ ImageIO.setUseCache(false);
+ assertFalse("Failed to disable cache", ImageIO.getUseCache());
+
+ ImageIO.setCacheDirectory(null);
+ assertNull("Failed to set cache directory", ImageIO.getCacheDirectory());
+
+ try {
+ ImageIO.setCacheDirectory(new File(""));
+ fail("IllegalArgumentException expected");
+ }
+ catch (IllegalArgumentException expected) {
+ //OK
+ }
+ }
private void testFormat(String format) {
ImageReader reader = ImageIO.getImageReadersByFormatName(format).next();