All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.boot.cache.FCResource Maven / Gradle / Ivy

There is a newer version: 1.16.0
Show newest version
/*******************************************************************************
 * 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.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.SimpleTimeZone;

import at.spardat.xma.boot.Statics;
import at.spardat.xma.boot.logger.LogLevel;
import at.spardat.xma.boot.logger.Logger;
import at.spardat.xma.boot.util.PropertyFile;
import at.spardat.xma.boot.util.Util;


/**
 *
 * class: FCResource ( File Cached Resource ) 

* * Describes an entry in the file-cache.

* * @author 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.

* * @param location the remote resource location * @param file the resource file * @param bmode buffer mode * @throws IOException containing the filename * @throws IllegalArgumentException the file must exist already */ protected FCResource(URL location, File file, boolean bmode, boolean debug) throws 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$ } formater = new SimpleDateFormat( "EEE, dd MMM yyyy hh:mm:ss zzz", Locale.getDefault() ); //$NON-NLS-1$ formater.setTimeZone(new SimpleTimeZone(0, "GMT")); //$NON-NLS-1$ this.debug = debug; this.location_ = location; this.file_ = file; this.buffer_ = null; infoFile = new File( file.getPath() + Statics.FILEINFO_EXT); this.properties_ = new PropertyFile(infoFile, debug); if(bmode) { loadBuffer(); } }// FCResource /** * load data from resource file into memory buffer * * @return void * @throws IOException containing the filename */ protected void loadBuffer() throws IOException { int length = (int)file_.length(); buffer_ = new byte[length]; InputStream is = null; int read = 0; try { is = new FileInputStream( file_ ); for(int all=0; all





© 2015 - 2024 Weber Informatics LLC | Privacy Policy