當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtils.fileWrite方法代碼示例

本文整理匯總了Java中org.codehaus.plexus.util.FileUtils.fileWrite方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtils.fileWrite方法的具體用法?Java FileUtils.fileWrite怎麽用?Java FileUtils.fileWrite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.plexus.util.FileUtils的用法示例。


在下文中一共展示了FileUtils.fileWrite方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createEnvWrapperFile

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
private File createEnvWrapperFile( File vsInstallDir, String platform )
    throws IOException
{

    File tmpFile = File.createTempFile( "msenv", ".bat" );

    StringBuffer buffer = new StringBuffer();
    buffer.append( "@echo off\r\n" );
    buffer.append( "call \"" ).append( vsInstallDir ).append( "\"" ).append( "\\VC\\vcvarsall.bat " + platform
                                                                                 + "\n\r" );
    buffer.append( "echo " + EnvStreamConsumer.START_PARSING_INDICATOR ).append( "\r\n" );
    buffer.append( "set\n\r" );

    FileUtils.fileWrite( tmpFile.getAbsolutePath(), buffer.toString() );

    return tmpFile;
}
 
開發者ID:mojohaus,項目名稱:maven-native,代碼行數:18,代碼來源:AbstractMSVCEnvFactory.java

示例2: insertPreWrapperConf

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
private void insertPreWrapperConf( File wrapperConf, File preWrapperConf )
    throws DaemonGeneratorException
{
    try
    {
        StringBuilder buffer = new StringBuilder();
        buffer.append( FileUtils.fileRead( preWrapperConf ) );
        buffer.append( "\n" );
        buffer.append( FileUtils.fileRead( wrapperConf ) );
        FileUtils.fileWrite( wrapperConf, buffer.toString() );
    }
    catch ( IOException e )
    {
        throw new DaemonGeneratorException( "Unable to merge pre wrapper config file." );
    }
}
 
開發者ID:mojohaus,項目名稱:appassembler,代碼行數:17,代碼來源:JavaServiceWrapperDaemonGenerator.java

示例3: installSignChecksum

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
void installSignChecksum(Path pChecksumPath, Path pArchivePath, boolean pRepack) throws MojoExecutionException
{
  String checksum = _calculateChecksum(pArchivePath, pRepack);

  Path path = pChecksumPath.resolveSibling(pChecksumPath.getFileName() + _getPostfix());
  log.debug("Installing checksum to " + path);
  try
  {
    Files.createDirectories(path.getParent());
    FileUtils.fileWrite(path.toFile(), "UTF-8", checksum);
  }
  catch (IOException e)
  {
    throw new MojoExecutionException("Failed to install checksum to " + path, e);
  }
}
 
開發者ID:aditosoftware,項目名稱:repository-jarsign-maven-plugin,代碼行數:17,代碼來源:SignChecksumHelper.java

