/** * Deletes this resource. * * @param pruneEmptyParentDirs if <code>true</code>, empty parent folders will * automatically be deleted * @see FileSystem#deleteFile */ public synchronized void delete(boolean pruneEmptyParentDirs) throws FileSystemException { fs.deleteFile(path); if (pruneEmptyParentDirs) { // prune empty parent folders String parentDir = FileSystemPathUtil.getParentDir(path); while (!parentDir.equals(FileSystem.SEPARATOR) && fs.exists(parentDir) && !fs.hasChildren(parentDir)) { fs.deleteFolder(parentDir); parentDir = FileSystemPathUtil.getParentDir(parentDir); } } }
/** * @see FileSystem#getInputStream */ public InputStream getInputStream() throws FileSystemException { return fs.getInputStream(path); }
/** * Creates the parent directory of this resource, including any necessary * but nonexistent parent directories. * * @throws FileSystemException */ public synchronized void makeParentDirs() throws FileSystemException { String parentDir = getParentDir(); if (!fs.exists(parentDir)) { fs.createFolder(parentDir); } }
/** * {@inheritDoc} */ public void init() throws FileSystemException { // check base path if (!fsBase.isFolder(basePath)) { fsBase.createFolder(basePath); } }
assertTrue(fs.exists("/")); assertTrue(fs.isFolder("/")); assertFalse(fs.isFile("/")); assertEquals(0, fs.list("/").length); fs.createFolder("/folder"); assertTrue(fs.exists("/folder")); assertTrue(fs.isFolder("/folder")); assertFalse(fs.isFile("/folder")); assertEquals(0, fs.list("/folder").length); list = fs.list("/"); assertEquals(1, list.length); assertEquals("folder", list[0]); assertTrue(fs.exists("/folder/file")); assertFalse(fs.isFolder("/folder/file")); assertTrue(fs.isFile("/folder/file")); list = fs.list("/folder"); assertEquals(1, list.length); assertEquals("file", list[0]); assertEquals(3, fs.length("/folder/file")); verifyStreamInput(fs.getInputStream("/folder/file"), sampleBytes); fs.createFolder("/folder2/subfolder"); createFile("/folder2/file2", sampleBytes); assertTrue(fs.exists("/folder2/subfolder")); assertTrue(fs.isFolder("/folder2/subfolder")); assertFalse(fs.isFile("/folder2/subfolder")); assertEquals(0, fs.list("/folder2/subfolder").length);
if (!itemStateFS.isFile(propFilePath)) { throw new NoSuchItemStateException(propFilePath); new BufferedInputStream(itemStateFS.getInputStream(propFilePath)); try { PropertyState state = createNew(id);
/** * {@inheritDoc} */ public synchronized void store(NodeReferences refs) throws ItemStateException { if (!initialized) { throw new IllegalStateException("not initialized"); } try { StringBuffer buf = buildNodeFolderPath(null, refs.getTargetId()); buf.append('.'); buf.append(NODEREFSFILENAME); String fileName = buf.toString(); String dir = fileName.substring(0, fileName.lastIndexOf(FileSystem.SEPARATOR_CHAR)); if (!itemFs.exists(dir)) { itemFs.createFolder(dir); } OutputStream out = itemFs.getOutputStream(fileName); Serializer.serialize(refs, out); out.close(); } catch (Exception e) { String msg = "failed to write " + refs; BundleFsPersistenceManager.log.error(msg, e); throw new ItemStateException(msg, e); } }
String[] folders = blobFS.listFolders("/"); for (String folder: folders) { blobFS.deleteFolder(folder); String[] files = blobFS.listFiles("/"); for (String file : files) { blobFS.deleteFile(file); blobFS.close(); blobFS = null; blobStore = null;
FileSystem fs = fsf.getFileSystem(); try { if (!fs.exists(workspaceConfigDirectory)) { fs.createFolder(workspaceConfigDirectory); } else { String[] dirNames = fs.listFolders(workspaceConfigDirectory); for (String dir : dirNames) { String configDir = workspaceConfigDirectory fs.close();
private Properties loadProperties(String path) throws RepositoryException { Properties properties = new Properties(); FileSystem filesystem = source.getFileSystem(); try { if (filesystem.exists(path)) { InputStream stream = filesystem.getInputStream(path); try { properties.load(stream); } finally { stream.close(); } } } catch (FileSystemException e) { throw new RepositoryException(e); } catch (IOException e) { throw new RepositoryException(e); } return properties; }
@Override protected void tearDown() throws Exception { try { if (fs.exists("/privileges") && fs.isFolder("/privileges")) { fs.deleteFolder("/privileges"); } } finally { super.tearDown(); } }
try { virtualFS.createFolder(configDir); virtualFS.getOutputStream(configFile)); } catch (FileSystemException e) { throw new ConfigurationException( try { if (virtualFS != null) { virtualFS.close();
/** * @see FileSystem#exists */ public boolean exists() throws FileSystemException { return fs.exists(path); }
private void getListRecursive( ArrayList<NodeId> list, String path, NodeId bigger, int maxCount) throws FileSystemException { if (maxCount > 0 && list.size() >= maxCount) { return; } String[] files = itemFs.listFiles(path); Arrays.sort(files); for (int i = 0; i < files.length; i++) { String f = files[i]; NodeId n = getIdFromFileName(path + FileSystem.SEPARATOR + f); if (n == null) { continue; } if (bigger != null && bigger.toString().compareTo(n.toString()) >= 0) { continue; } list.add(n); if (maxCount > 0 && list.size() >= maxCount) { return; } } String[] dirs = itemFs.listFolders(path); Arrays.sort(dirs); for (int i = 0; i < dirs.length; i++) { getListRecursive(list, path + FileSystem.SEPARATOR + dirs[i], bigger, maxCount); } }
/** * @see FileSystem#getOutputStream */ public OutputStream getOutputStream() throws FileSystemException { return fs.getOutputStream(path); }
public void close() { try { fs.close(); fs = null; } catch (Exception e) { // ignore } } }
/** * {@inheritDoc} */ public synchronized void close() throws Exception { if (!initialized) { throw new IllegalStateException("not initialized"); } try { if (persistent) { // serialize contents of state and refs stores storeContents(); } else if (useFileBlobStore) { blobFS.close(); // not persistent, clear out blobs wspFS.deleteFolder("blobs"); } } finally { initialized = false; } }
/** * {@inheritDoc} */ public void deleteFolder(String folderPath) throws FileSystemException { fsBase.deleteFolder(buildBasePath(folderPath)); }
/** * {@inheritDoc} */ public void createFolder(String folderPath) throws FileSystemException { fsBase.createFolder(buildBasePath(folderPath)); }
/** * {@inheritDoc} */ public void deleteFile(String filePath) throws FileSystemException { fsBase.deleteFile(buildBasePath(filePath)); }