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

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

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

Utils.storeDirectoryResourcesAsBytes介绍

[英]Stores the resources from a directory into a map.
[中]将目录中的资源存储到地图中。

代码示例

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

/**
 * Stores the resources from a directory into a map.
 * @param directory an existing directory
 * @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 ) throws IOException {
  return storeDirectoryResourcesAsBytes( directory, new ArrayList<String>( 0 ));
}

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

/**
 * Stores the resources from a directory into a map.
 * @param directory an existing directory
 * @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,String> storeDirectoryResourcesAsString( File directory ) throws IOException {
  Map<String,byte[]> map = storeDirectoryResourcesAsBytes( directory );
  Map<String,String> result = new HashMap<>( map.size());
  for( Map.Entry<String,byte[]> entry : map.entrySet())
    result.put( entry.getKey(), new String( entry.getValue(), StandardCharsets.UTF_8 ));
  return result;
}

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

@Override
public Map<String,byte[]> findScriptResourcesForAgent( String targetId ) throws IOException {
  Map<String,byte[]> result = new HashMap<>( 0 );
  File targetDir = new File( findTargetDirectory( targetId ), Constants.PROJECT_SUB_DIR_SCRIPTS );
  if( targetDir.isDirectory()){
    List<String> exclusionPatterns = Arrays.asList(
      "(?i).*" + Pattern.quote( Constants.LOCAL_RESOURCE_PREFIX ) + ".*"
    );
    result.putAll( Utils.storeDirectoryResourcesAsBytes( targetDir, exclusionPatterns ));
  }
  return result;
}

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

/**
 * Stores the instance resources into a map.
 * @param applicationFilesDirectory the application's directory
 * @param instance an instance (not null)
 * @return a non-null map (key = the file location, relative to the instance's directory, value = file content)
 * @throws IOException if something went wrong while reading a file
 */
public static Map<String,byte[]> storeInstanceResources( File applicationFilesDirectory, Instance instance ) throws IOException {
  // Recipes
  Map<String,byte[]> result = new HashMap<> ();
  File instanceResourcesDirectory = findInstanceResourcesDirectory( applicationFilesDirectory, instance );
  if( instanceResourcesDirectory.exists()
      && instanceResourcesDirectory.isDirectory())
    result.putAll( Utils.storeDirectoryResourcesAsBytes( instanceResourcesDirectory ));
  // Probe files
  result.putAll( storeInstanceProbeResources( applicationFilesDirectory, instance ));
  return result;
}

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

@Test( expected = IllegalArgumentException.class )
public void testStoreDirectoryResourcesAsBytes_illegalArgument_1() throws Exception {
  Utils.storeDirectoryResourcesAsBytes( new File( "not/existing/file" ));
}

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

@Test( expected = IllegalArgumentException.class )
public void testStoreDirectoryResourcesAsBytes_illegalArgument_2() throws Exception {
  Utils.storeDirectoryResourcesAsBytes( this.folder.newFile( "roboconf.txt" ));
}

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

@Test
public void testStoreDirectoryResourcesAsBytes_withExclusionPatterns() throws Exception {
  File dir = this.folder.newFolder();
  Assert.assertTrue( new File( dir, "dir1/dir2" ).mkdirs());
  Assert.assertTrue( new File( dir, "dir1/dir2/t1.txt" ).createNewFile());
  Assert.assertTrue( new File( dir, "dir1/dir2/t2.toto" ).createNewFile());
  Assert.assertTrue( new File( dir, "t3.txt" ).createNewFile());
  Map<String,byte[]> map = Utils.storeDirectoryResourcesAsBytes( dir );
  Assert.assertEquals( 3, map.size());
  Assert.assertTrue( map.containsKey( "dir1/dir2/t1.txt" ));
  Assert.assertTrue( map.containsKey( "dir1/dir2/t2.toto" ));
  Assert.assertTrue( map.containsKey( "t3.txt" ));
  map = Utils.storeDirectoryResourcesAsBytes( dir, Arrays.asList( ".*\\.txt" ));
  Assert.assertEquals( 1, map.size());
  Assert.assertTrue( map.containsKey( "dir1/dir2/t2.toto" ));
  map = Utils.storeDirectoryResourcesAsBytes( dir, Arrays.asList( ".*toto.*" ));
  Assert.assertEquals( 2, map.size());
  Assert.assertTrue( map.containsKey( "dir1/dir2/t1.txt" ));
  Assert.assertTrue( map.containsKey( "t3.txt" ));
  map = Utils.storeDirectoryResourcesAsBytes( dir, Arrays.asList( "dir1" ));
  Assert.assertEquals( 3, map.size());
  Assert.assertTrue( map.containsKey( "dir1/dir2/t1.txt" ));
  Assert.assertTrue( map.containsKey( "dir1/dir2/t2.toto" ));
  Assert.assertTrue( map.containsKey( "t3.txt" ));
}

相关文章