net.roboconf.core.utils.Utils.computeFileRelativeLocation()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(134)

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

Utils.computeFileRelativeLocation介绍

[英]Computes the relative location of a file with respect to a root directory.
[中]计算文件相对于根目录的相对位置。

代码示例

代码示例来源:origin: roboconf/roboconf-platform

continue;
String path = Utils.computeFileRelativeLocation( searchDirectory, f );
result.add( path );

代码示例来源:origin: roboconf/roboconf-platform

/**
 * Stores the resources from a directory into a map.
 * @param directory an existing directory
 * @param exclusionPatteners a non-null list of exclusion patterns for file names (e.g. ".*\\.properties")
 * @return a non-null map (key = the file location, relative to the directory, value = file content)
 * @throws IOException if something went wrong while reading a file
 */
public static Map<String,byte[]> storeDirectoryResourcesAsBytes( File directory, List<String> exclusionPatteners )
throws IOException {
  if( ! directory.exists())
    throw new IllegalArgumentException( "The resource directory was not found. " + directory.getAbsolutePath());
  if( ! directory.isDirectory())
    throw new IllegalArgumentException( "The resource directory is not a valid directory. " + directory.getAbsolutePath());
  Map<String,byte[]> result = new HashMap<> ();
  List<File> resourceFiles = listAllFiles( directory, false );
  fileLoop: for( File file : resourceFiles ) {
    for( String exclusionPattern : exclusionPatteners ) {
      if( file.getName().matches( exclusionPattern ))
        continue fileLoop;
    }
    String key = computeFileRelativeLocation( directory, file );
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Utils.copyStream( file, os );
    result.put( key, os.toByteArray());
  }
  return result;
}

代码示例来源:origin: roboconf/roboconf-platform

@Test( expected = IllegalArgumentException.class )
public void testComputeFileRelativeLocation_failure_sameFile() {
  final File rootDir = new File( System.getProperty( "java.io.tmpdir" ));
  Utils.computeFileRelativeLocation( rootDir, rootDir );
}

代码示例来源:origin: roboconf/roboconf-platform

@Test( expected = IllegalArgumentException.class )
public void testComputeFileRelativeLocation_failure_notASubFile() {
  final File rootDir = new File( System.getProperty( "java.io.tmpdir" ), "does-not-exist");
  Utils.computeFileRelativeLocation( rootDir, new File( "invalid-path" ));
}

代码示例来源:origin: roboconf/roboconf-platform

@Test
public void testComputeFileRelativeLocation_success() {
  final File rootDir = new File( System.getProperty( "java.io.tmpdir" ));
  File directChildFile = new File( rootDir, "woo.txt" );
  Assert.assertEquals(
      directChildFile.getName(),
      Utils.computeFileRelativeLocation( rootDir, directChildFile ));
  String indirectChildPath = "dir1/dir2/script.sh";
  File indirectChildFile = new File( rootDir, indirectChildPath );
  Assert.assertEquals(
      indirectChildPath,
      Utils.computeFileRelativeLocation( rootDir, indirectChildFile ));
}

代码示例来源:origin: roboconf/roboconf-platform

/**
 * Copies a directory.
 * <p>
 * This method copies the content of the source directory
 * into the a target directory. This latter is created if necessary.
 * </p>
 *
 * @param source the directory to copy
 * @param target the target directory
 * @throws IOException if a problem occurred during the copy
 */
public static void copyDirectory( File source, File target ) throws IOException {
  Utils.createDirectory( target );
  for( File sourceFile : listAllFiles( source, false )) {
    String path = computeFileRelativeLocation( source, sourceFile );
    File targetFile = new File( target, path );
    Utils.createDirectory( targetFile.getParentFile());
    copyStream( sourceFile, targetFile );
  }
}

代码示例来源:origin: net.roboconf/roboconf-dm

Utils.createDirectory( scriptsOutDir );
for( File inputFile : scriptFiles ) {
  String relativePath = Utils.computeFileRelativeLocation( scriptsInDir, inputFile );
  File outputFile = new File( scriptsOutDir, relativePath );
  Utils.createDirectory( outputFile.getParentFile());

相关文章