Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2259 - development/main/transit/core/handler/src/main/net/dpml/transit/cache

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT hedhman.org
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2259 - development/main/transit/core/handler/src/main/net/dpml/transit/cache
  • Date: Sat, 09 Apr 2005 13:09:27 -0400

Author: niclas AT hedhman.org
Date: Sat Apr 9 13:09:22 2005
New Revision: 2259

Modified:

development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
Log:
Remove the use of temporary files for obtaining the internal references in
Jar/Zip files. TRANSIT-2

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/cache/FileCacheHandler.java
Sat Apr 9 13:09:22 2005
@@ -153,52 +153,14 @@
public InputStream getResource( Artifact artifact )
throws IOException, TransitException, NullArgumentException
{
- CacheMonitorRouter monitor =
Transit.getInstance().getCacheMonitorRouter();
- if( monitor != null )
- {
- monitor.resourceRequested( artifact );
- }
+ File destination = getResourceFile( artifact );

- if( null == artifact )
- {
- throw new NullArgumentException( "artifact" );
- }
- String path = m_resolver.resolvePath( artifact );
- File destination = new File( m_cacheDir, path );
- File parentDir = destination.getParentFile();
- parentDir.mkdirs();
- boolean exist = destination.exists();
- boolean success;
- if( exist )
- {
- success = true;
- }
- else
- {
- ResourceHost known = findKnownGroupHost( artifact );
- success = download( known, artifact, destination );
- if( !success )
- {
- ResourceHost any = findAnyPresence( artifact );
- success = download( any, artifact, destination );
- }
- }
- if( success )
- {
- checkInternalConsistency( artifact, destination );
- endNotifyMonitor( monitor, exist, artifact, destination );
- }
if( destination.exists() )
{
FileInputStream stream = new FileInputStream( destination );
return new BufferedInputStream( stream );
}

- if( monitor != null )
- {
- monitor.failedDownload( artifact );
- }
-
String error = "Unresolvable artifact: [" + artifact + "]. (" +
destination + ")";
throw new ArtifactNotFoundException( error, artifact );
}
@@ -233,12 +195,8 @@
ZipFile zip = m_zipCache.get( artifact );
if( zip == null )
{
- InputStream artifactStream = getResource( artifact );
- File tmpFile = File.createTempFile( "~dpml", ".tmp" );
- tmpFile.deleteOnExit();
- FileOutputStream fos = new FileOutputStream( tmpFile );
- StreamUtils.copyStream( artifactStream, fos, true );
- zip = new ZipFile( tmpFile );
+ File resourceFile = getResourceFile( artifact );
+ zip = new ZipFile( resourceFile );
m_zipCache.put( artifact, zip );
}
ZipEntry entry = zip.getEntry( internalReference );
@@ -417,5 +375,56 @@
throw new InternalError( error );
}

+ /** Locates and if necessary downloads the artifact.
+ * @param artifact the Artifact to download and locate in the cache.
+ * @return the File pointing to the artifact. The file may not exist if
the
+ * download has failed.
+ */
+ private File getResourceFile( Artifact artifact )
+ throws TransitException, IOException
+ {
+ CacheMonitorRouter monitor =
Transit.getInstance().getCacheMonitorRouter();
+ if( monitor != null )
+ {
+ monitor.resourceRequested( artifact );
+ }
+
+ if( null == artifact )
+ {
+ throw new NullArgumentException( "artifact" );
+ }
+ String path = m_resolver.resolvePath( artifact );
+ File destination = new File( m_cacheDir, path );
+ File parentDir = destination.getParentFile();
+ parentDir.mkdirs();
+ boolean exist = destination.exists();
+ boolean success;
+ if( exist )
+ {
+ success = true;
+ }
+ else
+ {
+ ResourceHost known = findKnownGroupHost( artifact );
+ success = download( known, artifact, destination );
+ if( !success )
+ {
+ ResourceHost any = findAnyPresence( artifact );
+ success = download( any, artifact, destination );
+ }
+ }
+ if( success )
+ {
+ checkInternalConsistency( artifact, destination );
+ endNotifyMonitor( monitor, exist, artifact, destination );
+ }
+
+ if( !destination.exists() && monitor != null )
+ {
+ monitor.failedDownload( artifact );
+ }
+
+ return destination;
+ }

}



  • svn commit: r2259 - development/main/transit/core/handler/src/main/net/dpml/transit/cache, niclas, 04/09/2005

Archive powered by MHonArc 2.6.24.

Top of Page