Files not always closing when using server-side java

I have a couple of different java classes, one unzips compressed archives and another writes text into image files. If I use them either standalone (in the jvm) or locally in the Notes client, they work ok. But if I take the same code and run it as an agent on a Domino server, the files sometimes don’t always get closed, so any delete, rename or moves fail. If I stop amgr, the files get released. Has anyone else had this problem? Any suggestions?

Subject: File not closing (sample code)

I took out some of the non-essential features, but here is the guts of one of the methods I call (apologies if it doesn’t format well):

public boolean unzipMyFile(String sourceZipFileName, String destDir, String filenameRoot) {

 ZipEntry z;

 final int BUFFER = 2048;

     BufferedOutputStream dest = null;

 try {

	 ZipInputStream in = new ZipInputStream(new FileInputStream(sourceZipFileName));

	 while((z = in.getNextEntry()) != null) {

		 while (z.isDirectory()) {

			 z = in.getNextEntry();

		 }

		 int count;

		 byte data[] = new byte[BUFFER];

		 File f = new File(z.getName());

		 FileOutputStream fos = new  FileOutputStream(destDir + "\\" + filenameRoot + "-" + f.getName());

		 dest = new BufferedOutputStream(fos, BUFFER);

		 while ((count = in.read(data, 0, BUFFER)) != -1) {

		    dest.write(data, 0, count);

		 }

         dest.flush();

         dest.close();

             }

      in.close();

 } catch (Exception e) {

	 e.printStackTrace();

	 return false;

 }

 return true;

}