changeset 209:f8c82fea551a

Servlet version 1.18b9 -- cleanup and bugfixes - fixed bug with slow color JPEGs - better pathname handling - better filehandle cleanup (hopefully)
author robcast
date Fri, 12 Mar 2004 19:52:07 +0100
parents 460cd1f18b96
children cbc3f8697c7f
files servlet/src/digilib/image/JAIImageLoaderDocuImage.java servlet/src/digilib/io/AliasingDocuDirCache.java servlet/src/digilib/io/DocuDirCache.java servlet/src/digilib/io/FileOps.java servlet/src/digilib/servlet/Scaler.java
diffstat 5 files changed, 27 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/JAIImageLoaderDocuImage.java	Fri Mar 12 19:52:06 2004 +0100
+++ b/servlet/src/digilib/image/JAIImageLoaderDocuImage.java	Fri Mar 12 19:52:07 2004 +0100
@@ -82,7 +82,8 @@
 
 	/* Load an image file into the Object. */
 	public void loadImage(ImageFile f) throws FileOpException {
-		System.gc();
+		logger.debug("loadImage: "+f.getFile());
+		//System.gc();
 		img = JAI.create("ImageRead", f.getFile().getAbsolutePath());
 		if (img == null) {
 			throw new FileOpException("Unable to load File!");
@@ -91,22 +92,25 @@
 
 	/* Get an ImageReader for the image file. */
 	public void preloadImage(ImageFile f) throws IOException {
-		System.gc();
+		logger.debug("preloadImage: "+f.getFile());
+		//System.gc();
 		RandomAccessFile rf = new RandomAccessFile(f.getFile(), "r");
 		ImageInputStream istream = ImageIO.createImageInputStream(rf);
 		//Iterator readers = ImageIO.getImageReaders(istream);
 		Iterator readers = ImageIO.getImageReadersByMIMEType(f.getMimetype());
 		reader = (ImageReader) readers.next();
-		reader.setInput(istream);
 		if (reader == null) {
 			throw new FileOpException("Unable to load File!");
 		}
+		logger.debug("JAIImageIO: this reader: " + reader.getClass());
+		reader.setInput(istream);
 	}
 
 	/* Load an image file into the Object. */
 	public void loadSubimage(ImageFile f, Rectangle region, int prescale)
 		throws FileOpException {
-		System.gc();
+		logger.debug("loadSubimage: "+f.getFile());
+		//System.gc();
 		try {
 			if ((reader == null) || (imgFile != f.getFile())) {
 				preloadImage(f);
@@ -136,6 +140,7 @@
 	/* Write the current image to an OutputStream. */
 	public void writeImage(String mt, OutputStream ostream)
 		throws FileOpException {
+		logger.debug("writeImage");
 		try {
 			// setup output
 			ParameterBlock pb3 = new ParameterBlock();
@@ -160,11 +165,15 @@
 	 * @see java.lang.Object#finalize()
 	 */
 	protected void finalize() throws Throwable {
+		dispose();
+		super.finalize();
+	}
+
+	public void dispose() {
 		// we must dispose the ImageReader because it keeps the filehandle open!
 		reader.dispose();
 		reader = null;
 		img = null;
-		super.finalize();
 	}
 
 }
--- a/servlet/src/digilib/io/AliasingDocuDirCache.java	Fri Mar 12 19:52:06 2004 +0100
+++ b/servlet/src/digilib/io/AliasingDocuDirCache.java	Fri Mar 12 19:52:07 2004 +0100
@@ -66,7 +66,7 @@
 		 */
 		
 		for (Iterator i = pathMap.keySet().iterator(); i.hasNext();) {
-			String link = (String)i.next();
+			String link = FileOps.normalName((String)i.next());
 			String dir = (String) pathMap.get(link);
 			DocuDirectory destDir = new DocuDirectory(dir, this);
 			if (destDir.isValid()) {
--- a/servlet/src/digilib/io/DocuDirCache.java	Fri Mar 12 19:52:06 2004 +0100
+++ b/servlet/src/digilib/io/DocuDirCache.java	Fri Mar 12 19:52:07 2004 +0100
@@ -134,7 +134,8 @@
 	public List getChildren(String dirname, boolean recurse) {
 		List l = new LinkedList();
 		for (Iterator i = map.keySet().iterator(); i.hasNext();) {
-			DocuDirectory dd = (DocuDirectory) i.next();
+			String n = (String) i.next();
+			DocuDirectory dd = (DocuDirectory) map.get(n);
 			if (recurse) {
 				if (dd.getDirName().startsWith(dirname)) {
 					l.add(dd);
--- a/servlet/src/digilib/io/FileOps.java	Fri Mar 12 19:52:06 2004 +0100
+++ b/servlet/src/digilib/io/FileOps.java	Fri Mar 12 19:52:07 2004 +0100
@@ -192,15 +192,18 @@
 			return null;
 		}
 		int a = 0;
-		int e = pathname.length();
+		int e = pathname.length() - 1;
+		if (e < 0) {
+			return pathname;
+		}
 		// leading and trailing "/" are removed
-		if (pathname.startsWith("/")) {
+		while ((a <= e) && (pathname.charAt(a) == '/')) {
 			a++;
 		}
-		if (pathname.endsWith("/")) {
+		while ((a < e) && (pathname.charAt(e) == '/')) {
 			e--; 
 		}
-		return pathname.substring(a, e);
+		return pathname.substring(a, e + 1);
 	}
 	
 	
--- a/servlet/src/digilib/servlet/Scaler.java	Fri Mar 12 19:52:06 2004 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Fri Mar 12 19:52:07 2004 +0100
@@ -59,7 +59,7 @@
 public class Scaler extends HttpServlet {
 
 	// digilib servlet version (for all components)
-	public static final String dlVersion = "1.18b6";
+	public static final String dlVersion = "1.18b9";
 
 	// logger for accounting requests
 	Logger accountlog = Logger.getLogger("account.request");
@@ -760,6 +760,8 @@
 			docuImage.writeImage(mimeType, response.getOutputStream());
 
 			logger.info("Done in " + (System.currentTimeMillis() - startTime) + "ms");
+			
+			docuImage.dispose();
 
 			/* error handling */
 
@@ -813,7 +815,6 @@
 				}
 			} catch (FileOpException ex) {
 			} // so we don't get a loop
-
 		}
 	}