/** * Reads in the registered SPARQL endpoints from the configuration file /endpoints.txt. Each line * of this file must contain the URL of a SPARQL endpoint. */ public EndpointManagement() { try { this.urlsOfEndpoints = FileHelper.readInputStreamToCollection( FileHelper.getInputStreamFromJarOrFile("/endpoints.config")) .toArray(new String[0]); for (int i = 0; i < this.urlsOfEndpoints.length; i++) { if (!this.urlsOfEndpoints[i].endsWith("/")) { // this is necessary when using distribution strategies as different contexts must be // addressed for different key types this.urlsOfEndpoints[i] += "/"; } } } catch (final FileNotFoundException e) { System.err.println(e); e.printStackTrace(); this.urlsOfEndpoints = new String[0]; } }
public static void readTriples(String type, final InputStream input, final TripleConsumer tc) throws Exception { type = type.toUpperCase(); if (type.startsWith("MULTIPLE")) { final String typeWithoutMultiple = type.substring("MULTIPLE".length()); if (MULTIPLEDATATHREADS == 1) { final BoundedBuffer<Triple> bbTriples = new BoundedBuffer<Triple>(MAX_TRIPLES_IN_BUFFER); final Thread thread = new Thread() { @Override public void run() { for (final String filename : FileHelper.readInputStreamToCollection(input)) { System.out.println("Reading data from file: " + filename); try { String type2; if (typeWithoutMultiple.compareTo("DETECT") == 0) { final int index = filename.lastIndexOf('.'); if (index == -1) { System.err.println( "Type of " + filename + " could not be automatically detected!"); } type2 = filename.substring(index + 1).toUpperCase(); } else { type2 = typeWithoutMultiple; } readTriplesWithoutMultipleFiles( type2, new FileInputStream(filename), new TripleConsumer() { @Override public void consume(final Triple triple) { try { bbTriples.put(triple); } catch (final InterruptedException e) { System.err.println(e); e.printStackTrace(); } } }); } catch (final Throwable e) { System.err.println(e); e.printStackTrace(); } } bbTriples.endOfData(); } }; thread.start(); Triple t; try { while ((t = bbTriples.get()) != null) { tc.consume(t); } } catch (final InterruptedException e) { System.err.println(e); e.printStackTrace(); } } else { final TripleConsumer synchronizedTC = new TripleConsumer() { @Override public synchronized void consume(final Triple triple) { tc.consume(triple); } }; final Collection<String> filenames = FileHelper.readInputStreamToCollection(input); final BoundedBuffer<String> filenamesBB = new BoundedBuffer<String>(filenames.size()); for (final String filename : filenames) { try { filenamesBB.put(filename); } catch (final InterruptedException e) { System.err.println(e); e.printStackTrace(); } } filenamesBB.endOfData(); final Thread[] threads = new Thread[MULTIPLEDATATHREADS]; for (int i = 0; i < MULTIPLEDATATHREADS; i++) { threads[i] = new Thread() { @Override public void run() { try { while (filenamesBB.hasNext()) { final String filename = filenamesBB.get(); if (filename == null) { break; } System.out.println("Reading data from file: " + filename); String type2; if (typeWithoutMultiple.compareTo("DETECT") == 0) { final int index = filename.lastIndexOf('.'); if (index == -1) { System.err.println( "Type of " + filename + " could not be automatically detected!"); } type2 = filename.substring(index + 1).toUpperCase(); } else { type2 = typeWithoutMultiple; } try { readTriplesWithoutMultipleFiles( type2, new FileInputStream(filename), synchronizedTC); } catch (final Throwable e) { System.err.println(e); e.printStackTrace(); } } } catch (final InterruptedException e) { System.err.println(e); e.printStackTrace(); } } }; threads[i].start(); } for (int i = 0; i < MULTIPLEDATATHREADS; i++) { try { threads[i].join(); } catch (final InterruptedException e) { System.err.println(e); e.printStackTrace(); } } } } else { readTriplesWithoutMultipleFiles(type, input, tc); } }