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


Java FileUtils.isAbsolute方法代码示例

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


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

示例1: setBaseDir

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Set the base directory of persistent databases, unless the database is in
 * the user home folder (~).
 *
 * @param dir the new base directory
 */
public void setBaseDir(String dir) {
    if (persistent) {
        String absDir = FileUtils.unwrap(FileUtils.toRealPath(dir));
        boolean absolute = FileUtils.isAbsolute(name);
        String n;
        String prefix = null;
        if (dir.endsWith(SysProperties.FILE_SEPARATOR)) {
            dir = dir.substring(0, dir.length() - 1);
        }
        if (absolute) {
            n = name;
        } else {
            n  = FileUtils.unwrap(name);
            prefix = name.substring(0, name.length() - n.length());
            n = dir + SysProperties.FILE_SEPARATOR + n;
        }
        String normalizedName = FileUtils.unwrap(FileUtils.toRealPath(n));
        if (normalizedName.equals(absDir) || !normalizedName.startsWith(absDir)) {
            // database name matches the baseDir or
            // database name is clearly outside of the baseDir
            throw DbException.get(ErrorCode.IO_EXCEPTION_1, normalizedName + " outside " +
                    absDir);
        }
        if (absDir.endsWith("/") || absDir.endsWith("\\")) {
            // no further checks are needed for C:/ and similar
        } else if (normalizedName.charAt(absDir.length()) != '/') {
            // database must be within the directory
            // (with baseDir=/test, the database name must not be
            // /test2/x and not /test2)
            throw DbException.get(ErrorCode.IO_EXCEPTION_1, normalizedName + " outside " +
                    absDir);
        }
        if (!absolute) {
            name = prefix + dir + SysProperties.FILE_SEPARATOR + FileUtils.unwrap(name);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:44,代码来源:ConnectionInfo.java

示例2: getName

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
 * Get the unique and normalized database name (excluding settings).
 *
 * @return the database name
 */
public String getName() {
    if (persistent) {
        if (nameNormalized == null) {
            if (!SysProperties.IMPLICIT_RELATIVE_PATH) {
                if (!FileUtils.isAbsolute(name)) {
                    if (name.indexOf("./") < 0 &&
                            name.indexOf(".\\") < 0 &&
                            name.indexOf(":/") < 0 &&
                            name.indexOf(":\\") < 0) {
                        // the name could start with "./", or
                        // it could start with a prefix such as "nio:./"
                        // for Windows, the path "\test" is not considered
                        // absolute as the drive letter is missing,
                        // but we consider it absolute
                        throw DbException.get(
                                ErrorCode.URL_RELATIVE_TO_CWD,
                                originalURL);
                    }
                }
            }
            String suffix = Constants.SUFFIX_PAGE_FILE;
            String n;
            if (FileUtils.exists(name + suffix)) {
                n = FileUtils.toRealPath(name + suffix);
            } else {
                suffix = Constants.SUFFIX_MV_FILE;
                n = FileUtils.toRealPath(name + suffix);
            }
            String fileName = FileUtils.getName(n);
            if (fileName.length() < suffix.length() + 1) {
                throw DbException.get(ErrorCode.INVALID_DATABASE_NAME_1, name);
            }
            nameNormalized = n.substring(0, n.length() - suffix.length());
        }
        return nameNormalized;
    }
    return name;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:44,代码来源:ConnectionInfo.java

示例3: getFile

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private String getFile(String f) {
    if (FileUtils.isAbsolute(f)) {
        return f;
    }
    String unwrapped = FileUtils.unwrap(f);
    String prefix = f.substring(0, f.length() - unwrapped.length());
    f = prefix + currentWorkingDirectory + SysProperties.FILE_SEPARATOR + unwrapped;
    return FileUtils.toRealPath(f);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:10,代码来源:FileShell.java

示例4: process

import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void process(Connection conn, boolean continueOnError, String path,
        Reader reader, Charset charset) throws SQLException, IOException {
    Statement stat = conn.createStatement();
    ScriptReader r = new ScriptReader(reader);
    while (true) {
        String sql = r.readStatement();
        if (sql == null) {
            break;
        }
        String trim = sql.trim();
        if (trim.length() == 0) {
            continue;
        }
        if (trim.startsWith("@") && StringUtils.toUpperEnglish(trim).
                startsWith("@INCLUDE")) {
            sql = trim;
            sql = sql.substring("@INCLUDE".length()).trim();
            if (!FileUtils.isAbsolute(sql)) {
                sql = path + SysProperties.FILE_SEPARATOR + sql;
            }
            process(conn, sql, continueOnError, charset);
        } else {
            try {
                if (showResults && !trim.startsWith("-->")) {
                    out.print(sql + ";");
                }
                if (showResults || checkResults) {
                    boolean query = stat.execute(sql);
                    if (query) {
                        ResultSet rs = stat.getResultSet();
                        int columns = rs.getMetaData().getColumnCount();
                        StringBuilder buff = new StringBuilder();
                        while (rs.next()) {
                            buff.append("\n-->");
                            for (int i = 0; i < columns; i++) {
                                String s = rs.getString(i + 1);
                                if (s != null) {
                                    s = StringUtils.replaceAll(s, "\r\n", "\n");
                                    s = StringUtils.replaceAll(s, "\n", "\n-->    ");
                                    s = StringUtils.replaceAll(s, "\r", "\r-->    ");
                                }
                                buff.append(' ').append(s);
                            }
                        }
                        buff.append("\n;");
                        String result = buff.toString();
                        if (showResults) {
                            out.print(result);
                        }
                        if (checkResults) {
                            String expected = r.readStatement() + ";";
                            expected = StringUtils.replaceAll(expected, "\r\n", "\n");
                            expected = StringUtils.replaceAll(expected, "\r", "\n");
                            if (!expected.equals(result)) {
                                expected = StringUtils.replaceAll(expected, " ", "+");
                                result = StringUtils.replaceAll(result, " ", "+");
                                throw new SQLException(
                                        "Unexpected output for:\n" + sql.trim() +
                                        "\nGot:\n" + result + "\nExpected:\n" + expected);
                            }
                        }

                    }
                } else {
                    stat.execute(sql);
                }
            } catch (Exception e) {
                if (continueOnError) {
                    e.printStackTrace(out);
                } else {
                    throw DbException.toSQLException(e);
                }
            }
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:77,代码来源:RunScript.java


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