示例4: failLocalChangeItTest

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
@Test
@Ignore
// svn local db corrupted
public void failLocalChangeItTest()
    throws Exception
{
    File projDir = resources.getBasedir( "failed-local-change" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File basedir = result.getBasedir();
    File foo = new File( basedir, "foo.txt" );
    FileUtils.fileWrite( foo, "hello" );
    FileUtils.copyDirectory( new File( basedir, "DotSvnDir" ), new File( basedir, ".svn" ) );
    result = mavenExec.execute( "verify" );
    // this fail local dotSvnDir corrupted, not b/c we change local file
    result.assertLogText( "BUILD FAILURE" );
}
 
開發者ID:mojohaus,項目名稱:buildnumber-maven-plugin,代碼行數:20,代碼來源:BuildNumberMojoTest.java

示例5: gitBasicItMBUILDNUM66Test

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
@Test
@Ignore
// git local database corrected
public void gitBasicItMBUILDNUM66Test()
    throws Exception
{
    File projDir = resources.getBasedir( "git-basic-it-MBUILDNUM-66" );

    MavenExecution mavenExec = maven.forProject( projDir );
    MavenExecutionResult result = mavenExec.execute( "clean" );
    result.assertErrorFreeLog();
    File basedir = result.getBasedir();
    File foo = new File( basedir, "foo.txt" );
    FileUtils.fileWrite( foo, "hello" );
    FileUtils.copyDirectory( new File( basedir, "dotGitDir" ), new File( basedir, ".git" ) );
    result = mavenExec.execute( "verify" );
    // this fail local dotSvnDir corrupted, not b/c we change local file

}
 
開發者ID:mojohaus,項目名稱:buildnumber-maven-plugin,代碼行數:20,代碼來源:BuildNumberMojoTest.java

示例6: playActions

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
public void playActions() throws Exception {
  for (FileSystemAction action : actions) {
    if (action.kind == ENTRY_CREATE) {
      FileUtils.fileWrite(action.path.toFile(), action.content);
    } else if (action.kind == ENTRY_MODIFY) {
      FileUtils.fileAppend(action.path.toFile().getAbsolutePath(), action.content);
      action.path.toFile().setLastModified(new Date().getTime());
    } else if (action.kind == ENTRY_DELETE) {
      action.path.toFile().delete();
    } else {
      switch (action.myType) {
        case WAIT:
          try {
            Thread.sleep(action.millis);
          } catch (InterruptedException e) {
          }
          break;
        case MKDIR:
          if (!action.path.toFile().exists()) {
            action.path.toFile().mkdirs();
          }
          break;
        case COUNTABLE:
        case NOOP:
          break;
      }
    }
  }
}
 
開發者ID:takari,項目名稱:directory-watcher,代碼行數:30,代碼來源:FileSystem.java

示例7: processToml

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
private List<String> processToml(
    File tomlFile,
    File templatesDirectory,
    Map<String, String> env,
    String encoding,
    boolean mkdirs
) throws IOException {
    Toml toml = new Toml().read(tomlFile);
    String src = toml.getString("template.src");
    String dest = toml.getString("template.dest");
    List<String> keys = toml.getList("template.keys");

    if (keys == null || keys.size() == 0) {
        throw new IOException("Something went wrong while processing the toml file <" + tomlFile +
            ">: the 'keys' section must exist and contain at least one key");
    }

    // filter the env map according to the keys defined in the toml
    HashMap<String, String> filteredEnv = new HashMap<String, String>();
    for (Map.Entry<String, String> entry : env.entrySet()) {
        for (String key : keys) {
            if (entry.getKey().startsWith(key)) {
                filteredEnv.put(entry.getKey(), entry.getValue());
            }
        }
    }
    File templateFile = new File(templatesDirectory, src);
    File destFile = new File(dest);
    if (mkdirs) {
        destFile.getParentFile().mkdirs();
    }
    Parser parser = new Parser(templateFile, encoding);
    String parsedTemplate = parser.parse(filteredEnv);
    FileUtils.fileWrite(destFile, encoding, parsedTemplate);
    return parser.getTemplateKeys();
}
 
開發者ID:nodevops,項目名稱:confd-maven-plugin,代碼行數:37,代碼來源:JavaProcessorImpl.java

示例8: writeToml

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
public static void writeToml(
    File tomlFile,
    TemplateConfig tc,
    boolean globalForceDestToLocalFileSystemType) throws IOException {
    StringWriter sw = new StringWriter();
    sw.append("[template]")
        .append(LINE_SEPARATOR);

    sw.append("src = ")
        .append(QUOTE)
        .append(FileUtils.removePath(tc.getSrc().getPath()))
        .append(QUOTE)
        .append(LINE_SEPARATOR);

    sw.append("dest = ")
        .append(QUOTE)
        .append(tc.getResolvedDestPath(globalForceDestToLocalFileSystemType))
        .append(QUOTE)
        .append(LINE_SEPARATOR);

    sw.append("keys = [")
        .append(LINE_SEPARATOR);
    for (String key : tc.getKeys()) {
        sw.append(QUOTE)
            .append(key)
            .append(QUOTE)
            .append(',')
            .append(LINE_SEPARATOR);
    }

    sw.append(']')
        .append(LINE_SEPARATOR);

    FileUtils.fileWrite(tomlFile, "UTF8", sw.toString());
}
 
開發者ID:nodevops,項目名稱:confd-maven-plugin,代碼行數:36,代碼來源:WorkingDirectoryUtil.java

示例9: createTestFile

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
protected File createTestFile(String[] lines) throws IOException {
    StringBuilder sb = new StringBuilder();
    for (String s : lines) {
        sb.append(s).append('\n');
    }
    File f = temporaryFolder.newFile("test.dict");
    FileUtils.fileWrite(f, ENCODING, sb.toString());
    return f;
}
 
開發者ID:nodevops,項目名稱:confd-maven-plugin,代碼行數:10,代碼來源:AbstractTest.java

示例10: copyResource

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
private void copyResource(String source, File target, String separator, HashMap<String, String> interpolations) throws MojoExecutionException {

        try {
            String content = loadTextResource(getClass().getResource(source));
            if( interpolations!=null ) {
                content = StringUtils.interpolate(content, interpolations);
            }
            content = content.replaceAll("\\r?\\n", Matcher.quoteReplacement(separator));
            FileUtils.fileWrite(target, content);
        } catch (IOException e) {
            throw new MojoExecutionException("Could create the "+target+" file", e);
        }
    }
 
開發者ID:jboss-fuse,項目名稱:hawt-app,代碼行數:14,代碼來源:BuildMojo.java

示例11: createCassandraYaml

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
/**
 * Generates the {@code cassandra.yaml} file.
 *
 * @param cassandraYaml the {@code cassandra.yaml} file.
 * @param data          The data directory.
 * @param commitlog     The commitlog directory.
 * @param savedCaches   The saved caches directory.
 * @param listenAddress The address to listen on for storage and other cassandra servers.
 * @param rpcAddress    The address to listen on for clients.
 * @param seeds         The seeds.
 * @throws IOException If something went wrong.
 */
private void createCassandraYaml( File cassandraYaml, File data, File commitlog, File savedCaches,
                                  String listenAddress, String rpcAddress, BigInteger initialToken, String[] seeds )
    throws IOException
{
    String defaults = IOUtil.toString( getClass().getResourceAsStream( "/cassandra.yaml" ) );
    StringBuilder config = new StringBuilder();
    config.append( "data_file_directories:\n" ).append( "    - " ).append( data.getAbsolutePath() ).append( "\n" );
    config.append( "commitlog_directory: " ).append( commitlog ).append( "\n" );
    config.append( "saved_caches_directory: " ).append( savedCaches ).append( "\n" );
    config.append( "initial_token: " ).append(
        initialToken == null || "null".equals( initialToken ) ? "" : initialToken.toString() ).append( "\n" );
    config.append( "listen_address: " ).append( listenAddress ).append( "\n" );
    config.append( "storage_port: " ).append( storagePort ).append( "\n" );
    config.append( "rpc_address: " ).append( rpcAddress ).append( "\n" );
    config.append( "rpc_port: " ).append( rpcPort ).append( "\n" );
    config.append( "native_transport_port: " ).append( nativeTransportPort ).append( "\n" );
    config.append( "start_native_transport: " ).append( startNativeTransport ).append( "\n" );
    if ( seeds != null )
    {
        config.append( "seed_provider: " ).append( "\n" );
        config.append( "    - class_name: org.apache.cassandra.locator.SimpleSeedProvider" ).append( "\n" );
        config.append( "      parameters:" ).append( "\n" );
        String sep = "          - seeds: \"";
        for ( int i = 0; i < seeds.length; i++ )
        {
            config.append( sep ).append( seeds[i] );
            sep = ", ";
        }
        if ( sep.length() == 2 )
        {
            config.append( "\"" ).append( "\n" );
        }
    }
    FileUtils.fileWrite( cassandraYaml.getAbsolutePath(),
                         Utils.merge( Utils.merge( defaults, yaml ), config.toString() ) );
}
 
開發者ID:mojohaus,項目名稱:cassandra-maven-plugin,代碼行數:49,代碼來源:AbstractCassandraMojo.java

示例12: fixIndirectLibraryReferences

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
/**
 * 
 * 
 * @param projectDirectory
 * @param dependentLibs
 * @param log
 * @throws Exception
 */
public void fixIndirectLibraryReferences(File projectDirectory, Collection<String> dependentLibs, Log log) throws Exception
{
    File projectFile = new File(projectDirectory, ".project");
    if (!projectFile.exists()) {
        throw new Exception("unable to locate .project file at " + projectFile.getAbsolutePath());
    }
    String content = FileUtils.fileRead(projectFile);
    String projectsStartTag = "<projects>";
    String projectsEndTag = "</projects>";
    String projectStartTag = "<project>";
    String projectEndTag = "</project>";

    // / just want to append the file at the right point
    int insertionPoint = content.indexOf(projectsEndTag);
    if (insertionPoint == -1)
    {
        log.info("unable to find " + projectsEndTag + " in .project file");
    }
    String firstPart = content.substring(0, insertionPoint);

    String lastPart = content.substring(insertionPoint);

    String projectsSection = content.substring(content.indexOf(projectsStartTag), insertionPoint);
    boolean firstPartAppended = false;
    for (String dependentLib : dependentLibs)
    {
        String libTagNeeded = projectStartTag + dependentLib + projectEndTag;
        if (!projectsSection.contains(libTagNeeded))
        {
            firstPartAppended = true;
            firstPart += "\t" + libTagNeeded;
            log.info("adding direct project reference " + libTagNeeded + " to " + projectFile.getAbsolutePath());
        }

    }
    if (firstPartAppended)
    {
        firstPart += "\n\t";
    }
    else
    {
        log.info("no dependent libraries fix needed for " + projectFile.getAbsolutePath());
    }
    content = firstPart + lastPart;
    FileUtils.fileWrite(projectFile, content);


}
 
開發者ID:bretthshelley,項目名稱:Maven-IIB9-Plug-In,代碼行數:57,代碼來源:EclipseProjectFixUtil.java

示例13: writeTargetToProjectFile

import org.codehaus.plexus.util.FileUtils; //導入方法依賴的package包/類
/**
 * Write the ant target and surrounding tags to a temporary file
 *
 * @throws PlexusConfigurationException
 */
private File writeTargetToProjectFile()
        throws IOException, PlexusConfigurationException {
    // Have to use an XML writer because in Maven 2.x the PlexusConfig toString() method loses XML attributes
    StringWriter writer = new StringWriter();
    AntrunXmlPlexusConfigurationWriter xmlWriter = new AntrunXmlPlexusConfigurationWriter();
    xmlWriter.write(target, writer);

    StringBuffer antProjectConfig = writer.getBuffer();

    // replace deprecated tasks tag with standard Ant target
    stringReplace(antProjectConfig, "<tasks", "<target");
    stringReplace(antProjectConfig, "</tasks", "</target");

    antTargetName = target.getAttribute("name");

    if (antTargetName == null) {
        antTargetName = DEFAULT_ANT_TARGET_NAME;
        stringReplace(antProjectConfig, "<target", "<target name=\"" + antTargetName + "\"");
    }

    String xmlns = "";
    if (!customTaskPrefix.trim().equals("")) {
        xmlns = "xmlns:" + customTaskPrefix + "=\"" + TASK_URI + "\"";
    }

    final String xmlHeader = "<?xml version=\"1.0\" encoding=\"" + UTF_8 + "\" ?>\n";
    antProjectConfig.insert(0, xmlHeader);
    final String projectOpen = "<project name=\"maven-antrun-\" default=\"" + antTargetName + "\" " + xmlns + " >\n";
    int index = antProjectConfig.indexOf("<target");
    antProjectConfig.insert(index, projectOpen);

    final String projectClose = "\n</project>";
    antProjectConfig.append(projectClose);

    // The fileName should probably use the plugin executionId instead of the targetName
    String fileName = "build-" + antTargetName + ".xml";
    File file = new File(project.getBuild().getDirectory(), "/antrun/" + fileName);

    file.getParentFile().mkdirs();
    FileUtils.fileWrite(file.getAbsolutePath(), UTF_8, antProjectConfig.toString());
    return file;
}
 
開發者ID:0xC70FF3,項目名稱:java-gems,代碼行數:48,代碼來源:DebianMojo.java


注:本文中的org.codehaus.plexus.util.FileUtils.fileWrite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。