• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

File Lock I cant seem to find - can you?

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im building an app that allows photos to be uploaded to a server. I had it going perfect with jpeg and gif images only but I wanted to support tiffs and if they uploaded a tiff, convert it to a jpeg.

Anyways I have it all working fine .... not 100% thrilled with the logic yet but its getting there. Im having a problem though deleting the tiffs once Ive created the new jpeg. I know its a file lock someplace because I cant delete them thru Windows explorer either but MAN I can find the stinking lock!

Here's the code that calls the convertor (its done with a try catch as they ARENT supposed to be uploading TIFFs:

java.io.FileInputStream in = new java.io.FileInputStream(sc.getRealPath("/images/galleries/"+galleryID+"/")+images.elementAt(x));
com.sun.image.codec.jpeg.JPEGImageDecoder decoder = null;
java.awt.image.BufferedImage image = null;

try{
decoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(in);
image = decoder.decodeAsBufferedImage();
}
catch (com.sun.image.codec.jpeg.ImageFormatException ife) {
in.close();
String jpeg = new ConvertTiff().convertTiff((String)images.elementAt(x), sc, galleryID);
in = new java.io.FileInputStream(sc.getRealPath("/images/galleries/"+galleryID+"/")+jpeg);

decoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(in);
image = decoder.decodeAsBufferedImage();
images.remove(x);
images.add(x, jpeg);
}
in.close();


AND here is the ConvertTiff class:

class ConvertTiff{

public String convertTiff(String tiffFile, javax.servlet.ServletContext sc, String galleryID) throws java.io.IOException{

String fileName = tiffFile.substring(0, tiffFile.indexOf("."));

String outputFile = fileName+".jpg";

String fullOut = sc.getRealPath("/images/galleries/"+galleryID+"/")+fileName+".jpg";

// Load the input image.
javax.media.jai.RenderedOp src = javax.media.jai.JAI.create("fileload", sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

// Encode the file as a JPEG image.
java.io.FileOutputStream stream = new java.io.FileOutputStream(fullOut);
javax.media.jai.JAI.create("encode", src, stream, "JPEG", null);

// Store the image in the BMP format.
javax.media.jai.JAI.create("filestore", src, fullOut, "JPEG", null);

stream.close();

java.io.File oldFile = new java.io.File(sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

if (oldFile.exists()){
oldFile.delete();
}
return outputFile;
}
};

Now I AM getting into the if oldFile.exists() with no problem ... but as I said its not deleting either in my app OR in Windows explorer so Ive got a lock on the file someplace ... Im just not seeing it..

Thanks in advance!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ThIs is just a WAG, but you've created two RenderedOps, but dispose()d neither of them. Does that help?
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the point in the right direction but Im still having the problem after adding the dispose() to each of the RenderedOp objects ... just cant seem to nail it down. Heres the updated ConvertTiff class:

class ConvertTiff{

protected String convertTiff(String tiffFile, javax.servlet.ServletContext sc, String galleryID) throws java.io.IOException{

String fileName = tiffFile.substring(0, tiffFile.indexOf("."));

String outputFile = fileName+".jpg";

String fullOut = sc.getRealPath("/images/galleries/"+galleryID+"/")+fileName+".jpg";

// Load the input image.
javax.media.jai.RenderedOp src = javax.media.jai.JAI.create("fileload", sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

// Encode the file as a JPEG image.
java.io.FileOutputStream stream = new java.io.FileOutputStream(fullOut);
javax.media.jai.RenderedOp in = javax.media.jai.JAI.create("encode",src, stream, "JPEG", null);

// Store the image in the BMP format.
javax.media.jai.RenderedOp out = javax.media.jai.JAI.create("filestore",src, fullOut, "JPEG", null);

src.dispose();
stream.close();
in.dispose();
out.dispose();

java.io.File oldFile = new java.io.File(sc.getRealPath("/images/galleries/"+galleryID+"/")+tiffFile);

if (oldFile.exists()){
oldFile.delete();
}
return outputFile;
}
};

the code that calls this method remains the same, Im starting to wonder if its something there but I dont see anything else Ive forgotten to close prior to drop into the convert method..

thanks again!
[ August 08, 2005: Message edited by: DC Dalton ]
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic