📄 filelocator.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: FileLocator.java
package org.pf.file;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.pf.text.StringUtil;
// Referenced classes of package org.pf.file:
// FileUtil
public class FileLocator
{
private static final boolean DEBUG = false;
private static final String FILE_PROTOCOL_INDICATOR;
private static final String ARCHIVE_INDICATOR;
private FileLocator parent;
private File file;
private ZipFile zipFile;
private boolean exists;
private Exception exception;
protected FileLocator getParent()
{
return parent;
}
protected void setParent(FileLocator newValue)
{
parent = newValue;
}
protected File getFile()
{
return file;
}
protected void setFile(File newValue)
{
file = newValue;
}
protected ZipFile getZipFile()
{
return zipFile;
}
protected void setZipFile(ZipFile newValue)
{
zipFile = newValue;
}
protected boolean getExists()
{
return exists;
}
protected void setExists(boolean newValue)
{
exists = newValue;
}
protected Exception getException()
{
return exception;
}
protected void setException(Exception newValue)
{
exception = newValue;
}
public static FileLocator create(File file)
{
FileLocator locator = new FileLocator();
return locator.createFrom(file);
}
public static FileLocator create(String filename)
{
return create(new File(filename));
}
private static FileLocator newWith(FileLocator aParent, String pathElements[])
throws Exception
{
FileLocator locator = new FileLocator();
return locator.createFrom(aParent, pathElements);
}
private FileLocator()
{
parent = null;
file = null;
zipFile = null;
exists = true;
exception = null;
}
public File realFile()
{
File aFile;
try
{
aFile = fileRef();
}
catch (Exception e)
{
aFile = null;
}
return aFile;
}
public boolean exists()
{
return getExists();
}
public boolean isFile()
{
if (exists())
return isFileElement(getFile());
return false;
Exception e;
e;
return false;
}
public boolean isDirectory()
{
if (exists())
return !isFileElement(getFile());
return false;
Exception e;
e;
return false;
}
public long size()
{
ZipEntry entry;
if (!isInArchive())
break MISSING_BLOCK_LABEL_17;
entry = archiveEntry();
return entry.getSize();
return getFile().length();
Exception ex;
ex;
return 0L;
}
public long lastModified()
{
ZipEntry entry;
if (!isInArchive())
break MISSING_BLOCK_LABEL_17;
entry = archiveEntry();
return entry.getTime();
return getFile().lastModified();
Exception ex;
ex;
return 0L;
}
public InputStream getInputStream()
throws Exception
{
if (isInArchive())
{
ZipEntry entry = archiveEntry();
return container().getInputStream(entry);
} else
{
return new FileInputStream(getFile());
}
}
public boolean isInArchive()
{
return getParent() != null;
}
public String getPath()
{
return fullFilePath(false).getPath();
}
public String getAbsolutePath()
{
return fullFilePath(true).getPath();
}
public String getStandardizedPath()
{
return fileUtil().standardize(getPath());
}
public String getStandardizedAbsolutePath()
{
return fileUtil().standardize(getAbsolutePath());
}
public Exception exception()
{
return getException();
}
public URL toURL()
throws MalformedURLException
{
StringBuffer buffer = new StringBuffer(128);
urlPath(buffer);
return new URL(buffer.toString());
}
protected FileLocator createFrom(File filePath)
{
FileLocator locator = null;
String parts[] = null;
File path = filePath;
if (path.getPath().startsWith(FILE_PROTOCOL_INDICATOR))
path = convertFromURLSyntax(path);
parts = str().parts(path.getPath(), File.separator);
try
{
locator = initFromPath(parts, path.getPath().startsWith(File.separator));
}
catch (Exception ex)
{
setException(ex);
doesNotExist(path);
locator = this;
}
return locator;
}
private FileLocator createFrom(FileLocator aParent, String pathElements[])
throws Exception
{
setParent(aParent);
return initFromPath(pathElements, false);
}
protected FileLocator initFromPath(String parts[], boolean startsFromRoot)
throws Exception
{
FileLocator locator = this;
File pathElement = null;
String rest[] = null;
boolean elementExists = false;
if (startsFromRoot)
pathElement = new File(File.separator);
for (int i = 0; i < parts.length; i++)
{
if (pathElement == null)
pathElement = new File(parts[i]);
else
pathElement = new File(pathElement, parts[i]);
elementExists = doesElementExist(pathElement);
if (elementExists)
{
setFile(pathElement);
if (!isFileElement(pathElement))
continue;
if (i < parts.length - 1)
{
rest = str().copyFrom(parts, i + 1);
locator = newWith(this, rest);
}
break;
}
if (isInArchive())
{
if (i >= parts.length - 1)
throw new Exception((new StringBuilder()).append("\"").append(pathElement.getPath()).append("\" does not exist").toString());
} else
{
throw new Exception((new StringBuilder()).append("\"").append(pathElement.getPath()).append("\" does not exist").toString());
}
}
return locator;
}
protected boolean doesElementExist(File element)
throws Exception
{
if (isInArchive())
return doesElementExistInArchive(element.getPath());
else
return element.exists();
}
protected boolean isFileElement(File element)
throws Exception
{
if (isInArchive())
return isFileInArchive(element.getPath());
else
return element.isFile();
}
protected boolean doesElementExistInArchive(String elementName)
throws Exception
{
ZipEntry entry = entryFromArchive(elementName);
return entry != null;
}
protected boolean isFileInArchive(String elementName)
throws Exception
{
ZipEntry entry = entryFromArchive(elementName);
return entry != null && entry.getSize() > 0L;
}
protected ZipEntry entryFromArchive(String elementName)
throws Exception
{
String name = str().replaceAll(elementName, "\\", "/");
ZipFile archive = container();
ZipEntry entry = archive.getEntry(name);
return entry;
}
protected ZipEntry archiveEntry()
throws Exception
{
return entryFromArchive(getFile().getPath());
}
protected void doesNotExist(File file)
{
setExists(false);
setFile(file);
}
protected File fullFilePath(boolean absolute)
{
File full;
if (isInArchive())
full = new File(getParent().fullFilePath(absolute), getFile().getPath());
else
if (absolute)
full = getFile().getAbsoluteFile();
else
full = getFile();
return full;
}
protected void urlPath(StringBuffer buffer)
{
if (isInArchive())
{
getParent().urlPath(buffer);
buffer.append(ARCHIVE_INDICATOR);
} else
{
buffer.append(FILE_PROTOCOL_INDICATOR);
}
buffer.append(getFile().getPath());
}
protected File fileRef()
throws Exception
{
if (isInArchive())
{
ZipEntry entry = archiveEntry();
InputStream archiveStream = container().getInputStream(entry);
File tempFile = File.createTempFile("FLOC_", ".xtr");
tempFile.deleteOnExit();
FileOutputStream fileStream = new FileOutputStream(tempFile);
fileUtil().copyStream(archiveStream, fileStream);
return tempFile;
} else
{
return getFile();
}
}
protected ZipFile archive()
throws Exception
{
if (getZipFile() == null)
setZipFile(new ZipFile(fileRef()));
return getZipFile();
}
protected ZipFile container()
throws Exception
{
if (isInArchive())
return getParent().archive();
else
return null;
}
protected File convertFromURLSyntax(File file)
{
String newStr = file.getPath().substring(FILE_PROTOCOL_INDICATOR.length());
newStr = str().replaceAll(newStr, ARCHIVE_INDICATOR, File.separator);
return new File(newStr);
}
protected StringUtil str()
{
return StringUtil.current();
}
protected FileUtil fileUtil()
{
return FileUtil.current();
}
static
{
FILE_PROTOCOL_INDICATOR = (new StringBuilder()).append("file:").append(File.separator).toString();
ARCHIVE_INDICATOR = (new StringBuilder()).append("!").append(File.separator).toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -