private File getFileForWrite()

in taverna-server-webapp/src/main/java/org/apache/taverna/server/master/DirectoryREST.java [298:333]


	private File getFileForWrite(List<PathSegment> filePath,
			Holder<Boolean> isNew) throws FilesystemAccessException,
			NoDirectoryEntryException, NoUpdateException {
		support.permitUpdate(run);
		if (filePath == null || filePath.size() == 0)
			throw new FilesystemAccessException(
					"Cannot create a file that is not in a directory.");

		List<PathSegment> dirPath = new ArrayList<>(filePath);
		String name = dirPath.remove(dirPath.size() - 1).getPath();
		DirectoryEntry de = fileUtils.getDirEntry(run, dirPath);
		if (!(de instanceof Directory)) {
			throw new FilesystemAccessException(
					"Cannot create a file that is not in a directory.");
		}
		Directory d = (Directory) de;

		File f = null;
		isNew.value = false;
		for (DirectoryEntry e : d.getContents())
			if (e.getName().equals(name)) {
				if (e instanceof File) {
					f = (File) e;
					break;
				}
				throw new FilesystemAccessException(
						"Cannot create a file that is not in a directory.");
			}

		if (f == null) {
			f = d.makeEmptyFile(support.getPrincipal(), name);
			isNew.value = true;
		} else
			f.setContents(new byte[0]);
		return f;
	}