it.tidalwave.bluebill.taxonomy.elmo.impl.ElmoImporter Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Core - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it
* SCM: https://kenai.com/hg/bluebill~core-src
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.taxonomy.elmo.impl;
import javax.annotation.Nonnull;
import java.util.zip.GZIPInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import it.tidalwave.util.logging.Logger;
import it.tidalwave.bluebill.taxonomy.io.Importer;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryException;
import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFParseException;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class ElmoImporter implements Importer
{
private static final String CLASS = ElmoImporter.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void import_ (final @Nonnull Object repository, final @Nonnull File file)
throws IOException
{
try
{
InputStream is = new FileInputStream(file);
if (file.getName().endsWith(".gz"))
{
is = new GZIPInputStream(is);
}
final Reader r = new InputStreamReader(is, "UTF-8");
((Repository)repository).getConnection().add(r, "http://foo.bar", RDFFormat.RDFXML); // FIXME
r.close();
}
catch (RDFParseException e)
{
throw new IOException(e.toString()); // Java 5/Android compatibility
}
catch (RepositoryException e)
{
throw new IOException(e.toString()); // Java 5/Android compatibility
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy