本文整理了Java中org.mule.runtime.core.api.util.FileUtils.stringToFile()
方法的一些代码示例,展示了FileUtils.stringToFile()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.stringToFile()
方法的具体详情如下:
包路径:org.mule.runtime.core.api.util.FileUtils
类名称:FileUtils
方法名:stringToFile
[英]Reads the incoming String into a file at at the given destination.
[中]将传入字符串读入给定目标的文件中。
代码示例来源:origin: mulesoft/mule
private List<ExportedService> getServicesFromProperty(String privilegedExportedPackagesProperty) {
List<ExportedService> exportedServices = new ArrayList<>();
for (String exportedServiceDefinition : privilegedExportedPackagesProperty.split(",")) {
String[] split = exportedServiceDefinition.split(":");
String serviceInterface = split[0];
String serviceImplementation = split[1];
URL resource;
try {
File serviceFile = createTempFile(temporaryFolder.toPath(), serviceInterface, "tmp").toFile();
serviceFile.deleteOnExit();
stringToFile(serviceFile.getAbsolutePath(), serviceImplementation);
resource = serviceFile.toURI().toURL();
} catch (IOException e) {
throw new IllegalStateException(format("Error creating temporary service provider file for '%s'", serviceInterface), e);
}
exportedServices.add(new ExportedService(serviceInterface, resource));
}
return exportedServices;
}
代码示例来源:origin: mulesoft/mule
List<GeneratedResource> dumpAll() {
List<GeneratedResource> allResources =
contents.entrySet().stream().map(entry -> new GeneratedResource(entry.getKey(), entry.getValue().toString().getBytes()))
.collect(toImmutableList());
allResources.forEach(resource -> {
File targetFile = new File(resource.getPath());
try {
stringToFile(targetFile.getAbsolutePath(), new String(resource.getContent()));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return allResources;
}
}
代码示例来源:origin: mulesoft/mule
private void updateExpectedJson(String json) throws URISyntaxException, IOException {
File root = new File(getResourceAsUrl("models/" + expectedSource, getClass()).toURI()).getParentFile()
.getParentFile().getParentFile().getParentFile();
File testDir = new File(root, "src/test/resources/models");
File target = new File(testDir, expectedSource);
stringToFile(target.getAbsolutePath(), json);
System.out.println(expectedSource + " fixed");
}
代码示例来源:origin: mulesoft/mule
private void updateExpectedJson(String json) throws URISyntaxException, IOException {
File root = new File(getResourceAsUrl(expectedSource, getClass()).toURI()).getParentFile()
.getParentFile().getParentFile().getParentFile().getParentFile();
File testDir = new File(root, "src/test/resources/");
File target = new File(testDir, expectedSource);
stringToFile(target.getAbsolutePath(), json);
System.out.println(target.getAbsolutePath() + " was fixed");
}
代码示例来源:origin: mulesoft/mule
@Test
public void createsClassLoaderModelFromFolder() throws Exception {
File policyFolder = temporaryFolder.newFolder();
File libFolder = new File(policyFolder, LIB_DIR);
assertThat(libFolder.mkdir(), is(true));
File file1 = new File(libFolder, "test1.jar");
stringToFile(file1.getAbsolutePath(), "foo");
File file2 = new File(libFolder, "test2.jar");
stringToFile(file2.getAbsolutePath(), "foo");
ClassLoaderModel classLoaderModel = classLoaderModelLoader.load(policyFolder, null, POLICY);
assertThat(classLoaderModel.getUrls().length, equalTo(3));
assertThat(classLoaderModel.getUrls()[0], equalTo(policyFolder.toURI().toURL()));
assertThat(asList(classLoaderModel.getUrls()), allOf(hasItem(file1.toURI().toURL()), hasItem(file2.toURI().toURL())));
assertThat(classLoaderModel.getDependencies(), is(empty()));
assertThat(classLoaderModel.getExportedPackages(), is(empty()));
assertThat(classLoaderModel.getExportedResources(), is(empty()));
}
}
代码示例来源:origin: mulesoft/mule
@Test
public void generate() throws Exception {
String schema = generator.generate(extensionUnderTest, new SchemaTestDslContext());
try {
compareXML(expectedSchema, schema);
} catch (Throwable t) {
if (shouldUpdateExpectedFilesOnError()) {
File root = new File(getResourceAsUrl("schemas/" + expectedXSD, getClass()).toURI()).getParentFile()
.getParentFile().getParentFile().getParentFile();
File testDir = new File(root, "src/test/resources/schemas");
File target = new File(testDir, expectedXSD);
stringToFile(target.getAbsolutePath(), schema);
System.out.println(expectedXSD + " fixed");
}
throw t;
}
}
代码示例来源:origin: mulesoft/mule
@Before
public void createAppClassLoader() throws IOException {
// Creates folder structure
previousMuleHome = setProperty(MULE_HOME_DIRECTORY_PROPERTY, tempMuleHome.getRoot().getAbsolutePath());
// Add jar file on application's lib folder
File libDir = getAppLibFolder(APP_NAME);
assertThat(libDir.mkdirs(), is(true));
final File appLibrary = new File(libDir, "appLibrary.jar");
stringToFile(appLibrary.getAbsolutePath(), "Some text");
when(classLoaderLookupPolicy.getClassLookupStrategy(anyString())).thenReturn(PARENT_FIRST);
when(parentArtifactClassLoader.getClassLoaderLookupPolicy()).thenReturn(classLoaderLookupPolicy);
when(parentArtifactClassLoader.getClassLoader()).thenReturn(getClass().getClassLoader());
when(classLoaderLookupPolicy.extend(anyMap())).thenReturn(classLoaderLookupPolicy);
descriptor = new ApplicationDescriptor(APP_NAME);
descriptor.setArtifactLocation(new File(tempMuleHome.newFolder(), APP_NAME));
}
代码示例来源:origin: mulesoft/mule
assertThat(appFolder.mkdirs(), is(true));
FileUtils.stringToFile(new File(appFolder, RESOURCE_IN_CLASSES_AND_JAR).getAbsolutePath(), "Some text");
FileUtils.stringToFile(new File(appFolder, RESOURCE_JUST_IN_CLASSES).getAbsolutePath(), "Some text");
urls.add(appFolder.toURI().toURL());
FileUtils.stringToFile(new File(domainDir, RESOURCE_JUST_IN_DOMAIN).getAbsolutePath(), "Some text");
代码示例来源:origin: org.mule.runtime/mule-core
/**
* Reads the incoming String into a file at at the given destination.
*
* @param filename name and path of the file to create
* @param data the contents of the file
* @return the new file.
* @throws IOException If the creating or writing to the file stream fails
*/
public static File stringToFile(String filename, String data) throws IOException {
return stringToFile(filename, data, false);
}
代码示例来源:origin: org.mule.runtime/mule-core
public static synchronized File stringToFile(String filename, String data, boolean append) throws IOException {
return stringToFile(filename, data, append, false);
}
代码示例来源:origin: mulesoft/mule
File file = null;
try {
file = FileUtils.stringToFile(TEST_FILE, "this is a test file");
assertNotNull(file);
assertTrue(file.exists());
file = FileUtils.stringToFile(TEST_FILE, " and this is appended content", true);
代码示例来源:origin: org.mule.tests/mule-tests-runner
List<GeneratedResource> dumpAll() {
List<GeneratedResource> allResources =
contents.entrySet().stream().map(entry -> new GeneratedResource(entry.getKey(), entry.getValue().toString().getBytes()))
.collect(toImmutableList());
allResources.forEach(resource -> {
File targetFile = new File(resource.getPath());
try {
stringToFile(targetFile.getAbsolutePath(), new String(resource.getContent()));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return allResources;
}
}
代码示例来源:origin: org.mule.runtime/mule-module-extensions-spring-support
private void updateExpectedJson(String json) throws URISyntaxException, IOException {
File root = new File(getResourceAsUrl("models/" + expectedSource, getClass()).toURI()).getParentFile()
.getParentFile().getParentFile().getParentFile();
File testDir = new File(root, "src/test/resources/models");
File target = new File(testDir, expectedSource);
stringToFile(target.getAbsolutePath(), json);
System.out.println(expectedSource + " fixed");
}
代码示例来源:origin: org.mule.runtime/mule-module-deployment-model-impl
@Test
public void createsClassLoaderModelFromFolder() throws Exception {
File policyFolder = temporaryFolder.newFolder();
File libFolder = new File(policyFolder, LIB_DIR);
assertThat(libFolder.mkdir(), is(true));
File file1 = new File(libFolder, "test1.jar");
stringToFile(file1.getAbsolutePath(), "foo");
File file2 = new File(libFolder, "test2.jar");
stringToFile(file2.getAbsolutePath(), "foo");
ClassLoaderModel classLoaderModel = classLoaderModelLoader.load(policyFolder, null, POLICY);
assertThat(classLoaderModel.getUrls().length, equalTo(3));
assertThat(classLoaderModel.getUrls()[0], equalTo(policyFolder.toURI().toURL()));
assertThat(asList(classLoaderModel.getUrls()), allOf(hasItem(file1.toURI().toURL()), hasItem(file2.toURI().toURL())));
assertThat(classLoaderModel.getDependencies(), is(empty()));
assertThat(classLoaderModel.getExportedPackages(), is(empty()));
assertThat(classLoaderModel.getExportedResources(), is(empty()));
}
}
代码示例来源:origin: org.mule.runtime/mule-module-extensions-spring-support
@Test
public void generate() throws Exception {
String schema = generator.generate(extensionUnderTest, new SchemaTestDslContext());
try {
compareXML(expectedSchema, schema);
} catch (Throwable t) {
if (shouldUpdateExpectedFilesOnError()) {
File root = new File(getResourceAsUrl("schemas/" + expectedXSD, getClass()).toURI()).getParentFile()
.getParentFile().getParentFile().getParentFile();
File testDir = new File(root, "src/test/resources/schemas");
File target = new File(testDir, expectedXSD);
stringToFile(target.getAbsolutePath(), schema);
System.out.println(expectedXSD + " fixed");
}
throw t;
}
}
代码示例来源:origin: org.mule.runtime/mule-module-deployment-model
@Before
public void createAppClassLoader() throws IOException {
// Creates folder structure
previousMuleHome = setProperty(MULE_HOME_DIRECTORY_PROPERTY, tempMuleHome.getRoot().getAbsolutePath());
// Add jar file on application's lib folder
File libDir = getAppLibFolder(APP_NAME);
assertThat(libDir.mkdirs(), is(true));
final File appLibrary = new File(libDir, "appLibrary.jar");
stringToFile(appLibrary.getAbsolutePath(), "Some text");
when(classLoaderLookupPolicy.getClassLookupStrategy(anyString())).thenReturn(PARENT_FIRST);
when(parentArtifactClassLoader.getClassLoaderLookupPolicy()).thenReturn(classLoaderLookupPolicy);
when(parentArtifactClassLoader.getClassLoader()).thenReturn(getClass().getClassLoader());
when(classLoaderLookupPolicy.extend(anyMap())).thenReturn(classLoaderLookupPolicy);
descriptor = new ApplicationDescriptor(APP_NAME);
descriptor.setArtifactLocation(new File(tempMuleHome.newFolder(), APP_NAME));
}
代码示例来源:origin: org.mule.runtime/mule-module-deployment-model
assertThat(appFolder.mkdirs(), is(true));
FileUtils.stringToFile(new File(appFolder, RESOURCE_IN_CLASSES_AND_JAR).getAbsolutePath(), "Some text");
FileUtils.stringToFile(new File(appFolder, RESOURCE_JUST_IN_CLASSES).getAbsolutePath(), "Some text");
urls.add(appFolder.toURI().toURL());
FileUtils.stringToFile(new File(domainDir, RESOURCE_JUST_IN_DOMAIN).getAbsolutePath(), "Some text");
代码示例来源:origin: org.mule.runtime/mule-core-tests
File file = null;
try {
file = FileUtils.stringToFile(TEST_FILE, "this is a test file");
assertNotNull(file);
assertTrue(file.exists());
file = FileUtils.stringToFile(TEST_FILE, " and this is appended content", true);
内容来源于网络,如有侵权,请联系作者删除!