当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils.write方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:TemplatedMetadataAndCertificatesGenerationService.java

示例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();
		}

	}
 
开发者ID:how2j,项目名称:lazycat,代码行数:19,代码来源:ServerXMLGenerator.java

示例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;
}
 
开发者ID:steveloughran,项目名称:cloudup,代码行数:23,代码来源:CloudupTestUtils.java

示例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();
    }
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:27,代码来源:PreprocessData.java

示例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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:20,代码来源:AbstractJacksonBackedStringSerializer.java

示例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;
    }
 
开发者ID:alibaba,项目名称:atlas,代码行数:25,代码来源:BundleInfoUtils.java

示例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());
}
 
开发者ID:steveloughran,项目名称:cloudup,代码行数:20,代码来源:TestLocalCloudup.java

示例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"));
}
 
开发者ID:uber,项目名称:uberscriptquery,代码行数:11,代码来源:JsonFileCredentialProviderTest.java

示例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);
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:17,代码来源:JsonSettings.java

示例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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:10,代码来源:StandalonePluginIndexTest.java

示例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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:11,代码来源:FileMetadataTest.java

示例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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:10,代码来源:FileMetadataTest.java

示例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;
}
 
开发者ID:riboseinc,项目名称:aws-codecommit-trigger-plugin,代码行数:14,代码来源:SQSActivityAction.java

示例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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:11,代码来源:PluginCacheTest.java

示例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();
}
 
开发者ID:steveloughran,项目名称:cloudup,代码行数:9,代码来源:TestLocalCloudup.java


注:本文中的org.apache.commons.io.FileUtils.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。