001: /*---------------- FILE HEADER ------------------------------------------
002:
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: EXSE, Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014:
015: This library is distributed in the hope that it will be useful,
016: but WITHOUT ANY WARRANTY; without even the implied warranty of
017: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: Lesser General Public License for more details.
019:
020: You should have received a copy of the GNU Lesser General Public
021: License along with this library; if not, write to the Free Software
022: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023:
024: Contact:
025:
026: Andreas Poth
027: lat/lon GmbH
028: Aennchenstr. 19
029: 53115 Bonn
030: Germany
031: E-Mail: poth@lat-lon.de
032:
033: Prof. Dr. Klaus Greve
034: Department of Geography
035: University of Bonn
036: Meckenheimer Allee 166
037: 53115 Bonn
038: Germany
039: E-Mail: greve@giub.uni-bonn.de
040:
041:
042: ---------------------------------------------------------------------------*/
043: package org.deegree.tools.importer;
044:
045: import java.io.BufferedInputStream;
046: import java.io.File;
047: import java.io.FileInputStream;
048: import java.io.FileNotFoundException;
049: import java.io.IOException;
050: import java.util.ArrayList;
051: import java.util.List;
052:
053: import org.deegree.framework.log.ILogger;
054: import org.deegree.framework.log.LoggerFactory;
055:
056: /**
057: *
058: * The <code>FileLoader</code> loads a file from given path.
059: *
060: * @author <a href="mailto:buesching@lat-lon.de">Lyn Buesching</a>
061: * @author last edited by: $Author: buesching $
062: *
063: * @version $Revision: 1.1 $, $Date: 2007-10-10 14:21:26 $
064: *
065: */
066: public class FileLoader implements Loader {
067:
068: private static final ILogger LOG = LoggerFactory
069: .getLogger(FileLoader.class);
070:
071: /**
072: * @param objectToLoad contains an Array of strings, where the first
073: * entry contains the source to load and the second the target to export
074: * @return an ArrayList of objects, where the first object contains an
075: * Array of bytes to export and the second object the information
076: * of the target to export
077: */
078: public Object loadObject(Object objectToLoad) {
079: List<Object> result = new ArrayList<Object>();
080: String source = ((String[]) objectToLoad)[0];
081: LOG.logInfo(Messages.getString("FileLoader.LOAD", source));
082: File file = new File(source);
083: int fileLength = (int) file.length();
084: byte[] byteArray = new byte[fileLength];
085: try {
086: FileInputStream fileIS = new FileInputStream(file);
087: BufferedInputStream bufferedIS = new BufferedInputStream(
088: fileIS);
089: bufferedIS.read(byteArray, 0, fileLength);
090: bufferedIS.close();
091: fileIS.close();
092: result.add(byteArray);
093: result.add(((String[]) objectToLoad)[1]);
094: return result;
095: } catch (FileNotFoundException e) {
096: e.printStackTrace();
097: return null;
098: } catch (IOException e) {
099: e.printStackTrace();
100: return null;
101: }
102: }
103:
104: }
|