public String getItem(int i, boolean withIndirect) { if ( i < 0 || i >= items.size() ) return null ; String item = items.get(i) ; if ( withIndirect && item.startsWith(indirectionMarker) ) { item = item.substring(1) ; try { item = FileUtils.readWholeFileAsUTF8(item) ; } catch (Exception ex) { throw new IllegalArgumentException("Failed to read '"+item+"': "+ex.getMessage()) ; } } return item ; }
public String getItem(int i, boolean withIndirect) { if ( i < 0 || i >= items.size() ) return null ; String item = items.get(i) ; if ( withIndirect && item.startsWith(indirectionMarker) ) { item = item.substring(1) ; try { item = FileUtils.readWholeFileAsUTF8(item) ; } catch (Exception ex) { throw new IllegalArgumentException("Failed to read '"+item+"': "+ex.getMessage()) ; } } return item ; }
private String oneFile(String filename) { divider() ; try { return FileUtils.readWholeFileAsUTF8(filename) ; } catch (IOException ex) { System.err.println("No such file: "+filename) ; return null ; } }
private String oneFile(String filename) { divider() ; try { return FileUtils.readWholeFileAsUTF8(filename) ; } catch (IOException ex) { System.err.println("No such file: "+filename) ; return null ; } }
/** Read a template file, substitute for {NAME} and return the model. */ public static String templateResource(String resourceName, Map<String, String> params, Lang lang) { String template ; try { InputStream in = TemplateFunctions.class.getClassLoader().getResourceAsStream(resourceName) ; if ( in == null ) Fuseki.serverLog.error("Resource not found: "+resourceName); template = FileUtils.readWholeFileAsUTF8(in) ; } catch (IOException ex) { Fuseki.serverLog.error("Error reading resource: "+resourceName); IO.exception(ex); return null ; } return templateString(template, params, lang) ; }
/** Read a template file, substitute for {NAME} and return the model. */ public static String templateResource(String resourceName, Map<String, String> params, Lang lang) { String template ; try { InputStream in = TemplateFunctions.class.getClassLoader().getResourceAsStream(resourceName) ; if ( in == null ) Fuseki.serverLog.error("Resource not found: "+resourceName); template = FileUtils.readWholeFileAsUTF8(in) ; } catch (IOException ex) { Fuseki.serverLog.error("Error reading resource: "+resourceName); IO.exception(ex); return null ; } return templateString(template, params, lang) ; }
/** Read in a template from a file, substitute for {NAME} and return the string. */ public static String templateFile(String templateName, Map<String, String> params, Lang lang) { String templateFilename = Template.getPath(templateName).toString() ; String template ; try { template = FileUtils.readWholeFileAsUTF8(templateFilename) ; } catch (IOException ex) { Fuseki.serverLog.error("File not found: "+templateFilename); IO.exception(ex); return null ; } return templateString(template, params, lang) ; }
/** Read in a template from a file, substitute for {NAME} and return the string. */ public static String templateFile(String templateName, Map<String, String> params, Lang lang) { String templateFilename = Template.getPath(templateName).toString() ; String template ; try { template = FileUtils.readWholeFileAsUTF8(templateFilename) ; } catch (IOException ex) { Fuseki.serverLog.error("File not found: "+templateFilename); IO.exception(ex); return null ; } return templateString(template, params, lang) ; }
/** This test relies on forking a clean JVM */ public void testInitFromRDFS() throws IOException, InterruptedException { String separator = System.getProperty("file.separator"); String classpath = System.getProperty("java.class.path"); String java = System.getProperty("java.home") + separator + "bin" + separator + "java"; if (SystemUtils.IS_OS_WINDOWS) java += ".exe"; List<String> args = Arrays.asList(java, "-cp", classpath, "org.apache.jena.test.RDFSJenaInitTestApp"); Process child = new ProcessBuilder().command(args) .redirectError(ProcessBuilder.Redirect.INHERIT) .redirectOutput(ProcessBuilder.Redirect.PIPE) .start(); Assert.assertEquals(0, child.waitFor()); Assert.assertEquals(RDFS.subClassOf.toString()+"\n", FileUtils.readWholeFileAsUTF8(child.getInputStream())); } }
/** This test relies on forking a clean JVM */ public void testInitFromRDFS() throws IOException, InterruptedException { String separator = System.getProperty("file.separator"); String classpath = System.getProperty("java.class.path"); String java = System.getProperty("java.home") + separator + "bin" + separator + "java"; if (SystemUtils.IS_OS_WINDOWS) java += ".exe"; List<String> args = Arrays.asList(java, "-cp", classpath, "org.apache.jena.test.RDFSJenaInitTestApp"); Process child = new ProcessBuilder().command(args) .redirectError(ProcessBuilder.Redirect.INHERIT) .redirectOutput(ProcessBuilder.Redirect.PIPE) .start(); Assert.assertEquals(0, child.waitFor()); Assert.assertEquals(RDFS.subClassOf.toString()+"\n", FileUtils.readWholeFileAsUTF8(child.getInputStream())); } }
private static void jenaread_stream(String filename, String lang) throws IOException { filename = filename(filename); // Read with a base try (FileInputStream in0 = new FileInputStream(filename)) { Model m0 = ModelFactory.createDefaultModel(); RDFDataMgr.read(m0, in0, "http://example/base2", RDFLanguages.nameToLang(lang)); } // Read again, but without base try (FileInputStream in1 = new FileInputStream(filename)) { Model m1 = ModelFactory.createDefaultModel(); RDFDataMgr.read(m1, in1, RDFLanguages.nameToLang(lang)); } // Read via Jena API. Model m2 = ModelFactory.createDefaultModel(); try (FileInputStream in2 = new FileInputStream(filename)) { m2.read(in2, "http://example/base3", lang); } String x = FileUtils.readWholeFileAsUTF8(filename); Model m3 = ModelFactory.createDefaultModel(); m2.read(new StringReader(x), "http://example/base4", lang); }
@Test public void transBlobFile_1() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello" ; TestTransBlob.write(transactional, transBlob, str) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals(str, s); }
String s2 = FileUtils.readWholeFileAsUTF8(stream); System.out.print(s2); if ( s2 == null )
@Test public void transBlobFile_1() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello" ; TestTransBlob.write(transactional, transBlob, str) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals(str, s); }
@Test public void transBlobFile_1() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello" ; TestTransBlob.write(transactional, transBlob, str) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals(str, s); }
String s2 = FileUtils.readWholeFileAsUTF8(stream); System.out.print(s2); if ( s2 == null )
@Test public void fs_write_01() throws IOException { FileStore fs = FileStore.attach(STORE, "FILE"); assertEquals(0, fs.getCurrentIndex()); FileEntry entry = fs.writeNewFile(out->{ try(AWriter aw = IO .wrapUTF8(out)) { aw.write("abc"); } }) ; assertNotNull(entry); assertNotNull(entry.datafile); int idx = checkFilename(entry.datafile); assertEquals(1, idx); // Read it back in again. String s = FileUtils.readWholeFileAsUTF8(entry.getDatafileName()); assertEquals("abc", s); }
@Test public void transBlobFile_2() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello1" ; Txn.executeWrite(transactional, ()->{ transBlob.setString("one"); }) ; Txn.executeWrite(transactional, ()->{ transBlob.setString("two"); }) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals("two", s); }
@Test public void transBlobFile_2() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello1" ; Txn.executeWrite(transactional, ()->{ transBlob.setString("one"); }) ; Txn.executeWrite(transactional, ()->{ transBlob.setString("two"); }) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals("two", s); }
@Test public void transBlobFile_2() throws Exception { Journal journal = Journal.create(Location.create(DIR)) ; BufferChannel chan = BufferChannelFile.create(DATA) ; ComponentId cid = ComponentId.allocLocal() ; TransBlob transBlob = new TransBlob(cid, chan) ; Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ; String str = "Hello1" ; Txn.executeWrite(transactional, ()->{ transBlob.setString("one"); }) ; Txn.executeWrite(transactional, ()->{ transBlob.setString("two"); }) ; chan.close() ; journal.close() ; String s = FileUtils.readWholeFileAsUTF8(DATA) ; assertEquals("two", s); }