public void open(URI... uris) throws IOException { archives = new ReadableArchive[uris.length]; int slot = 0; for (URI uri : uris) { archives[slot++] = archiveFactory.openArchive(uri); } }
/** * Reports whether the entry is valid, in the sense that the entry is * more recent than the archive itself. * @param entryName name of the entry to check * @return */ private boolean isEntryValid(final String entryName, final Logger logger) { return isEntryValid(getEntryFile(entryName), true, logger); }
private boolean isEntryValid(final File entry, final boolean isLogging, final Logger logger) { return staleFileManager().isEntryValid(entry, isLogging, logger); }
public ReadableArchive openArchive(File path) throws java.io.IOException { try { return openArchive(prepareArchiveURI(path)); } catch(java.net.URISyntaxException e) { return null; } }
public WritableArchive createArchive(String protocol, File path) throws java.io.IOException { try { /* *Use the expanded constructor so illegal characters (such as embedded blanks) in the path *will be encoded. */ return createArchive(protocol, prepareArchiveURI(path)); } catch(java.net.URISyntaxException e) { return null; } }
/** * Creates a new archivist using the URL as the path. The URL * protocol will define the type of desired archive (jar, file, etc) * @param path to the archive * @return the apropriate archive */ public WritableArchive createArchive(URI path) throws IOException { String protocol = path.getScheme(); return createArchive(protocol, path); }
/** * @see #open(URI) * @param uri a string representing URI */ public void open(String uri) throws IOException { open(URI.create(uri)); }
private StaleFileManager staleFileManager() { ReadableArchive parent = getParentArchive(); if (parent == null) { return staleFileManager; } if (parent instanceof FileArchive) { return ((FileArchive) parent).staleFileManager(); } else { return null; } }
/** * delete the archive */ @Override public boolean delete() { // delete the directory structure... try { final boolean result = deleteDir(archive); /* * Create the stale file marker file, if needed. */ StaleFileManager.Util.markDeletedArchive(this); return result; } catch (IOException e) { return false; } }
/** * Factory method for a StaleFileManager. * <p> * Callers should invoke this method only after they have finished with * the FileArchive and have tried to delete it. If the directory * for the archive remains then it contains one or more stale files * that could not be deleted, and the factory method returns a * instance that tracks the stale files. If the directory no longer * exists then the delete succeeded, there are * @param archive the directory to contain the archive * @return StaleFileManager for the FileArchive to use */ public static StaleFileManager getInstance(final File archive) throws IOException { if (archive.exists()) { return new StaleFileManagerImpl(archive); } else { return new StaleFileManagerImplNoop(); } } }
private boolean deleteEntry(String name, final boolean isLogging) { name = name.replace('/', File.separatorChar); File input = new File(archive, name); if (!input.exists() || ! isEntryValid(input, isLogging)) { return false; } final boolean result = input.delete(); staleFileManager.recordDeletedEntry(input); return result; }
private boolean isEntryValid(final File entry, final boolean isLogging) { return isEntryValid(entry, isLogging, logger); }
/** * utility method for getting contents of directory and * sub directories */ private void getListOfFiles(File directory, List<String> files, List embeddedArchives) { getListOfFiles(directory, files, embeddedArchives, logger); }
/** delete an entry in the archive * @param name the entry name * @return true if the entry was successfully deleted * */ public boolean deleteEntry(String name) { return deleteEntry(name, true); }
@Override public boolean isEntryValid(final File f, final boolean isLogging) { return isEntryValid(f, isLogging, logger); }
private StaleFileManagerImpl(final File archive) throws FileNotFoundException, IOException { archiveFile = archive; archiveURI = archive.toURI(); markerFile = StaleFileManager.Util.markerFile(archive); staleEntryNames = readStaleEntryNames(markerFile); }
/** * Opens the specified file as an archive, using the provided archive factory. * @param dir directory to be opened as an archive * @param archiveFactory ArchiveFactory to use to create the archive object * @return FileArchive opened for the directory * @throws IOException */ public static FileArchive openAsFileArchive(final File dir, final ArchiveFactory archiveFactory) throws IOException { return (FileArchive) archiveFactory.openArchive(dir); }
public WritableArchive createArchive(File path) throws java.io.IOException { try { /* *Use the expanded constructor so illegal characters (such as embedded blanks) in the path *will be encoded. */ return createArchive(prepareArchiveURI(path)); } catch(java.net.URISyntaxException e) { return null; } }
/** * Reports whether the entry is valid, in the sense that if this * archive has been created during this execution then the entry * requested was created later than the archive itself. * <p> * It is possible (for example, on Windows) for GlassFish to want to create * a new archive in a directory that already exists and contains stale * "left-over" files from a previous deployment, for example. This method * causes the FileArchive implementation to hide any files that * reside in the directory for an archive that was created during this VM * execution but were not explicitly added to the archive using putNextEntry. * * @param entry file to check * @return */ private boolean isEntryValid(final File entry) { return isEntryValid(entry, true, logger); }
@Override public boolean isDirectory(String name) { final File candidate = new File(this.archive, name); return isEntryValid(candidate) && candidate.isDirectory(); }