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

com.ebay.sdk.helper.cache.BaseDownloader Maven / Gradle / Ivy

There is a newer version: 939.0.0
Show newest version
/*
Copyright (c) 2013 eBay, Inc.
This program is licensed under the terms of the eBay Common Development and
Distribution License (CDDL) Version 1.0 (the "License") and any subsequent  version 
thereof released by eBay.  The then-current version of the License can be found 
at http://www.opensource.org/licenses/cddl1.php and in the eBaySDKLicense file that 
is under the eBay SDK ../docs directory.
*/

package com.ebay.sdk.helper.cache;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.ebay.sdk.ApiContext;

/**
 * Base class for meta-data cache
 * @author Conan & William
 *
 */
public abstract class BaseDownloader {
	
	protected ApiContext apiContext;
	protected String FILE_NAME_PATTERN = "{0}_{1}"; // pattern: site_lastUpdateTime
	protected String FILE_EXTENSION = "null"; // specified by subclass
	protected String FILE_PREFIX = ""; // specified by subclass
	protected String ROOT_DIR; //root directory for meta-data cache
	protected String lastUpdateTime; //the latest update time of the meta-data
	
	public BaseDownloader(ApiContext apiContext){
		this.apiContext = apiContext;
	}
	
	//initialize ROOT_DIR and lastUpdateTime
	private void init() throws Exception{
		ROOT_DIR = new File (".").getCanonicalPath();
		this.lastUpdateTime = getLastUpdateTime();
	}
	
	//search latest file in the root directory
	private String searchFile() throws Exception{
		File dir = new File(ROOT_DIR);
		String[] dataFiles = getDataFiles(dir);
		return foundLatest(dataFiles);
	}
	
	//find the latest cached file
	private String foundLatest(String[] dataFiles) {
		String name = java.text.MessageFormat.format(FILE_PREFIX+ "_"+FILE_NAME_PATTERN,
				new Object[]{apiContext.getSite().toString(),lastUpdateTime});
		for(int i = 0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy