info.aduna.io.FileUtil Java Examples

The following examples show how to use info.aduna.io.FileUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OWLCompiler.java    From anno4j with Apache License 2.0 5 votes vote down vote up
/**
 * Build concepts and behaviours, compile them and save them to this jar file
 * 
 * @throws IllegalArgumentException
 *             if no concepts found
 * @return a ClassLoader with in jar included
 * @throws IOException 
 * @throws ObjectStoreConfigException 
 */
public ClassLoader createJar(File jar) throws IOException,
		ObjectStoreConfigException {
	File target = createTempDir(getClass().getSimpleName());
	compile(target);
	JarPacker packer = new JarPacker(target);
	packer.packageJar(jar);
	FileUtil.deleteDir(target);
	return new URLClassLoader(new URL[] { jar.toURI().toURL() }, cl);
}
 
Example #2
Source File: RepositoryProviderTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testFileURI() throws Exception {
	File dir = FileUtil.createTempDir(RepositoryProviderTest.class.getSimpleName());
	try {
		RepositoryManager byfile = RepositoryProvider.getRepositoryManager(dir);
		RepositoryManager byurl = RepositoryProvider.getRepositoryManager(dir.toURI().getRawPath());
		try {
			assertEquals(byfile, byurl);
		} finally {
			byfile.shutDown();
			byurl.shutDown();
		}
	} finally {
		FileUtil.deleteDir(dir);
	}
}
 
Example #3
Source File: SPARQL11ManifestTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private static String getManifestFile(boolean officialWorkingGroupTests, boolean useRemote) {
	String manifestFile = null;
	if (useRemote) {
		manifestFile = "http://www.w3.org/2009/sparql/docs/tests/data-sparql11/manifest-all.ttl";
	}
	else {
		URL url = null;
		if (officialWorkingGroupTests) {
			url = SPARQL11ManifestTest.class.getResource("/testcases-sparql-1.1-w3c/manifest-all.ttl");
		}
		else {
			url = SPARQL11ManifestTest.class.getResource("/testcases-sparql-1.1/manifest-evaluation.ttl");
		}

		if ("jar".equals(url.getProtocol())) {
			// Extract manifest files to a temporary directory
			try {
				tmpDir = FileUtil.createTempDir("sparql11-test-evaluation");

				JarURLConnection con = (JarURLConnection)url.openConnection();
				JarFile jar = con.getJarFile();

				ZipUtil.extract(jar, tmpDir);

				File localFile = new File(tmpDir, con.getEntryName());
				manifestFile = localFile.toURI().toURL().toString();
			}
			catch (IOException e) {
				throw new AssertionError(e);
			}
		}
		else {
			manifestFile = url.toString();
		}
	}
	return manifestFile;
}
 
Example #4
Source File: TripleIndexCreator.java    From AGDISTIS with GNU Affero General Public License v3.0 5 votes vote down vote up
public void createIndex(List<File> files, String idxDirectory, String baseURI) {
	try {
		urlAnalyzer = new SimpleAnalyzer(LUCENE_VERSION);
		literalAnalyzer = new LiteralAnalyzer(LUCENE_VERSION);
		Map<String, Analyzer> mapping = new HashMap<String, Analyzer>();
		mapping.put(TripleIndex.FIELD_NAME_SUBJECT, urlAnalyzer);
		mapping.put(TripleIndex.FIELD_NAME_PREDICATE, urlAnalyzer);
		mapping.put(TripleIndex.FIELD_NAME_OBJECT_URI, urlAnalyzer);
		mapping.put(TripleIndex.FIELD_NAME_OBJECT_LITERAL, literalAnalyzer);
		PerFieldAnalyzerWrapper perFieldAnalyzer = new PerFieldAnalyzerWrapper(urlAnalyzer, mapping);

		File indexDirectory = new File(idxDirectory);
		indexDirectory.mkdir();
		directory = new MMapDirectory(indexDirectory);
		IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, perFieldAnalyzer);
		iwriter = new IndexWriter(directory, config);
		iwriter.commit();
		for (File file : files) {
			String type = FileUtil.getFileExtension(file.getName());
			if (type.equals(TTL))
				indexTTLFile(file, baseURI);
			if (type.equals(TSV))
				indexTSVFile(file);
			iwriter.commit();
		}
		iwriter.close();
		ireader = DirectoryReader.open(directory);
	} catch (Exception e) {
		log.error("Error while creating TripleIndex.", e);
	}
}
 
Example #5
Source File: TripleIndexCreatorContext.java    From AGDISTIS with GNU Affero General Public License v3.0 5 votes vote down vote up
public void createIndex(List<File> files, String idxDirectory, String baseURI) {
	try {
		urlAnalyzer = new SimpleAnalyzer(LUCENE_VERSION);
		literalAnalyzer = new LiteralAnalyzer(LUCENE_VERSION);
		Map<String, Analyzer> mapping = new HashMap<String, Analyzer>();
		mapping.put(FIELD_NAME_URI, urlAnalyzer);
		mapping.put(FIELD_NAME_SURFACE_FORM, literalAnalyzer);
		mapping.put(FIELD_NAME_URI_COUNT, literalAnalyzer);
		mapping.put(FIELD_NAME_CONTEXT, literalAnalyzer);
		PerFieldAnalyzerWrapper perFieldAnalyzer = new PerFieldAnalyzerWrapper(urlAnalyzer, mapping);

		File indexDirectory = new File(idxDirectory);
		indexDirectory.mkdir();
		directory = new MMapDirectory(indexDirectory);
		IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, perFieldAnalyzer);
		iwriter = new IndexWriter(directory, config);
		iwriter.commit();
		for (File file : files) {
			String type = FileUtil.getFileExtension(file.getName());
			if (type.equals(TTL))
				indexTTLFile(file, baseURI);
			iwriter.commit();
		}
	} catch (Exception e) {
		log.error("Error while creating TripleIndex.", e);
	}
}
 
Example #6
Source File: TripleIndexCreatorContext.java    From AGDISTIS with GNU Affero General Public License v3.0 5 votes vote down vote up
public void updateIndex(List<File> files, String baseURI, String endpoint) {
	log.info("UpdateIndexBegin");
	try {
		for (File file : files) {
			String type = FileUtil.getFileExtension(file.getName());
			if (type.equals(TTL))
				indexTTLFile(file, baseURI);
			iwriter.commit();
		}
	} catch (Exception e) {
		log.error("Error while creating TripleIndex.", e);
	}

}
 
Example #7
Source File: ClassTemplateTest.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void setUp() throws Exception {
	super.setUp();
	dir = FileUtil.createTempDir("alibaba");
}
 
Example #8
Source File: ClassTemplateTest.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public void tearDown() throws Exception {
	System.gc();
	FileUtil.deleteDir(dir);
	super.tearDown();
}
 
Example #9
Source File: CodeGenTestCase.java    From anno4j with Apache License 2.0 4 votes vote down vote up
@Override
public void tearDown() throws Exception {
	FileUtil.deltree(targetDir.getParentFile());
	imports.clear();
}