本文整理汇总了Java中org.apache.commons.io.FileUtils.write方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.write方法的具体用法?Java FileUtils.write怎么用?Java FileUtils.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.FileUtils
的用法示例。
在下文中一共展示了FileUtils.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildMetadataGeneratorParameters
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* Build metadata generator parameters by passing the encryption,
* signing and back-channel certs to the parameter generator.
*
* @throws Exception Thrown if cert files are missing, or metadata file inaccessible.
*/
protected void buildMetadataGeneratorParameters() throws Exception {
final SamlIdPProperties idp = casProperties.getAuthn().getSamlIdp();
final Resource template = this.resourceLoader.getResource("classpath:/template-idp-metadata.xml");
String signingKey = FileUtils.readFileToString(idp.getMetadata().getSigningCertFile().getFile(), StandardCharsets.UTF_8);
signingKey = StringUtils.remove(signingKey, BEGIN_CERTIFICATE);
signingKey = StringUtils.remove(signingKey, END_CERTIFICATE).trim();
String encryptionKey = FileUtils.readFileToString(idp.getMetadata().getEncryptionCertFile().getFile(), StandardCharsets.UTF_8);
encryptionKey = StringUtils.remove(encryptionKey, BEGIN_CERTIFICATE);
encryptionKey = StringUtils.remove(encryptionKey, END_CERTIFICATE).trim();
try (StringWriter writer = new StringWriter()) {
IOUtils.copy(template.getInputStream(), writer, StandardCharsets.UTF_8);
final String metadata = writer.toString()
.replace("${entityId}", idp.getEntityId())
.replace("${scope}", idp.getScope())
.replace("${idpEndpointUrl}", getIdPEndpointUrl())
.replace("${encryptionKey}", encryptionKey)
.replace("${signingKey}", signingKey);
FileUtils.write(idp.getMetadata().getMetadataFile(), metadata, StandardCharsets.UTF_8);
}
}
示例2: generate
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void generate(int port) {
int port80 = port;
File f = new File("conf/server-module.xml");
File destFile = new File(String.format("conf/server-%d.xml", port));
try {
String fc = FileUtils.readFileToString(f);
fc = StringUtils.replace(fc, "#80#", String.valueOf(port));
FileUtils.write(destFile, fc);
// System.out.println(fc);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: createTestFiles
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static int createTestFiles(File sourceDir, int size)
throws IOException{
File subdir = new File(sourceDir, "subdir");
int expected = 0;
mkdirs(subdir);
File top = new File(sourceDir, "top");
FileUtils.write(top, "toplevel");
expected++;
for (int i = 0; i < size; i++) {
String text = String.format("file-%02d", i);
File f = new File(subdir, text);
FileUtils.write(f, f.toString());
}
expected += size;
// and write the largest file
File largest = new File(subdir, "largest");
FileUtils.writeByteArrayToFile(largest,
ContractTestUtils.dataset(8192, 32, 64));
expected++;
return expected;
}
示例4: CreateArff
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void CreateArff() {
List<String> facetList = BResult_delete4.GetNameOrder("M:\\我是研究生\\任务\\分面树的生成\\Facet\\experiment\\facet_order.txt");
StringBuffer cont = new StringBuffer("@relation FacetData\n\n");
for (String s : facetList) {
cont.append("@attribute " + s.replaceAll(" ", "_") + " {0, 1}\n");
}
cont.append("\[email protected]\n");
List<String> fileName = BResult_delete4.GetNameOrder("M:\\我是研究生\\任务\\分面树的生成\\Facet\\otherFiles\\Data_structure_topics.txt");
for (String name : fileName) {
cont.append("{");
List<String> topicFacet = BResult_delete4.GetNameOrder("M:\\我是研究生\\任务\\分面树的生成\\Facet\\good ground truth\\" + name + ".txt");
for (int i = 0; i < facetList.size(); i++) {
if (topicFacet.contains(facetList.get(i))) {
cont.append(i + " 1,");
}
}
cont.deleteCharAt(cont.length() - 1);
cont.append("}\n");
}
try {
FileUtils.write(new File("C:\\Users\\tong\\Desktop\\dataset\\facet\\facet.arff"), cont.toString(), "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: to
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public void to(final File out, final T object) {
try (StringWriter writer = new StringWriter()) {
this.objectMapper.writer(this.prettyPrinter).writeValue(writer, object);
if (isJsonFormat()) {
try (FileWriter fileWriter = new FileWriter(out);
BufferedWriter buffer = new BufferedWriter(fileWriter)) {
JsonValue.readHjson(writer.toString()).writeTo(buffer);
buffer.flush();
fileWriter.flush();
}
} else {
FileUtils.write(out, writer.toString(), StandardCharsets.UTF_8);
}
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
示例6: writeBundleInfo
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static File writeBundleInfo(AppVariantContext appVariantContext) throws IOException, DocumentException {
List<BundleInfo> bundleInfoList = getBundleInfoList(appVariantContext);
File bundleInfoFile = new File(appVariantContext.getProject().getBuildDir(),
"outputs/bundleInfo-" +
appVariantContext.getVariantConfiguration()
.getVersionName() +
".json");
File bundleInfoFile2 = new File(appVariantContext.getProject().getBuildDir(),
"outputs/pretty-bundleInfo-" +
appVariantContext.getVariantConfiguration()
.getVersionName() +
".json");
try {
FileUtils.write(bundleInfoFile, JSON.toJSONString(bundleInfoList, false));
FileUtils.write(bundleInfoFile2, JSON.toJSONString(bundleInfoList, true));
} catch (IOException e) {
e.printStackTrace();
}
return bundleInfoFile;
}
示例7: testNoOverwriteDest
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void testNoOverwriteDest() throws Throwable {
FileUtils.write(sourceDir, "hello");
LOG.info("Initial upload");
expectSuccess(
"-s", sourceDir.toURI().toString(),
"-d", destDir.toURI().toString());
assertDestDirIsFile();
LOG.info("Second upload");
expectException(IOException.class,
"-s", sourceDir.toURI().toString(),
"-d", destDir.toURI().toString());
// and now with -i, the failure is ignored
expectSuccess(
"-s", sourceDir.toURI().toString(),
"-i",
"-d", destDir.toURI().toString());
}
示例8: test_addPassword
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void test_addPassword() throws IOException {
File file = File.createTempFile("test_password_file", ".json");
file.deleteOnExit();
FileUtils.write(file, "{'aa':{'bb':'cc'}}");
JsonFileCredentialProvider credentialManager = new JsonFileCredentialProvider();
Assert.assertEquals("cc", credentialManager.getPassword(file.getAbsolutePath(), "$.aa.bb"));
}
示例9: save
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
* Makes the argument value as current internal representation (which means it
* will be returned by get()'s) and saves the data to a file.
*/
public synchronized void save(T value) {
SettingsData<T> data = newData(value, mData.version);
try {
String content = mMapper.writeValueAsString(data);
FileUtils.write(mSettingsFile, content, DEFAULT_ENCODING);
mData = data;
}
catch (Exception e) {
throw new RuntimeException("Can't save JSON settings into a file", e);
}
}
示例10: setUp
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws IOException {
File file = temp.newFile("filename");
FileUtils.write(file, "string");
URL plugin = file.toURI().toURL();
StandalonePluginUrls urls = new StandalonePluginUrls(Collections.singletonList(plugin));
cache = mock(PluginCache.class);
index = new StandalonePluginIndex(urls, cache);
}
示例11: windows_without_latest_eol
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void windows_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", StandardCharsets.UTF_8, true);
FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10);
assertThat(metadata.lastValidOffset).isEqualTo(13);
}
示例12: mix_of_newlines_without_latest_eol
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void mix_of_newlines_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 9);
}
示例13: getActivityLogFile
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public File getActivityLogFile() {
String date = df.format(new Date());
String logPath = String.format("%s/activities-on-%s.log", this.getActivityDir().getPath(), date);
File logFile = new File(logPath);
if (!logFile.exists()) {
try {
FileUtils.write(logFile, "", "UTF-8");
} catch (IOException e) {
throw new UnexpectedException("Unable to create activity file: " + logPath, e);
}
}
return logFile;
}
示例14: found_in_cache
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void found_in_cache() throws IOException {
PluginCache cache = PluginCache.create(tempFolder.newFolder().toPath());
// populate the cache. Assume that hash is correct.
File cachedFile = new File(new File(cache.getCacheDir().toFile(), "ABCDE"), "sonar-foo-plugin-1.5.jar");
FileUtils.write(cachedFile, "body");
assertThat(cache.get("sonar-foo-plugin-1.5.jar", "ABCDE").toFile()).isNotNull().exists().isEqualTo(cachedFile);
}
示例15: testCopyFileSrcAndDest
import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void testCopyFileSrcAndDest() throws Throwable {
FileUtils.write(sourceDir, "hello");
expectSuccess(
"-s", sourceDir.toURI().toString(),
"-d", destDir.toURI().toString());
assertDestDirIsFile();
}