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


Java PathUtils.normalizeFileSystemPath方法代码示例

本文整理汇总了Java中org.apache.zookeeper.common.PathUtils.normalizeFileSystemPath方法的典型用法代码示例。如果您正苦于以下问题:Java PathUtils.normalizeFileSystemPath方法的具体用法?Java PathUtils.normalizeFileSystemPath怎么用?Java PathUtils.normalizeFileSystemPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.common.PathUtils的用法示例。


在下文中一共展示了PathUtils.normalizeFileSystemPath方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDynamicFile

import org.apache.zookeeper.common.PathUtils; //导入方法依赖的package包/类
private String createDynamicFile(String quorumCfgSection, String version)
        throws IOException {
    String filename = "zoo.cfg.dynamic";
    if( version != null ){
        filename = filename + "." + version;
    }

    File dynamicConfigFile = new File(tmpDir, filename);
    String dynamicConfigFilename = PathUtils.normalizeFileSystemPath(dynamicConfigFile.toString());

    FileWriter fDynamicConfigWriter = new FileWriter(dynamicConfigFile);
    fDynamicConfigWriter.write(quorumCfgSection);
    fDynamicConfigWriter.flush();
    fDynamicConfigWriter.close();

    return dynamicConfigFilename;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:18,代码来源:QuorumPeerTestBase.java

示例2: MainThread

import org.apache.zookeeper.common.PathUtils; //导入方法依赖的package包/类
public MainThread(int clientPort) throws IOException {
    super("Standalone server with clientPort:" + clientPort);
    File tmpDir = ClientBase.createTmpDir();
    confFile = new File(tmpDir, "zoo.cfg");

    FileWriter fwriter = new FileWriter(confFile);
    fwriter.write("tickTime=2000\n");
    fwriter.write("initLimit=10\n");
    fwriter.write("syncLimit=5\n");
    fwriter.write("snapCount=1\n");

    File dataDir = new File(tmpDir, "data");
    if (!dataDir.mkdir()) {
        throw new IOException("unable to mkdir " + dataDir);
    }
    
    // Convert windows path to UNIX to avoid problems with "\"
    String dir = PathUtils.normalizeFileSystemPath(dataDir.toString());
    fwriter.write("dataDir=" + dir + "\n");
    
    fwriter.write("clientPort=" + clientPort + "\n");
    fwriter.flush();
    fwriter.close();

    main = new TestMain();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:27,代码来源:InvalidSnapCountTest.java

示例3: MainThread

import org.apache.zookeeper.common.PathUtils; //导入方法依赖的package包/类
public MainThread(int clientPort, boolean preCreateDirs, File tmpDir, String configs)
        throws IOException {
    super("Standalone server with clientPort:" + clientPort);
    this.tmpDir = tmpDir;
    confFile = new File(tmpDir, "zoo.cfg");

    FileWriter fwriter = new FileWriter(confFile);
    fwriter.write("tickTime=2000\n");
    fwriter.write("initLimit=10\n");
    fwriter.write("syncLimit=5\n");
    if(configs != null){
        fwriter.write(configs);
    }

    dataDir = new File(this.tmpDir, "data");
    logDir = new File(dataDir.toString() + "_txnlog");
    if (preCreateDirs) {
        if (!dataDir.mkdir()) {
            throw new IOException("unable to mkdir " + dataDir);
        }
        if (!logDir.mkdir()) {
            throw new IOException("unable to mkdir " + logDir);
        }
        ClientBase.createInitializeFile(logDir);
    }
    
    String normalizedDataDir = PathUtils.normalizeFileSystemPath(dataDir.toString());
    String normalizedLogDir = PathUtils.normalizeFileSystemPath(logDir.toString());
    fwriter.write("dataDir=" + normalizedDataDir + "\n");
    fwriter.write("dataLogDir=" + normalizedLogDir + "\n");
    fwriter.write("clientPort=" + clientPort + "\n");
    fwriter.flush();
    fwriter.close();

    main = new TestZKSMain();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:37,代码来源:ZooKeeperServerMainTest.java

示例4: MainThread

import org.apache.zookeeper.common.PathUtils; //导入方法依赖的package包/类
public MainThread(int clientPort, boolean preCreateDirs, String configs)
        throws IOException {
    super("Standalone server with clientPort:" + clientPort);
    tmpDir = ClientBase.createTmpDir();
    confFile = new File(tmpDir, "zoo.cfg");

    FileWriter fwriter = new FileWriter(confFile);
    fwriter.write("tickTime=2000\n");
    fwriter.write("initLimit=10\n");
    fwriter.write("syncLimit=5\n");
    if(configs != null){
        fwriter.write(configs);
    }

    File dataDir = new File(tmpDir, "data");
    String dir = dataDir.toString();
    String dirLog = dataDir.toString() + "_txnlog";
    if (preCreateDirs) {
        if (!dataDir.mkdir()) {
            throw new IOException("unable to mkdir " + dataDir);
        }
        dirLog = dataDir.toString();
    }
    
    dir = PathUtils.normalizeFileSystemPath(dir);
    dirLog = PathUtils.normalizeFileSystemPath(dirLog);
    fwriter.write("dataDir=" + dir + "\n");
    fwriter.write("dataLogDir=" + dirLog + "\n");
    fwriter.write("clientPort=" + clientPort + "\n");
    fwriter.flush();
    fwriter.close();

    main = new TestZKSMain();
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:35,代码来源:ZooKeeperServerMainTest.java

示例5: editStaticConfig

import org.apache.zookeeper.common.PathUtils; //导入方法依赖的package包/类
/**
 * Edit static config file.
 * If there are quorum information in static file, e.g. "server.X", "group",
 * it will remove them.
 * If it needs to erase client port information left by the old config,
 * "eraseClientPortAddress" should be set true.
 * It should also updates dynamic file pointer on reconfig.
 */
public static void editStaticConfig(final String configFileStr,
                                    final String dynamicFileStr,
                                    final boolean eraseClientPortAddress)
        throws IOException {
    // Some tests may not have a static config file.
    if (configFileStr == null)
        return;

    File configFile = (new VerifyingFileFactory.Builder(LOG)
            .warnForRelativePath()
            .failForNonExistingPath()
            .build()).create(configFileStr);

    final File dynamicFile = (new VerifyingFileFactory.Builder(LOG)
            .warnForRelativePath()
            .failForNonExistingPath()
            .build()).create(dynamicFileStr);
    
    final Properties cfg = new Properties();
    FileInputStream in = new FileInputStream(configFile);
    try {
        cfg.load(in);
    } finally {
        in.close();
    }

    new AtomicFileWritingIdiom(new File(configFileStr), new WriterStatement() {
        @Override
        public void write(Writer out) throws IOException {
            for (Entry<Object, Object> entry : cfg.entrySet()) {
                String key = entry.getKey().toString().trim();

                if (key.startsWith("server.")
                    || key.startsWith("group")
                    || key.startsWith("weight")
                    || key.startsWith("dynamicConfigFile")
                    || key.startsWith("peerType")
                    || (eraseClientPortAddress
                        && (key.startsWith("clientPort")
                            || key.startsWith("clientPortAddress")))) {
                    // not writing them back to static file
                    continue;
                }

                String value = entry.getValue().toString().trim();
                out.write(key.concat("=").concat(value).concat("\n"));
            }

            // updates the dynamic file pointer
            String dynamicConfigFilePath = PathUtils.normalizeFileSystemPath(dynamicFile.getCanonicalPath());
            out.write("dynamicConfigFile="
                     .concat(dynamicConfigFilePath)
                     .concat("\n"));
        }
    });
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:65,代码来源:QuorumPeerConfig.java

示例6: MainThread

import org.apache.zookeeper.common.PathUtils; //导入方法依赖的package包/类
public MainThread(int myid, int clientPort, int adminServerPort, Integer secureClientPort,
                  String quorumCfgSection, String configs, boolean writeDynamicConfigFile, String version)
        throws IOException {
    tmpDir = ClientBase.createTmpDir();
    LOG.info("id = " + myid + " tmpDir = " + tmpDir + " clientPort = "
            + clientPort + " adminServerPort = " + adminServerPort);

    File dataDir = new File(tmpDir, "data");
    if (!dataDir.mkdir()) {
        throw new IOException("Unable to mkdir " + dataDir);
    }

    confFile = new File(tmpDir, "zoo.cfg");

    FileWriter fwriter = new FileWriter(confFile);
    fwriter.write("tickTime=4000\n");
    fwriter.write("initLimit=10\n");
    fwriter.write("syncLimit=5\n");
    if(configs != null){
        fwriter.write(configs);
    }

    // Convert windows path to UNIX to avoid problems with "\"
    String dir = PathUtils.normalizeFileSystemPath(dataDir.toString());

    fwriter.write("dataDir=" + dir + "\n");
    fwriter.write("admin.serverPort=" + adminServerPort + "\n");

    // For backward compatibility test, some tests create dynamic configuration
    // without setting client port.
    // This could happen both in static file or dynamic file.
    if (clientPort != UNSET_STATIC_CLIENTPORT) {
        fwriter.write("clientPort=" + clientPort + "\n");
    }

    if (secureClientPort != null) {
        fwriter.write("secureClientPort=" + secureClientPort + "\n");
    }

    if (writeDynamicConfigFile) {
        String dynamicConfigFilename = createDynamicFile(quorumCfgSection, version);
        fwriter.write("dynamicConfigFile=" + dynamicConfigFilename + "\n");
    } else {
        fwriter.write(quorumCfgSection);
    }
    fwriter.flush();
    fwriter.close();

    File myidFile = new File(dataDir, "myid");
    fwriter = new FileWriter(myidFile);
    fwriter.write(Integer.toString(myid));
    fwriter.flush();
    fwriter.close();
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:55,代码来源:QuorumPeerTestBase.java


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