org.scijava.util.FileUtils.readFile()方法的使用及代码示例

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

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

FileUtils.readFile介绍

[英]Reads the contents of the given file into a new byte array.
[中]将给定文件的内容读入新的字节数组。

代码示例

代码示例来源:origin: scijava/scijava-common

@Override
public String loadChecksum(final Location source) throws IOException {
  final File cachedChecksum = cachedChecksum(source);
  if (!cachedChecksum.exists()) return null;
  return DigestUtils.string(FileUtils.readFile(cachedChecksum));
}

代码示例来源:origin: org.scijava/scijava-common

@Override
public String loadChecksum(final Location source) throws IOException {
  final File cachedChecksum = cachedChecksum(source);
  if (!cachedChecksum.exists()) return null;
  return DigestUtils.string(FileUtils.readFile(cachedChecksum));
}

代码示例来源:origin: org.scijava/scijava-common

@Override
public String getVersion() {
  final File file = new File(path);
  if (!file.exists()) return null; // no version for non-existent script
  try {
    return DigestUtils.bestHex(FileUtils.readFile(file));
  }
  catch (final IOException exc) {
    log.error(exc);
  }
  final Date lastModified = FileUtils.getModifiedTime(file);
  final String datestamp =
    new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(lastModified);
  return datestamp;
}

代码示例来源:origin: scijava/scijava-common

@Override
public String getVersion() {
  final File file = new File(path);
  if (!file.exists()) return null; // no version for non-existent script
  try {
    return DigestUtils.bestHex(FileUtils.readFile(file));
  }
  catch (final IOException exc) {
    log.error(exc);
  }
  final Date lastModified = FileUtils.getModifiedTime(file);
  final String datestamp =
    new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(lastModified);
  return datestamp;
}

代码示例来源:origin: io.scif/scifio

private void parsePosition(final Metadata meta, final int posIndex)
  throws IOException, FormatException
{
  final Position p = meta.getPositions().get(posIndex);
  final byte[] bytes = FileUtils.readFile(new File(p.metadataFile));
  final String s = DigestUtils.string(bytes);
  parsePosition(s, meta, posIndex);
  buildTIFFList(meta, posIndex);
}

代码示例来源:origin: scifio/scifio

private void parsePosition(final Metadata meta, final int posIndex)
  throws IOException, FormatException
{
  final Position p = meta.getPositions().get(posIndex);
  final byte[] bytes = FileUtils.readFile(new File(p.metadataFile));
  final String s = DigestUtils.string(bytes);
  parsePosition(s, meta, posIndex);
  buildTIFFList(meta, posIndex);
}

代码示例来源:origin: io.scif/scifio

/** Parse metadata values from the Acqusition.xml file. */
private void parseXMLFile(final Metadata meta, final int imageIndex)
  throws IOException
{
  final Position p = meta.getPositions().get(imageIndex);
  final byte[] bytes = FileUtils.readFile(new File(p.xmlFile));
  String xmlData = DigestUtils.string(bytes);
  xmlData = xmlService.sanitizeXML(xmlData);
  final DefaultHandler handler = new MicromanagerHandler();
  xmlService.parseXML(xmlData, handler);
}

代码示例来源:origin: scifio/scifio

/** Parse metadata values from the Acqusition.xml file. */
private void parseXMLFile(final Metadata meta, final int imageIndex)
  throws IOException
{
  final Position p = meta.getPositions().get(imageIndex);
  final byte[] bytes = FileUtils.readFile(new File(p.xmlFile));
  String xmlData = DigestUtils.string(bytes);
  xmlData = xmlService.sanitizeXML(xmlData);
  final DefaultHandler handler = new MicromanagerHandler();
  xmlService.parseXML(xmlData, handler);
}

代码示例来源:origin: scijava/scijava-common

@Test
public void testDownload() throws IOException, InterruptedException,
  ExecutionException
{
  final byte[] data = randomBytes(0xbabebabe);
  final String prefix = getClass().getName();
  final File inFile = File.createTempFile(prefix, "testDownloadIn");
  final File outFile = File.createTempFile(prefix, "testDownloadOut");
  try {
    FileUtils.writeFile(inFile, data);
    final Location src = new FileLocation(inFile);
    final Location dest = new FileLocation(outFile);
    final Download download = downloadService.download(src, dest);
    download.task().waitFor();
    final byte[] result = FileUtils.readFile(outFile);
    assertArrayEquals(data, result);
  }
  finally {
    inFile.delete();
    outFile.delete();
  }
}

代码示例来源:origin: imagej/imagej-ops

@Test
public void testReadmesExample() throws Exception {
  // extract the example script
  final File readme = new File("README.md");
  final String contents = new String(FileUtils.readFile(readme), "UTF-8");
  final String telltale = String.format("```python%n");
  final int begin = contents.indexOf(telltale) + telltale.length();
  assertTrue(begin > telltale.length());
  assertTrue(contents.indexOf(telltale, begin) < 0);
  final int end = contents.indexOf(String.format("```%n"), begin);
  assertTrue(end > 0);
  final String snippet = contents.substring(begin, end);
  assertTrue(snippet.startsWith("# @ImageJ ij"));
  final Context context = new Context();
  final ScriptService script = context.getService(ScriptService.class);
  // create mock ImageJ gateway
  script.addAlias("ImageJ", Mock.class);
  final ScriptModule module =
    script.run("op-example.py", snippet, true).get();
  assertNotNull(module);
  module.run();
  final Mock ij = context.getService(Mock.class);
  assertEquals(3, ij.images.size());
  assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3);
  assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3);
  assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3);
}

代码示例来源:origin: scijava/scijava-common

final byte[] cachedData = FileUtils.readFile(cachedFile.getFile());
assertArrayEquals(data, cachedData);

相关文章