de.lmu.ifi.dbs.elki.utilities.io.FileUtil类的使用及代码示例

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

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

FileUtil介绍

[英]Various static helper methods to deal with files and file names.
[中]处理文件和文件名的各种静态助手方法。

代码示例

代码示例来源:origin: elki-project/elki

/**
 * Constructor.
 * 
 * @param filters Filters, can be null
 * @param parser the parser to provide a database
 * @param infile File to load the data from
 */
public FileBasedDatabaseConnection(List<ObjectFilter> filters, Parser parser, String infile) {
 super(() -> {
  try {
   return new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(infile)));
  }
  catch(IOException e) {
   throw new AbortException("Could not load input file: " + infile, e);
  }
 }, filters, parser);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-core-util

/**
 * Returns the lower case extension of the selected file.
 * 
 * If no file is selected, <code>null</code> is returned.
 * 
 * @param file File object
 * @return Returns the extension of the selected file in lower case or
 *         <code>null</code>
 */
public static String getFilenameExtension(File file) {
 return getFilenameExtension(file.getName());
}

代码示例来源:origin: elki-project/elki

if((f = locateFile(name2, basedir)) != null) {
 return f;
if((f = locateFile(name2, basedir)) != null) {
 return f;
if((f = locateFile(name2, basedir)) != null) {
 return f;
if((f = locateFile(name.substring(1, name.length() - 1), basedir)) != null) {
 return f;

代码示例来源:origin: elki-project/elki

/**
 * Constructor with a given file name.
 * 
 * @param filename Name of properties file.
 * @param name NAme for this style
 */
public PropertiesBasedStyleLibrary(String filename, String name) {
 this.properties = new Properties();
 this.name = name;
 InputStream stream = null;
 try {
  stream = FileUtil.openSystemFile(filename);
 } catch (FileNotFoundException e) {
  try {
   stream = FileUtil.openSystemFile(filename + DEFAULT_PROPERTIES_EXTENSION);
  } catch (FileNotFoundException e2) {
   try {
    stream = FileUtil.openSystemFile(DEFAULT_PROPERTIES_PATH + filename + DEFAULT_PROPERTIES_EXTENSION);
   } catch (FileNotFoundException e3) {
    throw new AbortException("Could not find style scheme file '" + filename + "' for scheme '" + name + "'!");
   }
  }
 }
 try {
  properties.load(stream);
 } catch (Exception e) {
  throw new AbortException("Error loading properties file " + filename + ".\n", e);
 }
}

代码示例来源:origin: elki-project/elki

@Test
 public void testExternalDistance() throws IOException {
  Database db = new ELKIBuilder<>(StaticArrayDatabase.class) //
    .with(AbstractDatabase.Parameterizer.DATABASE_CONNECTION_ID, DBIDRangeDatabaseConnection.class) //
    .with(DBIDRangeDatabaseConnection.Parameterizer.COUNT_ID, 4) //
    .build();
  db.initialize();

  FileBasedSparseDoubleDistanceFunction df = new FileBasedSparseDoubleDistanceFunction(//
    new AsciiDistanceParser(CSVReaderFormat.DEFAULT_FORMAT), null, Double.POSITIVE_INFINITY);
  // We need to read from a resource, instead of a file.
  df.loadCache(4, FileUtil.openSystemFile(FILENAME));
  SLINK<DBID> slink = new SLINK<>(df);
  CutDendrogramByHeight clus = new CutDendrogramByHeight(slink, 0.5, false);
  Clustering<DendrogramModel> c = clus.run(db);

  testClusterSizes(c, new int[] { 2, 2 });
 }
}

代码示例来源:origin: elki-project/elki

/**
 * Constructor.
 * 
 * @param filters Filters, can be null
 * @param parser the parser to provide a database
 * @param infile File to load the data from
 */
public FileBasedDatabaseConnection(List<ObjectFilter> filters, Parser parser, File infile) {
 super(() -> {
  try {
   return new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(infile)));
  }
  catch(IOException e) {
   throw new AbortException("Could not load input file: " + infile, e);
  }
 }, filters, parser);
}

代码示例来源:origin: elki-project/elki

/**
 * Returns the lower case extension of the selected file.
 * 
 * If no file is selected, <code>null</code> is returned.
 * 
 * @param file File object
 * @return Returns the extension of the selected file in lower case or
 *         <code>null</code>
 */
public static String getFilenameExtension(File file) {
 return getFilenameExtension(file.getName());
}

代码示例来源:origin: elki-project/elki

@Test
 public void testExternalDistance() throws IOException {
  Database db = new ELKIBuilder<>(StaticArrayDatabase.class) //
    .with(AbstractDatabase.Parameterizer.DATABASE_CONNECTION_ID, DBIDRangeDatabaseConnection.class) //
    .with(DBIDRangeDatabaseConnection.Parameterizer.COUNT_ID, 4) //
    .build();
  db.initialize();

  FileBasedSparseFloatDistanceFunction df = new FileBasedSparseFloatDistanceFunction(//
    new AsciiDistanceParser(CSVReaderFormat.DEFAULT_FORMAT), null, Float.POSITIVE_INFINITY);
  // We need to read from a resource, instead of a file.
  df.loadCache(4, FileUtil.openSystemFile(FILENAME));
  SLINK<DBID> slink = new SLINK<>(df);
  CutDendrogramByHeight clus = new CutDendrogramByHeight(slink, 0.5, false);
  Clustering<DendrogramModel> c = clus.run(db);

  testClusterSizes(c, new int[] { 2, 2 });
 }
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-core-util

if((f = locateFile(name2, basedir)) != null) {
 return f;
if((f = locateFile(name2, basedir)) != null) {
 return f;
if((f = locateFile(name2, basedir)) != null) {
 return f;
if((f = locateFile(name.substring(1, name.length() - 1), basedir)) != null) {
 return f;

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-input

/**
 * Constructor.
 * 
 * @param filters Filters, can be null
 * @param parser the parser to provide a database
 * @param infile File to load the data from
 */
public FileBasedDatabaseConnection(List<ObjectFilter> filters, Parser parser, String infile) {
 super(() -> {
  try {
   return new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(infile)));
  }
  catch(IOException e) {
   throw new AbortException("Could not load input file: " + infile, e);
  }
 }, filters, parser);
}

代码示例来源:origin: elki-project/elki

/**
 * Guess a supported format from the file name. For "auto" format handling.
 *
 * @param name File name
 * @return format or "null"
 */
public static String guessFormat(String name) {
 String ext = FileUtil.getFilenameExtension(name);
 for(String format : FORMATS) {
  if(format.equals(ext)) {
   return ext;
  }
 }
 return null;
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-input

/**
 * Constructor.
 * 
 * @param filters Filters, can be null
 * @param parser the parser to provide a database
 * @param infile File to load the data from
 */
public FileBasedDatabaseConnection(List<ObjectFilter> filters, Parser parser, File infile) {
 super(() -> {
  try {
   return new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(infile)));
  }
  catch(IOException e) {
   throw new AbortException("Could not load input file: " + infile, e);
  }
 }, filters, parser);
}

代码示例来源:origin: elki-project/elki

private StreamFactory openStreamFactory() throws IOException {
 if(out == null) {
  return new SingleStreamOutput(gzip);
 }
 // If it does not exist, make a folder.
 final String ext = FileUtil.getFilenameExtension(out);
 if(!(out.exists() || "gz".equals(ext) || "csv".equals(ext) || "ascii".equals(ext) || "txt".equals(ext))) {
  LOG.info("Creating output directory: " + out);
  out.mkdirs();
 }
 if(out.isDirectory()) {
  if(warnoverwrite && out.listFiles().length > 0) {
   LOG.warning("Output directory specified is not empty. Files will be overwritten and old files may be left over.");
  }
  return new MultipleFilesOutput(out, gzip);
 }
 else {
  if(warnoverwrite && out.exists() && out.length() > 0) {
   LOG.warning("Output file exists and will be overwritten!");
  }
  return new SingleStreamOutput(out, gzip);
 }
}

代码示例来源:origin: elki-project/elki

@Override
public <O extends DBID> DistanceQuery<O> instantiate(Relation<O> relation) {
 if(cache == null) {
  try {
   loadCache(relation.size(), new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(matrixfile))));
  }
  catch(IOException e) {
   throw new AbortException("Could not load external distance file: " + matrixfile.toString(), e);
  }
 }
 return super.instantiate(relation);
}

