本文整理了Java中com.sun.enterprise.util.io.FileUtils.safeIsDirectory()
方法的一些代码示例,展示了FileUtils.safeIsDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.safeIsDirectory()
方法的具体详情如下:
包路径:com.sun.enterprise.util.io.FileUtils
类名称:FileUtils
方法名:safeIsDirectory
暂无
代码示例来源:origin: org.glassfish.main.common/common-util
public static boolean safeIsDirectory(String s) {
return safeIsDirectory(new File(s));
}
代码示例来源:origin: org.glassfish.common/common-util
public static boolean safeIsDirectory(String s) {
return safeIsDirectory(new File(s));
}
代码示例来源:origin: eclipse-ee4j/glassfish
public static boolean safeIsDirectory(String s) {
return safeIsDirectory(new File(s));
}
代码示例来源:origin: org.glassfish.web/web-glue
private static void verify(File inWebDir, File outWebDir) throws DeploymentException {
// inWebDir must exist, outWebDir must either exist or be creatable
if (!FileUtils.safeIsDirectory(inWebDir)) {
throw new DeploymentException("inWebDir is not a directory: " + inWebDir);
}
if (!FileUtils.safeIsDirectory(outWebDir)) {
outWebDir.mkdirs();
if (!FileUtils.safeIsDirectory(outWebDir)) {
throw new DeploymentException("outWebDir is not a directory, and it can't be created: " + outWebDir);
}
}
}
代码示例来源:origin: org.glassfish.main.admin/backup
private void copyBackups() throws IOException {
File domainBackupDir =
new File(request.domainDir, Constants.BACKUP_DIR);
/**
* If an existing backup directory does not exist then there
* is nothing to copy.
*/
if(!FileUtils.safeIsDirectory(domainBackupDir))
return;
File tempRestoreDirBackups = new File(tempRestoreDir,
Constants.BACKUP_DIR);
FileUtils.copyTree(domainBackupDir, tempRestoreDirBackups);
}
代码示例来源:origin: org.glassfish.common/common-util
/**
* Copies a file.
*
* @param fin File to copy
* @param fout New file
* @throws IOException if an error while copying the content
*/
public static void copy(File fin, File fout) throws IOException {
if (safeIsDirectory(fin)) {
copyTree(fin, fout);
return;
}
if (!fin.exists())
throw new IllegalArgumentException("File source doesn't exist");
if (!safeIsDirectory(fout.getParentFile()))
fout.getParentFile().mkdirs();
copyFile(fin, fout);
}
代码示例来源:origin: org.glassfish.common/common-util
/**
* Copies the entire tree to a new location.
*
* @param din File pointing at root of tree to copy
* @param dout File pointing at root of new tree
* @throws IOException if an error while copying the content
*/
public static void copyTree(File din, File dout)
throws IOException {
if (!safeIsDirectory(din))
throw new IllegalArgumentException("Source isn't a directory");
dout.mkdirs();
if (!safeIsDirectory(dout))
throw new IllegalArgumentException("Can't create destination directory");
FileListerRelative flr = new FileListerRelative(din);
String[] files = flr.getFiles();
for (int i = 0; i < files.length; i++) {
File fin = new File(din, files[i]);
File fout = new File(dout, files[i]);
copy(fin, fout);
}
}
代码示例来源:origin: org.glassfish.main.common/common-util
public static boolean safeIsRealDirectory(File f) {
if (safeIsDirectory(f) == false)
return false;
// these 2 values while be different for symbolic links
String canonical = safeGetCanonicalPath(f);
String absolute = f.getAbsolutePath();
if (canonical.equals(absolute))
return true;
/* Bug 4715043 -- WHOA -- Bug Obscura!!
* In Windows, if you create the File object with, say, "d:/foo", then the
* absolute path will be "d:\foo" and the canonical path will be "D:\foo"
* and they won't match!!!
**/
if (OS.isWindows() && canonical.equalsIgnoreCase(absolute))
return true;
return false;
}
代码示例来源:origin: org.glassfish.common/common-util
public static boolean safeIsRealDirectory(File f) {
if (safeIsDirectory(f) == false)
return false;
// these 2 values while be different for symbolic links
String canonical = safeGetCanonicalPath(f);
String absolute = f.getAbsolutePath();
if (canonical.equals(absolute))
return true;
/* Bug 4715043 -- WHOA -- Bug Obscura!!
* In Windows, if you create the File object with, say, "d:/foo", then the
* absolute path will be "d:\foo" and the canonical path will be "D:\foo"
* and they won't match!!!
**/
if (OS.isWindows() && canonical.equalsIgnoreCase(absolute))
return true;
return false;
}
代码示例来源:origin: eclipse-ee4j/glassfish
public static boolean safeIsRealDirectory(File f) {
if (safeIsDirectory(f) == false)
return false;
// these 2 values while be different for symbolic links
String canonical = safeGetCanonicalPath(f);
String absolute = f.getAbsolutePath();
if (canonical.equals(absolute))
return true;
/* Bug 4715043 -- WHOA -- Bug Obscura!!
* In Windows, if you create the File object with, say, "d:/foo", then the
* absolute path will be "d:\foo" and the canonical path will be "D:\foo"
* and they won't match!!!
**/
if (OS.isWindows() && canonical.equalsIgnoreCase(absolute))
return true;
return false;
}
代码示例来源:origin: org.glassfish.main.common/common-util
/**
* Copies a file.
*
* @param fin File to copy
* @param fout New file
* @throws IOException if an error while copying the content
*/
public static void copy(File fin, File fout) throws IOException {
if (safeIsDirectory(fin)) {
copyTree(fin, fout);
return;
}
if (!fin.exists())
throw new IllegalArgumentException("File source doesn't exist");
if(!mkdirsMaybe(fout.getParentFile()))
throw new RuntimeException("Can't create parent dir of output file: " + fout);
copyFile(fin, fout);
}
代码示例来源:origin: eclipse-ee4j/glassfish
/**
* Copies a file.
*
* @param fin File to copy
* @param fout New file
* @throws IOException if an error while copying the content
*/
public static void copy(File fin, File fout) throws IOException {
if (safeIsDirectory(fin)) {
copyTree(fin, fout);
return;
}
if (!fin.exists())
throw new IllegalArgumentException("File source doesn't exist");
if(!mkdirsMaybe(fout.getParentFile()))
throw new RuntimeException("Can't create parent dir of output file: " + fout);
copyFile(fin, fout);
}
代码示例来源:origin: org.glassfish.main.admin/backup
void init() throws BackupException {
// only do once!
if(wasInitialized)
return;
if(request == null)
throw new BackupException("backup-res.InternalError",
"null BackupRequest reference");
// add a timestamp
request.timestamp = System.currentTimeMillis();
// validate domains dir
if (request.domainsDir == null ||
!FileUtils.safeIsDirectory(request.domainsDir))
throw new BackupException("backup-res.NoDomainsDir",
request.domainsDir);
if (request.domainName != null)
request.domainDir = new File(request.domainsDir, request.domainName);
LoggerHelper.setLevel(request);
}
代码示例来源:origin: org.glassfish.deployment/deployment-common
/**
* This method returns the relative file path of an embedded module to
* the application root.
* For example, if the module is expanded/located at
* $domain_dir/applications/j2ee-apps/foo/fooEJB_jar,
* this method will return fooEJB_jar
*
*@param appRootPath The path of the application root which
* contains the module
* e.g. $domain_dir/applications/j2ee-apps/foo
*@param moduleUri The module uri
* e.g. fooEJB.jar
*@return The relative file path of the module to the application root
*/
public static String getRelativeEmbeddedModulePath(String appRootPath,
String moduleUri) {
moduleUri = FileUtils.makeLegalNoBlankFileName(moduleUri);
if (FileUtils.safeIsDirectory(new File(appRootPath, moduleUri))) {
return moduleUri;
} else {
return FileUtils.makeFriendlyFilenameExtension(moduleUri);
}
}
代码示例来源:origin: org.glassfish.main.admin/backup
private void initWithNoSpecifiedBackupFile() throws BackupException {
// if they did NOT specify a backupFile, then we *must* have a
// pre-existing backups directory in a pre-existing domain directory.
if(!FileUtils.safeIsDirectory(request.domainDir))
throw new BackupException("backup-res.NoDomainDir",
request.domainDir);
backupDir = getBackupDirectory(request);
// It's an error to not exist...
if(!FileUtils.safeIsDirectory(backupDir))
throw new BackupException("backup-res.NoBackupDir", backupDir);
BackupFilenameManager bfmgr = new BackupFilenameManager(backupDir,
request.domainName);
request.backupFile = bfmgr.latest();
//request.backupFile = getNewestZip(backupDir);
}
代码示例来源:origin: org.glassfish.main.common/common-util
/**
* Copies the entire tree to a new location.
*
* @param din File pointing at root of tree to copy
* @param dout File pointing at root of new tree
* @throws IOException if an error while copying the content
*/
public static void copyTree(File din, File dout)
throws IOException {
if (!safeIsDirectory(din))
throw new IllegalArgumentException("Source isn't a directory");
if(!mkdirsMaybe(dout))
throw new IllegalArgumentException("Can't create destination directory");
FileListerRelative flr = new FileListerRelative(din);
String[] files = flr.getFiles();
for (int i = 0; i < files.length; i++) {
File fin = new File(din, files[i]);
File fout = new File(dout, files[i]);
copy(fin, fout);
}
}
代码示例来源:origin: org.glassfish.main.admin/backup
/**
* Finish initializing the BackupRequest object.
* note: this method is called by the super class...
* @throws BackupException for fatal errors
* @throws BackupWarningException for non-fatal errors - these are errors
* where we can not continue execution.
*/
void init() throws BackupException, BackupWarningException {
super.init();
if(!FileUtils.safeIsDirectory(request.domainDir))
throw new BackupException("backup-res.NoDomainDir",
request.domainDir);
// It's a warning to not exist...
if(!FileUtils.safeIsDirectory(getBackupDirectory(request)))
throw new BackupWarningException("backup-res.NoBackupDir",
getBackupDirectory(request));
}
代码示例来源:origin: eclipse-ee4j/glassfish
/**
* Copies the entire tree to a new location.
*
* @param din File pointing at root of tree to copy
* @param dout File pointing at root of new tree
* @throws IOException if an error while copying the content
*/
public static void copyTree(File din, File dout)
throws IOException {
if (!safeIsDirectory(din))
throw new IllegalArgumentException("Source isn't a directory");
if(!mkdirsMaybe(dout))
throw new IllegalArgumentException("Can't create destination directory");
FileListerRelative flr = new FileListerRelative(din);
String[] files = flr.getFiles();
for (int i = 0; i < files.length; i++) {
File fin = new File(din, files[i]);
File fout = new File(dout, files[i]);
copy(fin, fout);
}
}
代码示例来源:origin: org.glassfish.main.admin/backup
private void initWithSpecifiedBackupFile() throws BackupException {
if(request.backupFile.length() <= 0)
throw new BackupException("backup-res.CorruptBackupFile",
request.backupFile);
if (request.domainName == null) {
if (!request.force) {
throw new BackupException("backup-res.UseForceOption");
}
Status status = new Status();
status.read(request.backupFile);
request.domainName = status.getDomainName();
request.domainDir = new File(request.domainsDir, request.domainName);
}
if(!FileUtils.safeIsDirectory(request.domainDir))
if (!request.domainDir.mkdirs())
throw new BackupException("backup-res.CantCreateDomainDir",
request.domainDir);
backupDir = new File(request.domainDir, Constants.BACKUP_DIR);
// It's NOT an error to not exist. The domain may not exist
// currently and, besides, they are specifying the backup-file
// from anywhere potentially...
if(!FileUtils.safeIsDirectory(backupDir))
backupDir = null;
//throw new BackupException("NOT YET IMPLEMENTED");
}
代码示例来源:origin: org.glassfish.main.admin/backup
void init() throws BackupException {
super.init();
if(request.backupFile != null)
throw new BackupException("backup-res.InternalError",
"No backupFilename may be specified for a backup -- it is reserved for restore operations only.");
if(!FileUtils.safeIsDirectory(request.domainDir))
throw new BackupException("backup-res.NoDomainDir",
request.domainDir);
File backupDir = getBackupDirectory(request);
// mkdirs may fail if the directory exists or it could not be created.
if (!backupDir.mkdirs()) {
// If it doesn't exist then it is an error.
if(!FileUtils.safeIsDirectory(backupDir))
throw new BackupException("backup-res.NoBackupDirCantCreate",
backupDir);
}
BackupFilenameManager bfmgr =
new BackupFilenameManager(backupDir, request.domainName);
request.backupFile = bfmgr.next();
// get customized description if user hasn't specified one
if(request.description == null || request.description.length() <= 0)
request.description = bfmgr.getCustomizedDescription();
}
内容来源于网络,如有侵权,请联系作者删除!