Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation /
 
 
 /*
  * Created on : 04.2003
  * Created by : s3595
  */
 package at.spardat.xma.boot.cache;
 
 import java.io.File;
 import java.net.URL;
 import java.util.Date;
 
class: FCResource ( File Cached Resource )

Describes an entry in the file-cache.

Author(s):
s3595 Chris Sch�fer (CGS)
Version:
$Id: FCResource.java 2084 2007-11-27 14:53:31Z s3460 $
 
 public class FCResource implements IFileCacheResource {

    
the remote resource location
 
     protected URL location_;

    
info-file about the cached file
 
     protected PropertyFile properties_;

    
resource file
 
     protected File file_;

    
byte array for buffered mode
 
     protected byte[] buffer_;

    
extended readable file output
 
     protected boolean debug;

    
used to format timesamps for debug correctly (converted long milliseconds since 1.1.1970 00:00:00 GMT)
 
     private DateFormat formater;
 
     VersionNumber versionNumber;

    

Create a FCResource for the resources specified as a remote URL.

it is protected, because a resource must not be created by others than the FileCache

If the file does not exist, it will not be created.

Parameters:
location the remote resource location
file the resource file
bmode buffer mode
Throws:
java.io.IOException containing the filename
java.lang.IllegalArgumentException the file must exist already
 
     protected FCResource(URL locationFile fileboolean bmodeboolean debugthrows IOException {
         File infoFile = null;
 
 //        if(location == null || file == null ) {
 //          throw new IllegalArgumentException( Statics.strInvalidARG );
 //        }
         if( !file.exists() ) {
             throw new FileNotFoundException"file: " + file.getAbsolutePath()); //$NON-NLS-1$
         }
 
          = new SimpleDateFormat"EEE, dd MMM yyyy hh:mm:ss zzz", Locale.getDefault() );            //$NON-NLS-1$
         .setTimeZone(new SimpleTimeZone(0, "GMT")); //$NON-NLS-1$
 
         this.       = debug;
         this.   = location;
         this.       = file;
        this.     = null;
        infoFile         = new Filefile.getPath() + .);
        this. = new PropertyFile(infoFiledebug);
        if(bmode) {
            loadBuffer();
        }
    }// FCResource

    
load data from resource file into memory buffer

Returns:
void
Throws:
java.io.IOException containing the filename
    protected void loadBuffer() throws IOException {
        int length     = (int).length();
                = new byte[length];
        InputStream is = null;
        int read       = 0;
        try {
            is = new FileInputStream );
            for(int all=0; all<length ; all+=read ) {
                read = is.readalllength-all );
                if(read<0) {  break; } // error in reading
            }
        } catch (IOException exc) {
            throw new IOException("Error reading resource-file "+.getAbsolutePath());
        } finally {
            Util.close(is,.getAbsolutePath());
        }
        if(read<0) { // loop terminated by error
            throw new IOException("Error reading resource-file "+.getAbsolutePath());
        }
    }

    
Returns the remote location this entry caches.
    public URL getLocation() {
        return ;
    }

    
Saves the current information for the cache entry.

Throws:
java.io.IOException containing the filename
    protected void store() throws IOException {
        .store();
    }

    

Returns:
InputStream
Throws:
java.io.IOException containing the filename
See also:
IFileCacheResource
    public InputStream getInputStream() throws IOException {
        if(== null) {
           loadBuffer();
        }
        return new ByteArrayInputStream();
    }

    
for internal use in file cache only!

Throws:
java.io.IOException containing the filename
    byte[] getBuffer() throws IOException {
        if(==nullloadBuffer();
        return ;
    }

    
Returns the value of the specified key, or null if the key does not exist.

Parameters:
key key to look for
    public String getProperty(String key) {
      return .getProperty(key);
    }

    
Returns the value of the specified key, or the default value if the key does not exist.
    public String getProperty(String keyString defaultValue) {
      return .getProperty(keydefaultValue);
    }

    
Sets the value for the specified key.

Returns:
the previous value
    public Object setProperty(String keyString value) {
        return this..setProperty(key,value);
    }

    
Returns the time in the local system clock that the file was most recently checked for an update.
    public long getLastUpdated() {
        try {
            String strLastUpdated = .getProperty.);
            if(strLastUpdated!=nullreturn Long.parseLong(strLastUpdated);
            else return 0;
        } catch (Exception ex) {
            Logger.getLogger("bootrt.bootRuntime").log(.,
                "error parsing "+.+" in "+.getStoreFile().getAbsolutePath(),ex);
            return 0;
        }
    }

    
Sets the time in the local system clock that the file was most recently checked for an update.
    public void setLastUpdated(long updatedTime) {
        .setProperty(., Long.toString(updatedTime));
        if() {
            .setProperty(. + ".STR".format(new Date(updatedTime)) );
        }
    }
    /* (non-Javadoc)
     * @see at.spardat.xma.cdb.cache.IFileCacheResource#getLastModified()
     */
    public long getLastModified() {
        try {
            String strLastModified = .getProperty.);
            if(strLastModified!=nullreturn Long.parseLong(strLastModified);
            else return 0;
        } catch (Exception ex) {
            Logger.getLogger("bootrt.bootRuntime").log(.,
                    "error parsing "+.+" in "+.getStoreFile().getAbsolutePath(),ex);
            return 0;
        }
    }

    
Sets the value of the last modified header in the resource description file.

Parameters:
lastModified in milliseconds since 1.1.1970
    public void setLastModified(long lastModified) {
        .setProperty(., Long.toString(lastModified));
        if() {
            .setProperty(. + ".STR".format(new Date(lastModified)) );
        }
    }
    /* (non-Javadoc)
     * @see at.spardat.xma.cdb.cache.IFileCacheResource#setExpiration(long)
     */
    public void setExpiration(long lExpires ) {
        .setProperty(., Long.toString(lExpires));
        if() {
            .setProperty(. + ".STR".format(new Date(lExpires)) );
        }
    }
    /* (non-Javadoc)
     * @see at.spardat.xma.cdb.cache.IFileCacheResource#getExpiration()
     */
    public long getExpiration() {
        try {
            String strExpires = .getProperty.);
            if(strExpires!=nullreturn Long.parseLong(strExpires);
            else return 0;
        } catch (Exception ex) {
            Logger.getLogger("bootrt.bootRuntime").log(.,
                    "error parsing "+.+" in "+.getStoreFile().getAbsolutePath(),ex);
            return 0;
        }
    }
    /* (non-Javadoc)
     * @see at.spardat.xma.cdb.cache.IFileCacheResource#setProperty(java.lang.String, long)
     */
    public void setProperty(String stringlong l) {
        this.setProperty(string, Long.toString(l));
    }
    /* (non-Javadoc)
     * @see at.spardat.xma.cdb.cache.IFileCacheResource#getLocalRes()
     */
    public URL getLocalRes() {
        if == null ) {
          return null;
        }
        try {
            return .toURL();
        } catch (MalformedURLException e) {
            throw new RuntimeException("error converting "+.getAbsolutePath()+" to url",e);
        }
    }
    /*
     *  (non-Javadoc)
     * @see at.spardat.xma.boot.cache.IFileCacheResource#isExpired()
     */
    public boolean isExpired() {
        long expires = this.getExpiration();
        long ctime   = System.currentTimeMillis();
        // if the resource has exiriration information set,
        // and it is exired.
        ifexpires != 0 && expires < ctime )
          return true;
        else
          return false;
    }
     File getResourceFile() {
        return ;
     }
     File getProperties() {
        return .getStoreFile();
     }
New to GrepCode? Check out our FAQ X