org.apache.jena.util.FileUtils.readWholeFileAsUTF8()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中org.apache.jena.util.FileUtils.readWholeFileAsUTF8()方法的一些代码示例,展示了FileUtils.readWholeFileAsUTF8()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.readWholeFileAsUTF8()方法的具体详情如下:
包路径:org.apache.jena.util.FileUtils
类名称:FileUtils
方法名:readWholeFileAsUTF8

FileUtils.readWholeFileAsUTF8介绍

[英]Read a whole stream as UTF-8
[中]将整个流读取为UTF-8

代码示例

代码示例来源:origin: apache/jena

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 ;
}

代码示例来源:origin: org.apache.jena/jena-cmds

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 ;
}

代码示例来源:origin: org.apache.jena/jena-cmds

private String oneFile(String filename)
{
  divider() ;
  try
  {
    return FileUtils.readWholeFileAsUTF8(filename) ;
  } catch (IOException ex)
  {
    System.err.println("No such file: "+filename) ;
    return null ;
  }
}

代码示例来源:origin: apache/jena

private String oneFile(String filename)
{
  divider() ;
  try
  {
    return FileUtils.readWholeFileAsUTF8(filename) ;
  } catch (IOException ex)
  {
    System.err.println("No such file: "+filename) ;
    return null ;
  }
}

代码示例来源:origin: apache/jena

/** 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) ;
}

代码示例来源:origin: org.apache.jena/jena-fuseki-webapp

/** 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) ;
}

代码示例来源:origin: apache/jena

/** 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) ;
}

代码示例来源:origin: org.apache.jena/jena-fuseki-webapp

/** 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) ;
}

代码示例来源:origin: apache/jena

/** 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()));
  }
}

代码示例来源:origin: org.apache.jena/jena-core

/** 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()));
  }
}

代码示例来源:origin: apache/jena

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);
}

代码示例来源:origin: apache/jena

@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); 
}

代码示例来源:origin: apache/jena

String s2 = FileUtils.readWholeFileAsUTF8(stream);
System.out.print(s2);
if ( s2 == null )

代码示例来源:origin: org.apache.jena/jena-dboe-trans-data

@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); 
}

代码示例来源:origin: org.seaborne.mantis/dboe-trans-data

@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); 
}

代码示例来源:origin: org.apache.jena/jena-fuseki-main

String s2 = FileUtils.readWholeFileAsUTF8(stream);
System.out.print(s2);
if ( s2 == null )

代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-server-local

@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);
}

代码示例来源:origin: apache/jena

@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); 
}

代码示例来源:origin: org.apache.jena/jena-dboe-trans-data

@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); 
}

代码示例来源:origin: org.seaborne.mantis/dboe-trans-data

@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); 
}

相关文章