org.apache.jena.util.FileUtils类的使用及代码示例

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

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

FileUtils介绍

暂无

代码示例

代码示例来源: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: apache/jena

/** Guess the language/type of model data
 * 
 * <ul>
 * <li> If the URI ends ".rdf", it is assumed to be RDF/XML</li>
 * <li> If the URI ends ".nt", it is assumed to be N-Triples</li>
 * <li> If the URI ends ".ttl", it is assumed to be Turtle</li>
 * <li> If the URI ends ".owl", it is assumed to be RDF/XML</li>
 * </ul>
 * @param urlStr    URL to base the guess on
 * @return String   Guessed syntax - default is RDF/XML
 */
public static String guessLang(String urlStr)
{
  return guessLang(urlStr, langXML) ;
}

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

/** Check whether a name is an absolute URI (has a scheme name)
 * 
 * @param name
 * @return boolean True if there is a scheme name 
 */
public static boolean isURI(String name)
{
  return (getScheme(name) != null) ;
}

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

/** Create a buffered reader that uses UTF-8 encoding */ 

static public BufferedReader asBufferedUTF8(InputStream in)
{
  BufferedReader r = new BufferedReader(asUTF8(in)) ;
  return r ;
}

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

@Override
final
public void read(Model model, InputStream in, String base) 
{
  readImpl(model, FileUtils.asBufferedUTF8(in), base) ;
}

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

public PlainFormat(OutputStream outStream, SerializationContext context)
{
  this.out = FileUtils.asPrintWriterUTF8(outStream) ;
  this.context = context ;
}

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

/** Guess the language/type of model data.
 * 
 * <ul>
 * <li> If the URI ends ".rdf", it is assumed to be RDF/XML</li>
 * <li> If the URI ends ".nt", it is assumed to be N-Triples</li>
 * <li> If the URI ends ".ttl", it is assumed to be Turtle</li>
 * <li> If the URI ends ".owl", it is assumed to be RDF/XML</li>
 * </ul>
 * @param name    URL to base the guess on
 * @param otherwise Default guess
 * @return String   Guessed syntax - or the default supplied
 */
public static String guessLang( String name, String otherwise )
{
  String suffix = getFilenameExt( name );
  if (suffix.equals( "n3" ))   return langN3;
  if (suffix.equals( "nt" ))   return langNTriple;
  if (suffix.equals( "ttl" ))  return langTurtle ;
  if (suffix.equals( "rdf" ))  return langXML;
  if (suffix.equals( "owl" ))  return langXML;
  return otherwise; 
}

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

/** Create a print writer that uses UTF-8 encoding */ 
static public PrintWriter asPrintWriterUTF8(OutputStream out) {
  return new PrintWriter(asUTF8(out)); 
}

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

@Override
final
public void read(Model model, InputStream in, String base) 
{
  readImpl(model, FileUtils.asBufferedUTF8(in), base) ;
}

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

@Override
  public void format(OutputStream out, boolean answer) {
    PrintWriter pw = FileUtils.asPrintWriterUTF8(out);
    if ( answer )
      pw.write("yes");
    else
      pw.write("no");
    pw.flush();
  }
}

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

/** Guess the language/type of model data.
 * 
 * <ul>
 * <li> If the URI ends ".rdf", it is assumed to be RDF/XML</li>
 * <li> If the URI ends ".nt", it is assumed to be N-Triples</li>
 * <li> If the URI ends ".ttl", it is assumed to be Turtle</li>
 * <li> If the URI ends ".owl", it is assumed to be RDF/XML</li>
 * </ul>
 * @param name    URL to base the guess on
 * @param otherwise Default guess
 * @return String   Guessed syntax - or the default supplied
 */
public static String guessLang( String name, String otherwise )
{
  String suffix = getFilenameExt( name );
  if (suffix.equals( "n3" ))   return langN3;
  if (suffix.equals( "nt" ))   return langNTriple;
  if (suffix.equals( "ttl" ))  return langTurtle ;
  if (suffix.equals( "rdf" ))  return langXML;
  if (suffix.equals( "owl" ))  return langXML;
  return otherwise; 
}

代码示例来源: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-core

/** Guess the language/type of model data
 * 
 * <ul>
 * <li> If the URI ends ".rdf", it is assumed to be RDF/XML</li>
 * <li> If the URI ends ".nt", it is assumed to be N-Triples</li>
 * <li> If the URI ends ".ttl", it is assumed to be Turtle</li>
 * <li> If the URI ends ".owl", it is assumed to be RDF/XML</li>
 * </ul>
 * @param urlStr    URL to base the guess on
 * @return String   Guessed syntax - default is RDF/XML
 */
public static String guessLang(String urlStr)
{
  return guessLang(urlStr, langXML) ;
}

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

/** Check whether a name is an absolute URI (has a scheme name)
 * 
 * @param name
 * @return boolean True if there is a scheme name 
 */
public static boolean isURI(String name)
{
  return (getScheme(name) != null) ;
}

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

/** Create a buffered reader that uses UTF-8 encoding */ 

static public BufferedReader asBufferedUTF8(InputStream in)
{
  BufferedReader r = new BufferedReader(asUTF8(in)) ;
  return r ;
}

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

public static BufferedReader readerFromURL( String urlStr ) 
{
  try { return asBufferedUTF8( new URL(urlStr).openStream() ); }    
  catch (java.net.MalformedURLException e) 
  { // Try as a plain filename.
    try { return asBufferedUTF8( new FileInputStream( urlStr ) ); }
    catch (FileNotFoundException f) { throw new WrappedIOException( f ); }
  }
  catch (IOException e)
  { throw new WrappedIOException( e ); }
}

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

/** Write out an RDF model that encodes the result set
 * 
 * @param outStream     Output
 * @param format        Name of RDF format (names as Jena writers) 
 * @param resultSet     The result set to encode in RDF
 */

static public void outputAsRDF(OutputStream outStream, String format, ResultSet resultSet)
{
  PrintWriter out = FileUtils.asPrintWriterUTF8(outStream) ;
  RDFOutput.outputAsRDF(out, format, resultSet) ;
  out.flush() ;
}

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

/** Try to map a URI or file name to a {@link Lang}; return null on no registered mapping. */
public static Lang filenameToLang(String filename)
{
  if ( filename == null )
    return null;
  // Remove any URI fragment (there can be only one # in a URI).
  // Pragmatically, assume any # is URI related.
  // URIs can be relative.
  int iHash = filename.indexOf('#');
  if ( iHash  > 0 )
    filename = filename.substring(0, iHash);
  // Gzip or BZip2 compressed?
  filename = IO.filenameNoCompression(filename);
  return fileExtToLang(FileUtils.getFilenameExt(filename));
}

代码示例来源: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

public void testGuessLangLowerCase() {
  assertEquals(FileUtils.langN3, FileUtils.guessLang("simple.n3"));
  assertEquals(FileUtils.langN3, FileUtils.guessLang("hello.there.n3"));
  assertEquals(FileUtils.langTurtle, FileUtils.guessLang("simple.ttl"));
  assertEquals(FileUtils.langTurtle, FileUtils
      .guessLang("hello.there.ttl"));
  assertEquals(FileUtils.langNTriple, FileUtils.guessLang("simple.nt"));
  assertEquals(FileUtils.langNTriple, FileUtils.guessLang("whats.up.nt"));
  assertEquals(FileUtils.langXML, FileUtils.guessLang("poggle.rdf"));
  assertEquals(FileUtils.langXML, FileUtils.guessLang("wise.owl"));
  assertEquals(FileUtils.langXML, FileUtils.guessLang("dotless"));
}

相关文章