protected DefaultFileReplicator createDefaultFileReplicator() { return new DefaultFileReplicator(); }
protected File createAndAddFile(final File parent, final String basename) throws FileSystemException { final File file = createFile(tempDir, basename); // Keep track to delete later addFile(file); return file; }
/** * Allocates a new temporary file. * * @param baseName the base file name. * @return The created File. * @throws FileSystemException if an error occurs. */ @Override public File allocateFile(final String baseName) throws FileSystemException { // Create a unique-ish file name final String basename = createFilename(baseName); synchronized (this) { filecount++; } return createAndAddFile(tempDir, basename); }
/** * Physically deletes the file from the filesystem. * * @param file The File to delete. */ protected void deleteFile(final File file) { try { final FileObject fileObject = getContext().toFileObject(file); fileObject.deleteAll(); } catch (final FileSystemException e) { final String message = Messages.getString("vfs.impl/delete-temp.warn", file.getName()); VfsLog.warn(getLogger(), log, message, e); } }
/** * Creates a local copy of the file, and all its descendants. * * @param srcFile The file to copy. * @param selector The FileSelector. * @return the created File. * @throws FileSystemException if an error occurs copying the file. */ @Override public File replicateFile(final FileObject srcFile, final FileSelector selector) throws FileSystemException { final String basename = srcFile.getName().getBaseName(); final File file = allocateFile(basename); // Copy from the source file final FileObject destFile = getContext().toFileObject(file); destFile.copyFrom(srcFile, selector); return file; } }
/** * Closes the replicator, deleting all temporary files. */ @Override public void close() { // Delete the temporary files synchronized (copies) { while (copies.size() > 0) { final File file = (File) removeFile(); deleteFile(file); } } // Clean up the temp directory, if it is empty if (tempDir != null && tempDir.exists() && tempDir.list().length == 0) { tempDir.delete(); tempDir = null; } }
/** * Create the temporary file name. * * @param baseName The base to prepend to the file name being created. * @return the name of the File. */ protected String createFilename(final String baseName) { // BUG29007 // return baseName + "_" + getFilecount() + ".tmp"; // imario@apache.org: BUG34976 get rid of maybe reserved and dangerous characters // e.g. to allow replication of http://hostname.org/fileservlet?file=abc.txt final String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_'); return "tmp_" + getFilecount() + "_" + safeBasename; }
/** * Initializes this component. * * @throws FileSystemException if an error occurs. */ @Override public void init() throws FileSystemException { if (tempDir == null) { final String baseTmpDir = System.getProperty("java.io.tmpdir"); tempDir = new File(baseTmpDir, "vfs_cache").getAbsoluteFile(); } filecount = random.nextInt() & MASK; if (!tempDirMessageLogged) { final String message = Messages.getString("vfs.impl/temp-dir.debug", tempDir); VfsLog.debug(getLogger(), log, message); tempDirMessageLogged = true; } }
/** * Physically deletes the file from the filesystem. * * @param file The File to delete. */ protected void deleteFile(final File file) { try { final FileObject fileObject = getContext().toFileObject(file); fileObject.deleteAll(); } catch (final FileSystemException e) { final String message = Messages.getString("vfs.impl/delete-temp.warn", file.getName()); VfsLog.warn(getLogger(), log, message, e); } }
/** * Creates a local copy of the file, and all its descendants. * * @param srcFile The file to copy. * @param selector The FileSelector. * @return the created File. * @throws FileSystemException if an error occurs copying the file. */ @Override public File replicateFile(final FileObject srcFile, final FileSelector selector) throws FileSystemException { final String basename = srcFile.getName().getBaseName(); final File file = allocateFile(basename); // Copy from the source file final FileObject destFile = getContext().toFileObject(file); destFile.copyFrom(srcFile, selector); return file; } }
/** * Closes the replicator, deleting all temporary files. */ @Override public void close() { // Delete the temporary files synchronized (copies) { while (copies.size() > 0) { final File file = (File) removeFile(); deleteFile(file); } } // Clean up the temp directory, if it is empty if (tempDir != null && tempDir.exists() && tempDir.list().length == 0) { tempDir.delete(); tempDir = null; } }
/** * Create the temporary file name. * * @param baseName The base to prepend to the file name being created. * @return the name of the File. */ protected String createFilename(final String baseName) { // BUG29007 // return baseName + "_" + getFilecount() + ".tmp"; // imario@apache.org: BUG34976 get rid of maybe reserved and dangerous characters // e.g. to allow replication of http://hostname.org/fileservlet?file=abc.txt final String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_'); return "tmp_" + getFilecount() + "_" + safeBasename; }
/** * Initializes this component. * * @throws FileSystemException if an error occurs. */ @Override public void init() throws FileSystemException { if (tempDir == null) { final String baseTmpDir = System.getProperty("java.io.tmpdir"); tempDir = new File(baseTmpDir, "vfs_cache").getAbsoluteFile(); } filecount = random.nextInt() & MASK; if (!tempDirMessageLogged) { final String message = Messages.getString("vfs.impl/temp-dir.info", tempDir); VfsLog.info(getLogger(), log, message); tempDirMessageLogged = true; } }
protected DefaultFileReplicator createDefaultFileReplicator() { return new DefaultFileReplicator(); }
protected File createAndAddFile(final File parent, final String basename) throws FileSystemException { final File file = createFile(tempDir, basename); // Keep track to delete later addFile(file); return file; }
/** * Physically deletes the file from the filesystem. * * @param file The File to delete. */ protected void deleteFile(final File file) { try { final FileObject fileObject = getContext().toFileObject(file); fileObject.deleteAll(); } catch (final FileSystemException e) { final String message = Messages.getString("vfs.impl/delete-temp.warn", file.getName()); VfsLog.warn(getLogger(), log, message, e); } }
/** * Creates a local copy of the file, and all its descendants. * * @param srcFile The file to copy. * @param selector The FileSelector. * @return the created File. * @throws FileSystemException if an error occurs copying the file. */ @Override public File replicateFile(final FileObject srcFile, final FileSelector selector) throws FileSystemException { final String basename = srcFile.getName().getBaseName(); final File file = allocateFile(basename); // Copy from the source file final FileObject destFile = getContext().toFileObject(file); destFile.copyFrom(srcFile, selector); return file; } }
/** * Allocates a new temporary file. * * @param baseName the base file name. * @return The created File. * @throws FileSystemException if an error occurs. */ @Override public File allocateFile(final String baseName) throws FileSystemException { // Create a unique-ish file name final String basename = createFilename(baseName); synchronized (this) { filecount++; } return createAndAddFile(tempDir, basename); }
/** * Closes the replicator, deleting all temporary files. */ @Override public void close() { // Delete the temporary files synchronized (copies) { while (copies.size() > 0) { final File file = (File) removeFile(); deleteFile(file); } } // Clean up the temp directory, if it is empty if (tempDir != null && tempDir.exists() && tempDir.list().length == 0) { tempDir.delete(); tempDir = null; } }
/** * Create the temporary file name. * * @param baseName The base to prepend to the file name being created. * @return the name of the File. */ protected String createFilename(final String baseName) { // BUG29007 // return baseName + "_" + getFilecount() + ".tmp"; // imario@apache.org: BUG34976 get rid of maybe reserved and dangerous characters // e.g. to allow replication of http://hostname.org/fileservlet?file=abc.txt final String safeBasename = UriParser.encode(baseName, TMP_RESERVED_CHARS).replace('%', '_'); return "tmp_" + getFilecount() + "_" + safeBasename; }