代码示例来源:origin: elki-project/elki

String extension = FileUtil.getFilenameExtension(file);
if("svg".equals(extension)) {
 saveAsSVG(file);

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-precomputed

@Override
public <O extends DBID> DistanceQuery<O> instantiate(Relation<O> relation) {
 if(cache == null) {
  try {
   loadCache(relation.size(), new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(matrixfile))));
  }
  catch(IOException e) {
   throw new AbortException("Could not load external distance file: " + matrixfile.toString(), e);
  }
 }
 return super.instantiate(relation);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-precomputed

@Override
public <O extends DBID> DistanceQuery<O> instantiate(Relation<O> relation) {
 if(cache == null) {
  int size = relation.size();
  try {
   loadCache(size, new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(matrixfile))));
  }
  catch(IOException e) {
   throw new AbortException("Could not load external distance file: " + matrixfile.toString(), e);
  }
 }
 return super.instantiate(relation);
}

代码示例来源:origin: elki-project/elki

@Override
public <O extends DBID> DistanceQuery<O> instantiate(Relation<O> relation) {
 if(cache == null) {
  int size = relation.size();
  try {
   loadCache(size, new BufferedInputStream(FileUtil.tryGzipInput(new FileInputStream(matrixfile))));
  }
  catch(IOException e) {
   throw new AbortException("Could not load external distance file: " + matrixfile.toString(), e);
  }
 }
 return super.instantiate(relation);
}

代码示例来源:origin: elki-project/elki

@Override
public void run() {
 try (FileInputStream fis = new FileInputStream(infile); //
   InputStream is = new BufferedInputStream(FileUtil.tryGzipInput(fis)); //
   FileOutputStream fosResult = new FileOutputStream(outfile, true);
   PrintStream fout = new PrintStream(fosResult);

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-outlier

InputStream in = FileUtil.tryGzipInput(fis);
 BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
for(String line; (line = br.readLine()) != null;) {

相关文章