Method from com.sun.tools.javac.zip.ZipFileIndex Detail: |
public static void clearCache() {
lock.lock();
try {
zipFileIndexCache.clear();
}
finally {
lock.unlock();
}
}
|
public static void clearCache(long timeNotUsed) {
lock.lock();
try {
Iterator< File > cachedFileIterator = zipFileIndexCache.keySet().iterator();
while (cachedFileIterator.hasNext()) {
File cachedFile = cachedFileIterator.next();
ZipFileIndex cachedZipIndex = zipFileIndexCache.get(cachedFile);
if (cachedZipIndex != null) {
long timeToTest = cachedZipIndex.lastReferenceTimeStamp + timeNotUsed;
if (timeToTest < cachedZipIndex.lastReferenceTimeStamp || // Overflow...
System.currentTimeMillis() > timeToTest) {
zipFileIndexCache.remove(cachedFile);
}
}
}
}
finally {
lock.unlock();
}
}
|
public void close() {
lock.lock();
try {
writeIndex();
closeFile();
}
finally {
lock.unlock();
}
}
|
public boolean contains(String path) {
lock.lock();
try {
checkIndex();
return getZipIndexEntry(path) != null;
}
catch (IOException e) {
return false;
}
finally {
lock.unlock();
}
}
Tests if a specific path exists in the zip. This method will return true
for file entries and directories. |
protected void finalize() {
closeFile();
}
|
public Set<String> getAllDirectories() {
lock.lock();
try {
checkIndex();
if (allDirs == Collections.EMPTY_SET) {
Set< String > alldirs = new HashSet< String >();
Iterator< String > dirsIter = directories.keySet().iterator();
while (dirsIter.hasNext()) {
alldirs.add(new String(dirsIter.next()));
}
allDirs = alldirs;
}
return allDirs;
}
catch (IOException e) {
return Collections.< String >emptySet();
}
finally {
lock.unlock();
}
}
|
public List<String> getAllDirectories(String path) {
if (File.separatorChar != '/') {
path = path.replace('/', File.separatorChar);
}
lock.lock();
try {
checkIndex();
path = path.intern();
DirectoryEntry de = directories.get(path);
com.sun.tools.javac.util.List< String > ret = de == null ? null : de.getDirectories();
if (ret == null) {
return com.sun.tools.javac.util.List.< String >nil();
}
return ret;
}
catch (IOException e) {
return com.sun.tools.javac.util.List.< String >nil();
}
finally {
lock.unlock();
}
}
|
public static ZipFileIndex getExistingZipIndex(File zipFile) {
lock.lock();
try {
return zipFileIndexCache.get(zipFile);
}
finally {
lock.unlock();
}
}
|
public List<String> getFiles(String path) {
if (File.separatorChar != '/') {
path = path.replace('/', File.separatorChar);
}
lock.lock();
try {
checkIndex();
DirectoryEntry de = directories.get(path);
com.sun.tools.javac.util.List< String > ret = de == null ? null : de.getFiles();
if (ret == null) {
return com.sun.tools.javac.util.List.< String >nil();
}
return ret;
}
catch (IOException e) {
return com.sun.tools.javac.util.List.< String >nil();
}
finally {
lock.unlock();
}
}
Returns a javac List of filenames within an absolute path in the ZipFileIndex. |
public long getLastModified(String path) throws IOException {
lock.lock();
try {
ZipFileIndexEntry entry = getZipIndexEntry(path);
if (entry == null)
throw new FileNotFoundException();
return entry.getLastModified();
}
finally {
lock.unlock();
}
}
|
public File getZipFile() {
return zipFile;
}
|
public static ZipFileIndex getZipFileIndex(File zipFile,
int symbolFilePrefixLen,
boolean useCache,
String cacheLocation,
boolean writeIndex) throws IOException {
ZipFileIndex zi = null;
lock.lock();
try {
zi = getExistingZipIndex(zipFile);
if (zi == null || (zi != null && zipFile.lastModified() != zi.zipFileLastModified)) {
zi = new ZipFileIndex(zipFile, symbolFilePrefixLen, writeIndex,
useCache, cacheLocation);
zipFileIndexCache.put(zipFile, zi);
}
}
finally {
lock.unlock();
}
return zi;
}
|
public static List<ZipFileIndex> getZipFileIndexes() {
return getZipFileIndexes(false);
}
Returns a list of all ZipFileIndex entries |
public static List<ZipFileIndex> getZipFileIndexes(boolean openedOnly) {
List< ZipFileIndex > zipFileIndexes = new ArrayList< ZipFileIndex >();
lock.lock();
try {
zipFileIndexes.addAll(zipFileIndexCache.values());
if (openedOnly) {
for(ZipFileIndex elem : zipFileIndexes) {
if (!elem.isOpen()) {
zipFileIndexes.remove(elem);
}
}
}
}
finally {
lock.unlock();
}
return zipFileIndexes;
}
Returns a list of all ZipFileIndex entries |
public long getZipFileLastModified() throws IOException {
lock.lock();
try {
checkIndex();
return zipFileLastModified;
}
finally {
lock.unlock();
}
}
Returns the last modified timestamp of a zip file. |
public ZipFileIndexEntry getZipIndexEntry(String path) {
if (File.separatorChar != '/') {
path = path.replace('/', File.separatorChar);
}
lock.lock();
try {
checkIndex();
String lookFor = "";
int lastSepIndex = path.lastIndexOf(File.separatorChar);
boolean noSeparator = false;
if (lastSepIndex == -1) {
noSeparator = true;
}
DirectoryEntry de = directories.get(noSeparator ? "" : path.substring(0, lastSepIndex));
lookFor = path.substring(noSeparator ? 0 : lastSepIndex + 1);
return de == null ? null : de.getEntry(lookFor);
}
catch (IOException e) {
return null;
}
finally {
lock.unlock();
}
}
Returns the ZipFileIndexEntry for an absolute path, if there is one. |
public boolean isDirectory(String path) throws IOException {
lock.lock();
try {
// The top level in a zip file is always a directory.
if (path.length() == 0) {
lastReferenceTimeStamp = System.currentTimeMillis();
return true;
}
if (File.separatorChar != '/')
path = path.replace('/', File.separatorChar);
checkIndex();
return directories.get(path) != null;
}
finally {
lock.unlock();
}
}
|
public boolean isOpen() {
lock.lock();
try {
return zipRandomFile != null;
}
finally {
lock.unlock();
}
}
|
public int length(String path) throws IOException {
lock.lock();
try {
ZipFileIndexEntry entry = getZipIndexEntry(path);
if (entry == null)
throw new FileNotFoundException();
if (entry.isDir) {
return 0;
}
byte[] header = getHeader(entry);
// entry is not compressed?
if (get2ByteLittleEndian(header, 8) == 0) {
return entry.compressedSize;
} else {
return entry.size;
}
}
finally {
lock.unlock();
}
}
|
public byte[] read(String path) throws IOException {
lock.lock();
try {
ZipFileIndexEntry entry = getZipIndexEntry(path);
if (entry == null)
throw new FileNotFoundException(MessageFormat.format("Path not found in ZIP: {0}", path));
return read(entry);
}
finally {
lock.unlock();
}
}
|
public byte[] read(ZipFileIndexEntry entry) throws IOException {
lock.lock();
try {
openFile();
byte[] result = readBytes(entry);
closeFile();
return result;
}
finally {
lock.unlock();
}
}
|
public int read(String path,
byte[] buffer) throws IOException {
lock.lock();
try {
ZipFileIndexEntry entry = getZipIndexEntry(path);
if (entry == null)
throw new FileNotFoundException();
return read(entry, buffer);
}
finally {
lock.unlock();
}
}
|
public int read(ZipFileIndexEntry entry,
byte[] buffer) throws IOException {
lock.lock();
try {
int result = readBytes(entry, buffer);
return result;
}
finally {
lock.unlock();
}
}
|
public static void removeFromCache(File file) {
lock.lock();
try {
zipFileIndexCache.remove(file);
}
finally {
lock.unlock();
}
}
|
public static void setOpenedIndexes(List<ZipFileIndex> indexes) throws IllegalStateException {
lock.lock();
try {
if (zipFileIndexCache.isEmpty()) {
throw new IllegalStateException("Setting opened indexes should be called only when the ZipFileCache is empty. Call JavacFileManager.flush() before calling this method.");
}
for (ZipFileIndex zfi : indexes) {
zipFileIndexCache.put(zfi.zipFile, zfi);
}
}
finally {
lock.unlock();
}
}
Sets already opened list of ZipFileIndexes from an outside client
of the compiler. This functionality should be used in a non-batch clients of the compiler. |
public String toString() {
return "ZipFileIndex of file:(" + zipFile + ")";
}
|
public boolean writeZipIndex() {
lock.lock();
try {
return writeIndex();
}
finally {
lock.unlock();
}
}
|