mx4j/src/core/javax/management/loading MLet.java,1.24,1.25
Simone Bordet <[email protected]> Thu, 14 Oct 2004 07:47:42 +0000
| Newsgroups | gmane.comp.java.mx4j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mx4j/mx4j/src/core/javax/management/loading
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14251/src/core/javax/management/loading
Modified Files:
MLet.java
Log Message:
Fixed bug #1041478: MLet loading libraries and having the library directory in classpath was overwriting library with 0 length file.
Index: MLet.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/javax/management/loading/MLet.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** MLet.java 4 Sep 2004 15:44:03 -0000 1.24
--- MLet.java 14 Oct 2004 07:47:40 -0000 1.25
***************
*** 484,501 ****
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Loading library " + library);
InputStream is = null;
OutputStream os = null;
try
{
! is = getResourceAsStream(library);
! if (is == null) return null;
! is = new BufferedInputStream(is);
! File file = new File(getLibraryDirectory(), library);
! if (file.exists()) file.delete();
! os = new BufferedOutputStream(new FileOutputStream(file));
! readFromAndWriteTo(is, os);
! os.close();
! is.close();
! return file.getCanonicalPath();
}
catch (IOException x)
--- 484,521 ----
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Loading library " + library);
+ URL libraryURL = getResource(library);
+
InputStream is = null;
OutputStream os = null;
try
{
! try
! {
! is = getResourceAsStream(library);
! if (is == null) return null;
!
! if (!(is instanceof BufferedInputStream)) is = new BufferedInputStream(is);
! File localLibrary = new File(getLibraryDirectory(), library);
! URL localLibraryURL = localLibrary.toURL();
!
! // The library is local and its directory is in the classpath of this MLet
! if (localLibraryURL.equals(libraryURL)) return localLibrary.getCanonicalPath();
!
! // Copy the library (that can be remote) locally, overwriting old versions
! try
! {
! os = new BufferedOutputStream(new FileOutputStream(localLibrary));
! readFromAndWriteTo(is, os);
! return localLibrary.getCanonicalPath();
! }
! finally
! {
! if (os != null) os.close();
! }
! }
! finally
! {
! if (is != null) is.close();
! }
}
catch (IOException x)
***************
*** 508,512 ****
private void readFromAndWriteTo(InputStream is, OutputStream os) throws IOException
{
! byte[] buffer = new byte[512];
int read = -1;
while ((read = is.read(buffer)) >= 0) os.write(buffer, 0, read);
--- 528,532 ----
private void readFromAndWriteTo(InputStream is, OutputStream os) throws IOException
{
! byte[] buffer = new byte[64];
int read = -1;
while ((read = is.read(buffer)) >= 0) os.write(buffer, 0, read);
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl